8000 Merge pull request #132 from clue-labs/internet · reactphp/stream@df46cde · GitHub
[go: up one dir, main page]

Skip to content

Commit df46cde

Browse files
authored
Merge pull request #132 from clue-labs/internet
Add test group to skip integration tests relying on internet connection and apply timeouts
2 parents 8dbf5be + ef87054 commit df46cde

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
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: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
namespace React\Tests\Stream;
44

5-
use React\Stream\DuplexResourceStream;
65
use React\EventLoop\Factory;
6+
use React\EventLoop\LoopInterface;
7+
use React\Stream\DuplexResourceStream;
78
use React\Stream\WritableResourceStream;
89

910
/**
@@ -28,14 +29,14 @@ 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
}
3536

3637
public function testUploadBiggerBlockPlain()
3738
{
38-
$size = 1000 * 30;
39+
$size = 50 * 1000;
3940
$stream = stream_socket_client('tcp://httpbin.org:80');
4041

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

8081
public function testUploadBiggerBlockSecureRequiresSmallerChunkSize()
8182
{
82-
$size = 1000 * 30000;
83+
$size = 50 * 1000;
8384
$stream = stream_socket_client('tls://httpbin.org:443');
8485

8586
$loop = Factory::create();
@@ -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)
0