8000 Run test suite on Windows · reactphp/socket@86cb5f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 86cb5f8

Browse files
committed
Run test suite on Windows
1 parent 59730c4 commit 86cb5f8

9 files changed

+61
-54
lines changed

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,22 @@ matrix:
2323
before_install:
2424
- curl -s http://getcomposer.org/installer | php
2525
- mv composer.phar /usr/local/bin/composer
26+
- name: Windows
27+
os: windows
28+
language: generic
29+
before_install:
30+
- choco install php
31+
- choco install composer
32+
- export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::GetEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')"
33+
- php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);"
34+
- php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);"
35+
- php -r "file_put_contents(php_ini_loaded_file(),'extension=openssl'.PHP_EOL,FILE_APPEND);"
36+
install:
37+
- composer install
2638
allow_failures:
2739
- php: hhvm-3.18
2840
- os: osx
41+
- os: windows
2942

3043
sudo: false
3144

tests/FunctionalSecureServerTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
use React\Socket\SecureConnector;
1111
use React\Socket\ServerInterface;
1212
use React\Socket\SecureServer;
13-
use React\Socket\TcpServer;
1413
use React\Socket\TcpConnector;
14+
use React\Socket\TcpServer;
1515

1616
class FunctionalSecureServerTest extends TestCase
1717
{
@@ -549,6 +549,10 @@ public function testServerEmitsErrorForClientWithInvalidCertificate()
549549

550550
public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase()
551551
{
552+
if (DIRECTORY_SEPARATOR === '\\') {
553+
$this->markTestSkipped('Not supported on Windows');
554+
}
555+
552556
$loop = Factory::create();
553557

554558
$server = new TcpServer(0, $loop);
@@ -569,6 +573,10 @@ public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase
569573

570574
public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassphrase()
571575
{
576+
if (DIRECTORY_SEPARATOR === '\\') {
577+
$this->markTestSkipped('Not supported on Windows');
578+
}
579+
572580
$loop = Factory::create();
573581

574582
$server = new TcpServer(0, $loop);

tests/FunctionalTcpServerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ public function testEmitsConnectionWithLocalIp()
116116

117117
public function testEmitsConnectionWithLocalIpDespiteListeningOnAll()
118118
{
119+
if (DIRECTORY_SEPARATOR === '\\') {
120+
$this->markTestSkipped('Skipping on Windows due to default firewall rules');
121+
}
122+
119123
$loop = Factory::create();
120124

121125
$server = new TcpServer('0.0.0.0:0', $loop);

tests/HappyEyeBallsConnectorTest.php

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -178,52 +178,6 @@ public function testIpv6DoesntResolvesWhileIpv4DoesFirstSoIpv4Connects(array $ip
178178
$this->loop->run();
179179
}
180180

181-
public function testThatTheIpv4ConnectionWillWait100MilisecondsWhenIpv6AndIpv4ResolveSimultaniously()
182-
{
183-
$timings = array(); 341A
184-
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue(Promise\resolve(array('1:2:3:4'))));
185-
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue(Promise\resolve(array('1.2.3.4'))));
186-
$this->tcp->expects($this->at(0))->method('connect')->with($this->equalTo('scheme://[1:2:3:4]:80/?hostname=google.com'))->will($this->returnCallback(function () use (&$timings) {
187-
$timings[Message::TYPE_AAAA] = microtime(true);
188-
189-
return new Promise\Promise(function () {});
190-
}));
191-
$this->tcp->expects($this->at(1))->method('connect')->with($this->equalTo('scheme://1.2.3.4:80/?hostname=google.com'))->will($this->returnCallback(function () use (&$timings) {
192-
$timings[Message::TYPE_A] = microtime(true);
193-
194-
return new Promise\Promise(function () {});
195-
}));
196-
197-
$this->connector->connect('scheme://google.com:80/?hostname=google.com');
198-
199-
$this->loop->run();
200-
201-
self::assertGreaterThan(0.01, $timings[Message::TYPE_A] - $timings[Message::TYPE_AAAA]);
202-
}
203-
204-
/**
205-
* @dataProvider provideIpvAddresses
206-
*/
207-
public function testAssert100MilisecondsBetweenConnectionAttempts(array $ipv6, array $ipv4)
208-
{
209-
$timings = array();
210-
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue(Promise\resolve($ipv6)));
211-
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue(Promise\resolve($ipv4)));
212-
$this->tcp->expects($this->any())->method('connect')->with($this->stringContains(':80/?hostname=google.com'))->will($this->returnCallback(function () use (&$timings) {
213-
$timings[] = microtime(true);
214-
215-
return new Promise\Promise(function () {});
216-
}));
217-
218-
$this->connector->connect('scheme://google.com:80/?hostname=google.com');
219-
220-
$this->loop->run();
221-
222-
for ($i = 0; $i < (count($timings) - 1); $i++) {
223-
self::assertGreaterThan(0.01, $timings[$i + 1] - $timings[$i]);
224-
}
225-
}
226-
227181
/**
228182
* @dataProvider provideIpvAddresses
229183
*/

