Skip to content

Commit

Permalink
Add timeouts for all integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
clue committed Nov 15, 2016
1 parent 670e219 commit cb36b76
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 18 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
}
},
"require-dev": {
"clue/block-react": "~1.0"
"clue/block-react": "^1.1"
}
}
10 changes: 6 additions & 4 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

class IntegrationTest extends TestCase
{
const TIMEOUT = 5.0;

/** @test */
public function gettingStuffFromGoogleShouldWork()
{
Expand All @@ -25,7 +27,7 @@ public function gettingStuffFromGoogleShouldWork()

$conn->write("GET / HTTP/1.0\r\n\r\n");

$response = Block\await(BufferedSink::createPromise($conn), $loop);
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);

$this->assertRegExp('#^HTTP/1\.0#', $response);
}
Expand All @@ -51,7 +53,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork()

$conn->write("GET / HTTP/1.0\r\n\r\n");

$response = Block\await(BufferedSink::createPromise($conn), $loop);
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);

$this->assertRegExp('#^HTTP/1\.0#', $response);
}
Expand All @@ -77,7 +79,7 @@ public function testSelfSignedRejectsIfVerificationIsEnabled()
);

$this->setExpectedException('RuntimeException');
Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop);
Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop, self::TIMEOUT);
}

/** @test */
Expand All @@ -100,7 +102,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
)
);

$conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop);
$conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop, self::TIMEOUT);
$conn->close();
}
}
24 changes: 13 additions & 11 deletions tests/SecureIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

class SecureIntegrationTest extends TestCase
{
const TIMEOUT = 0.5;

private $portSecure;
private $portPlain;

Expand Down Expand Up @@ -51,7 +53,7 @@ public function tearDown()

public function testConnectToServer()
{
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$client->close();
Expand All @@ -63,7 +65,7 @@ public function testConnectToServerEmitsConnection()

$promiseClient = $this->connector->create('127.0.0.1', $this->portSecure);

list($_, $client) = Block\awaitAll(array($promiseServer, $promiseClient), $this->loop);
list($_, $client) = Block\awaitAll(array($promiseServer, $promiseClient), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$client->close();
Expand All @@ -79,13 +81,13 @@ public function testSendSmallDataToServerReceivesOneChunk()
});
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$client->write('hello');

// await server to report one "data" event
$data = Block\await($received->promise(), $this->loop);
$data = Block\await($received->promise(), $this->loop, self::TIMEOUT);

$client->close();

Expand All @@ -105,14 +107,14 @@ public function testSendDataWithEndToServerReceivesAllData()
});
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$data = str_repeat('a', 200000);
$client->end($data);

// await server to report connection "close" event
$received = Block\await($disconnected->promise(), $this->loop);
$received = Block\await($disconnected->promise(), $this->loop, self::TIMEOUT);

$this->assertEquals($data, $received);
}
Expand All @@ -126,7 +128,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData()
});
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

$data = str_repeat('d', 200000);
Expand All @@ -146,12 +148,12 @@ public function testConnectToServerWhichSendsSmallDataReceivesOneChunk()
$peer->write('hello');
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

// await client to report one "data" event
$receive = $this->createPromiseForEvent($client, 'data', $this->expectCallableOnceWith('hello'));
Block\await($receive, $this->loop);
Block\await($receive, $this->loop, self::TIMEOUT);

$client->close();
}
Expand All @@ -163,11 +165,11 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData()
$peer->end($data);
});

$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop);
$client = Block\await($this->connector->create('127.0.0.1', $this->portSecure), $this->loop, self::TIMEOUT);
/* @var $client Stream */

// await data from client until it closes
$received = Block\await(BufferedSink::createPromise($client), $this->loop);
$received = Block\await(BufferedSink::createPromise($client), $this->loop, self::TIMEOUT);

$this->assertEquals($data, $received);
}
Expand Down
6 changes: 4 additions & 2 deletions tests/TcpConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

class TcpConnectorTest extends TestCase
{
const TIMEOUT = 0.1;

/** @test */
public function connectionToEmptyPortShouldFail()
{
Expand All @@ -35,7 +37,7 @@ public function connectionToTcpServerShouldSucceed()

$connector = new TcpConnector($loop);

$stream = Block\await($connector->create('127.0.0.1', 9999), $loop);
$stream = Block\await($connector->create('127.0.0.1', 9999), $loop, self::TIMEOUT);

$this->assertInstanceOf('React\Stream\Stream', $stream);

Expand Down Expand Up @@ -67,7 +69,7 @@ public function connectionToIp6TcpServerShouldSucceed()

$connector = new TcpConnector($loop);

$stream = Block\await($connector->create('::1', 9999), $loop);
$stream = Block\await($connector->create('::1', 9999), $loop, self::TIMEOUT);

$this->assertInstanceOf('React\Stream\Stream', $stream);

Expand Down

0 comments on commit cb36b76

Please sign in to comment.