8000 Run test suite on Windows by clue · Pull Request #238 · reactphp/socket · GitHub
[go: up one dir, main page]

Skip to content

Run test suite on Windows #238

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 1 commit into from
Jun 23, 2020
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
8000
Diff view
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,27 @@ matrix:
- php: 7.3
- php: 7.4
- php: hhvm-3.18
install: composer require phpunit/phpunit:^5 --dev --no-interaction # requires legacy phpunit
- name: Mac OS X
os: osx
language: generic
before_install:
- curl -s http://getcomposer.org/installer | php
- mv composer.phar /usr/local/bin/composer
- name: Windows
os: windows
language: bash
before_install:
- choco install php
- choco install composer
- export PATH="$(powershell -Command '("Process", "Machine" | % { [Environment]::G 8000 etEnvironmentVariable("PATH", $_) -Split ";" -Replace "\\$", "" } | Select -Unique | % { cygpath $_ }) -Join ":"')"
- php -r "file_put_contents(php_ini_loaded_file(),'extension_dir=ext'.PHP_EOL,FILE_APPEND);"
- php -r "file_put_contents(php_ini_loaded_file(),'extension=sockets'.PHP_EOL,FILE_APPEND);"
install:
- composer install
allow_failures:
- php: hhvm-3.18
- os: osx
- os: windows

sudo: false

Expand Down
10 changes: 9 additions & 1 deletion tests/FunctionalSecureServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use React\Socket\SecureConnector;
use React\Socket\ServerInterface;
use React\Socket\SecureServer;
use React\Socket\TcpServer;
use React\Socket\TcpConnector;
use React\Socket\TcpServer;

class FunctionalSecureServerTest extends TestCase
{
Expand Down Expand Up @@ -549,6 +549,10 @@ public function testServerEmitsErrorForClientWithInvalidCertificate()

public function testEmitsErrorForServerWithEncryptedCertificateMissingPassphrase()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$loop = Factory::create();

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

public function testEmitsErrorForServerWithEncryptedCertificateWithInvalidPassphrase()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

$loop = Factory::create();

$server = new TcpServer(0, $loop);
Expand Down
4 changes: 4 additions & 0 deletions tests/FunctionalTcpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public function testEmitsConnectionWithLocalIp()

public function testEmitsConnectionWithLocalIpDespiteListeningOnAll()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Skipping on Windows due to default firewall rules');
}

$loop = Factory::create();

$server = new TcpServer('0.0.0.0:0', $loop);
Expand Down
46 changes: 0 additions & 46 deletions tests/HappyEyeBallsConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,52 +178,6 @@ public function testIpv6DoesntResolvesWhileIpv4DoesFirstSoIpv4Connects(array $ip
$this->loop->run();
}

public function testThatTheIpv4ConnectionWillWait100MilisecondsWhenIpv6AndIpv4ResolveSimultaniously()
{
$timings = array();
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue(Promise\resolve(array('1:2:3:4'))));
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue(Promise\resolve(array('1.2.3.4'))));
$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) {
$timings[Message::TYPE_AAAA] = microtime(true);

return new Promise\Promise(function () {});
}));
$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) {
$timings[Message::TYPE_A] = microtime(true);

return new Promise\Promise(function () {});
}));

$this->connector->connect('scheme://google.com:80/?hostname=google.com');

$this->loop->run();

self::assertGreaterThan(0.01, $timings[Message::TYPE_A] - $timings[Message::TYPE_AAAA]);
}

/**
* @dataProvider provideIpvAddresses
*/
public function testAssert100MilisecondsBetweenConnectionAttempts(array $ipv6, array $ipv4)
{
$timings = array();
$this->resolver->expects($this->at(0))->method('resolveAll')->with('google.com', Message::TYPE_AAAA)->will($this->returnValue(Promise\resolve($ipv6)));
$this->resolver->expects($this->at(1))->method('resolveAll')->with('google.com', Message::TYPE_A)->will($this->returnValue(Promise\resolve($ipv4)));
$this->tcp->expects($this->any())->method('connect')->with($this->stringContains(':80/?hostname=google.com'))->will($this->returnCallback(function () use (&$timings) {
$timings[] = microtime(true);

return new Promise\Promise(function () {});
}));

$this->connector->connect('scheme://google.com:80/?hostname=google.com');

$this->loop->run();

for ($i = 0; $i < (count($timings) - 1); $i++) {
self::assertGreaterThan(0.01, $timings[$i + 1] - $timings[$i]);
}
}

/**
* @dataProvider provideIpvAddresses
*/
Expand Down
5 changes: 4 additions & 1 deletion tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,10 @@ function ($e) use (&$wait) {
if ($wait) {
Block\sleep(0.2, $loop);
if ($wait) {
$this->fail('Connection attempt did not fail');
Block\sleep(2.0, $loop);
if ($wait) {
$this->fail('Connection attempt did not fail');
}
}
}
unset($promise);
Expand Down
2 changes: 1 addition & 1 deletion tests/TcpConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class TcpConnectorTest extends TestCase
{
const TIMEOUT = 0.1;
const TIMEOUT = 5.0;

/**
* @test
Expand Down
31 changes: 27 additions & 4 deletions tests/TcpServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@
use React\EventLoop\Factory;
use React\Socket\TcpServer;
use React\Stream\DuplexResourceStream;
use React\Promise\Promise;

class TcpServerTest extends TestCase
{
const TIMEOUT = 5.0;

private $loop;
private $server;
private $port;
Expand All @@ -33,13 +36,18 @@ public function setUp()
/**
* @covers React\Socket\TcpServer::handleConnection
*/
public function testConnection()
public function testServerEmitsConnectionEventForNewConnection()
{
$client = stream_socket_client('tcp://localhost:'.$this->port);

$this->server->on('connection', $this->expectCallableOnce());
$server = $this->server;
$promise = new Promise(function ($resolve) use ($server) {
$server->on('connection', $resolve);
});

$this->tick();
$connection = Block\await($promise, $this->loop, self::TIMEOUT);

$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);
}

/**
Expand Down Expand Up @@ -270,7 +278,9 @@ public function testEmitsErrorWhenAcceptListenerFails()
$server->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));

$this->assertNotNull($listener);
$listener(false);
$socket = stream_socket_server('tcp://127.0.0.1:0');
fclose($socket);
$listener($socket);
}

/**
Expand All @@ -295,8 +305,21 @@ public function tearDown()
}
}

/**
* This methods runs the loop for "one tick"
*
* This is prone to race conditions and as such somewhat unreliable across
* different operating systems. Running the loop until the expected events
* fire is the preferred alternative.
*
* @deprecated
*/
private function tick()
{
if (DIRECTORY_SEPARATOR === '\\') {
$this->markTestSkipped('Not supported on Windows');
}

Block\sleep(0, $this->loop);
}
}
4 changes: 4 additions & 0 deletions tests/UnixConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public function testInvalidScheme()

public function testValid()
{
if (!in_array('unix', stream_get_transports())) {
$this->markTestSkipped('Unix domain sockets (UDS) not supported on your platform (Windows?)');
}

// random unix domain socket path
$path = sys_get_temp_dir() . '/test' . uniqid() . '.sock';

Expand Down
4 changes: 3 additions & 1 deletion tests/UnixServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ public function testEmitsErrorWhenAcceptListenerFails()
$server->on('error', $this->expectCallableOnceWith($this->isInstanceOf('RuntimeException')));

$this->assertNotNull($listener);
$listener(false);
$socket = stream_socket_server('tcp://127.0.0.1:0');
fclose($socket);
$listener($socket);
}

/**
Expand Down
0