tests/IntegrationTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,10 @@ function ($e) use (&$wait) {
175175
if ($wait) {
176176
Block\sleep(0.2, $loop);
177177
if ($wait) {
178-
$this->fail('Connection attempt did not fail');
178+
Block\sleep(2.0, $loop);
179+
if ($wait) {
180+
$this->fail('Connection attempt did not fail');
181+
}
179182
}
180183
}
181184
unset($promise);

tests/TcpConnectorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
class TcpConnectorTest extends TestCase
1313
{
14-
const TIMEOUT = 0.1;
14+
const TIMEOUT = 5.0;
1515

1616
/**
1717
* @test

tests/TcpServerTest.php

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
use React\EventLoop\Factory;
77
use React\Socket\TcpServer;
88
use React\Stream\DuplexResourceStream;
9+
use React\Promise\Promise;
910

1011
class TcpServerTest extends TestCase
1112
{
13+
const TIMEOUT = 5.0;
14+
1215
private $loop;
1316
private $server;
1417
private $port;
@@ -33,13 +36,18 @@ public function setUp()
3336
/**
3437
* @covers React\Socket\TcpServer::handleConnection
3538
*/
36-
public function testConnection()
39+
public function testServerEmitsConnectionEventForNewConnection()
3740
{
3841
$client = stream_socket_client('tcp://localhost:'.$this->port);
3942

40-
$this->server->on('connection', $this->expectCallableOnce());
43+
$server = $this->server;
44+
$promise = new Promise(function ($resolve) use ($server) {
45+
$server->on('connection', $resolve);
46+
});
4147

42-
$this->tick();
48+
$connection = Block\await($promise, $this->loop, self::TIMEOUT);
49+
50+
$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);
4351
}
4452

4553
/**
@@ -270,7 +278,7 @@ public function testEmitsErrorWhenAcceptListenerFails()
270278
$server->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
271279

272280
$this->assertNotNull($listener);
273-
$listener(false);
281+
$listener(tmpfile());
274282
}
275283

276284
/**
@@ -295,8 +303,21 @@ public function tearDown()
295303
}
296304
}
297305

306+
/**
307+
* This methods runs the loop for "one tick"
308+
*
309+
* This is prone to race conditions and as such somewhat unreliable across
310+
* different operating systems. Running the loop until the expected events
311+
* fire is the preferred alternative.
312+
*
313+
* @deprecated
314+
*/
298315
private function tick()
299316
{
317+
if (DIRECTORY_SEPARATOR === '\\') {
318+
$this->markTestSkipped('Not supported on Windows');
319+
}
320+
300321
Block\sleep(0, $this->loop);
301322
}
302323
}

tests/UnixConnectorTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public function testInvalidScheme()
3030

3131
public function testValid()
3232
{
33+
if (!in_array('unix', stream_get_transports())) {
34+
$this->markTestSkipped('Unix domain sockets (UDS) not supported on your platform (Windows?)');
35+
}
36+
3337
// random unix domain socket path
3438
$path = sys_get_temp_dir() . '/test' . uniqid() . '.sock';
3539

tests/UnixServerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function testEmitsErrorWhenAcceptListenerFails()
287287
$server->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));
288288

289289
$this->assertNotNull($listener);
290-
$listener(false);
290+
$listener(tmpfile());
291291
}
292292

293293
/**

0 commit comments

Comments
 (0)
0