From f85ff19f2c96a8a1789bdc23bd6d876f045e1eb9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 19 Jan 2018 12:16:04 +0100 Subject: [PATCH 1/2] Reduce traffic for functional tests to max 50KB per test --- tests/FunctionalInternetTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/FunctionalInternetTest.php b/tests/FunctionalInternetTest.php index fdbec53..773265a 100644 --- a/tests/FunctionalInternetTest.php +++ b/tests/FunctionalInternetTest.php @@ -2,8 +2,8 @@ namespace React\Tests\Stream; -use React\Stream\DuplexResourceStream; use React\EventLoop\Factory; +use React\Stream\DuplexResourceStream; use React\Stream\WritableResourceStream; /** @@ -35,7 +35,7 @@ public function testUploadKilobytePlain() public function testUploadBiggerBlockPlain() { - $size = 1000 * 30; + $size = 50 * 1000; $stream = stream_socket_client('tcp://httpbin.org:80'); $loop = Factory::create(); @@ -79,7 +79,7 @@ public function testUploadKilobyteSecure() public function testUploadBiggerBlockSecureRequiresSmallerChunkSize() { - $size = 1000 * 30000; + $size = 50 * 1000; $stream = stream_socket_client('tls://httpbin.org:443'); $loop = Factory::create(); From ef87054fd0031929a3468b0d042985ec7205b1f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 19 Jan 2018 12:24:53 +0100 Subject: [PATCH 2/2] Apply timeout for integration tests relying on internet connection --- README.md | 8 ++++++++ tests/FunctionalInternetTest.php | 24 ++++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9ad33bf..a0ed336 100644 --- a/README.md +++ b/README.md @@ -1203,6 +1203,14 @@ To run the test suite, go to the project root and run: $ php vendor/bin/phpunit ``` +The test suite also contains a number of functional integration tests that rely +on a stable internet connection. +If you do not want to run these, they can simply be skipped like this: + +```bash +$ php vendor/bin/phpunit --exclude-group internet +``` + ## License MIT, see [LICENSE file](LICENSE). diff --git a/tests/FunctionalInternetTest.php b/tests/FunctionalInternetTest.php index 773265a..4d31e8e 100644 --- a/tests/FunctionalInternetTest.php +++ b/tests/FunctionalInternetTest.php @@ -3,6 +3,7 @@ namespace React\Tests\Stream; use React\EventLoop\Factory; +use React\EventLoop\LoopInterface; use React\Stream\DuplexResourceStream; use React\Stream\WritableResourceStream; @@ -28,7 +29,7 @@ public function testUploadKilobytePlain() $stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); - $loop->run(); + $this->awaitStreamClose($stream, $loop); $this->assertNotEquals('', $buffer); } @@ -50,7 +51,7 @@ public function testUploadBiggerBlockPlain() $stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); - $loop->run(); + $this->awaitStreamClose($stream, $loop); $this->assertNotEquals('', $buffer); } @@ -72,7 +73,7 @@ public function testUploadKilobyteSecure() $stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); - $loop->run(); + $this->awaitStreamClose($stream, $loop); $this->assertNotEquals('', $buffer); } @@ -99,8 +100,23 @@ public function testUploadBiggerBlockSecureRequiresSmallerChunkSize() $stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size)); - $loop->run(); + $this->awaitStreamClose($stream, $loop); $this->assertNotEquals('', $buffer); } + + private function awaitStreamClose(DuplexResourceStream $stream, LoopInterface $loop, $timeout = 10.0) + { + $stream->on('close', function () use ($loop) { + $loop->stop(); + }); + + $that = $this; + $loop->addTimer($timeout, function () use ($loop, $that) { + $loop->stop(); + $that->fail('Timed out while waiting for stream to close'); + }); + + $loop->run(); + } }