Skip to content

Add test group to skip integration tests relying on internet connection and apply timeouts #132

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
30 changes: 23 additions & 7 deletions tests/FunctionalInternetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace React\Tests\Stream;

use React\Stream\DuplexResourceStream;
use React\EventLoop\Factory;
use React\EventLoop\LoopInterface;
use React\Stream\DuplexResourceStream;
use React\Stream\WritableResourceStream;

/**
Expand All @@ -28,14 +29,14 @@ 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);
}

public function testUploadBiggerBlockPlain()
{
$size = 1000 * 30;
$size = 50 * 1000;
$stream = stream_socket_client('tcp://httpbin.org:80');

$loop = Factory::create();
Expand All @@ -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);
}
Expand All @@ -72,14 +73,14 @@ 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);
}

public function testUploadBiggerBlockSecureRequiresSmallerChunkSize()
{
$size = 1000 * 30000;
$size = 50 * 1000;
$stream = stream_socket_client('tls://httpbin.org:443');

$loop = Factory::create();
Expand All @@ -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();
}
}