Skip to content

Commit ef87054

Browse files
committed
Apply timeout for integration tests relying on internet connection
1 parent f85ff19 commit ef87054

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1203,6 +1203,14 @@ To run the test suite, go to the project root and run:
12031203
$ php vendor/bin/phpunit
12041204
```
12051205

1206+
The test suite also contains a number of functional integration tests that rely
1207+
on a stable internet connection.
1208+
If you do not want to run these, they can simply be skipped like this:
1209+
1210+
```bash
1211+
$ php vendor/bin/phpunit --exclude-group internet
1212+
```
1213+
12061214
## License
12071215

12081216
MIT, see [LICENSE file](LICENSE).

tests/FunctionalInternetTest.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace React\Tests\Stream;
44

55
use React\EventLoop\Factory;
6+
use React\EventLoop\LoopInterface;
67
use React\Stream\DuplexResourceStream;
78
use React\Stream\WritableResourceStream;
89

@@ -28,7 +29,7 @@ public function testUploadKilobytePlain()
2829

2930
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size));
3031

31-
$loop->run();
32+
$this->awaitStreamClose($stream, $loop);
3233

3334
$this->assertNotEquals('', $buffer);
3435
}
@@ -50,7 +51,7 @@ public function testUploadBiggerBlockPlain()
5051

5152
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size));
5253

53-
$loop->run();
54+
$this->awaitStreamClose($stream, $loop);
5455

5556
$this->assertNotEquals('', $buffer);
5657
}
@@ -72,7 +73,7 @@ public function testUploadKilobyteSecure()
7273

7374
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size));
7475

75-
$loop->run();
76+
$this->awaitStreamClose($stream, $loop);
7677

7778
$this->assertNotEquals('', $buffer);
7879
}
@@ -99,8 +100,23 @@ public function testUploadBiggerBlockSecureRequiresSmallerChunkSize()
99100

100101
$stream->write("POST /post HTTP/1.0\r\nHost: httpbin.org\r\nContent-Length: $size\r\n\r\n" . str_repeat('.', $size));
101102

102-
$loop->run();
103+
$this->awaitStreamClose($stream, $loop);
103104

104105
$this->assertNotEquals('', $buffer);
105106
}
107+
108+
private function awaitStreamClose(DuplexResourceStream $stream, LoopInterface $loop, $timeout = 10.0)
109+
{
110+
$stream->on('close', function () use ($loop) {
111+
$loop->stop();
112+
});
113+
114+
$that = $this;
115+
$loop->addTimer($timeout, function () use ($loop, $that) {
116+
$loop->stop();
117+
$that->fail('Timed out while waiting for stream to close');
118+
});
119+
120+
$loop->run();
121+
}
106122
}

0 commit comments

Comments
 (0)