Skip to content

Commit cb36b76

Browse files
committed
Add timeouts for all integration tests
1 parent 670e219 commit cb36b76

4 files changed

Lines changed: 24 additions & 18 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
}
1717
},
1818
"require-dev": {
19-
"clue/block-react": "~1.0"
19+
"clue/block-react": "^1.1"
2020
}
2121
}

tests/IntegrationTest.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
class IntegrationTest extends TestCase
1414
{
15+
const TIMEOUT = 5.0;
16+
1517
/** @test */
1618
public function gettingStuffFromGoogleShouldWork()
1719
{
@@ -25,7 +27,7 @@ public function gettingStuffFromGoogleShouldWork()
2527

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

28-
$response = Block\await(BufferedSink::createPromise($conn), $loop);
30+
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);
2931

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

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

54-
$response = Block\await(BufferedSink::createPromise($conn), $loop);
56+
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);
5557

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

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

8385
/** @test */
@@ -100,7 +102,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
100102
)
101103
);
102104

103-
$conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop);
105+
$conn = Block\await($secureConnector->create('self-signed.badssl.com', 443), $loop, self::TIMEOUT);
104106
$conn->close();
105107
}
106108
}

tests/SecureIntegrationTest.php

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
class SecureIntegrationTest extends TestCase
1717
{
18+
const TIMEOUT = 0.5;
19+
1820
private $portSecure;
1921
private $portPlain;
2022

@@ -51,7 +53,7 @@ public function tearDown()
5153

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

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

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

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

6971
$client->close();
@@ -79,13 +81,13 @@ public function testSendSmallDataToServerReceivesOneChunk()
7981
});
8082
});
8183

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

8587
$client->write('hello');
8688

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

9092
$client->close();
9193

@@ -105,14 +107,14 @@ public function testSendDataWithEndToServerReceivesAllData()
105107
});
106108
});
107109

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

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

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

117119
$this->assertEquals($data, $received);
118120
}
@@ -126,7 +128,7 @@ public function testSendDataWithoutEndingToServerReceivesAllData()
126128
});
127129
});
128130

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

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

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

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

156158
$client->close();
157159
}
@@ -163,11 +165,11 @@ public function testConnectToServerWhichSendsDataWithEndReceivesAllData()
163165
$peer->end($data);
164166
});
165167

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

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

172174
$this->assertEquals($data, $received);
173175
}

tests/TcpConnectorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
class TcpConnectorTest extends TestCase
1111
{
12+
const TIMEOUT = 0.1;
13+
1214
/** @test */
1315
public function connectionToEmptyPortShouldFail()
1416
{
@@ -35,7 +37,7 @@ public function connectionToTcpServerShouldSucceed()
3537

3638
$connector = new TcpConnector($loop);
3739

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

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

@@ -67,7 +69,7 @@ public function connectionToIp6TcpServerShouldSucceed()
6769

6870
$connector = new TcpConnector($loop);
6971

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

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

0 commit comments

Comments
 (0)