Skip to content

Commit 12a7eaf

Browse files
committed
Add timeouts for all integration tests
1 parent 4d31e9d commit 12a7eaf

File tree

4 files changed

+24
-18
lines changed

4 files changed

+24
-18
lines changed

composer.json

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

tests/IntegrationTest.php

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

1414
class IntegrationTest extends TestCase
1515
{
16+
const TIMEOUT = 5.0;
17+
1618
/** @test */
1719
public function gettingStuffFromGoogleShouldWork()
1820
{
@@ -26,7 +28,7 @@ public function gettingStuffFromGoogleShouldWork()
2628

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

29-
$response = Block\await(BufferedSink::createPromise($conn), $loop);
31+
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);
3032

3133
$this->assertRegExp('#^HTTP/1\.0#', $response);
3234
}
@@ -52,7 +54,7 @@ public function gettingEncryptedStuffFromGoogleShouldWork()
5254

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

55-
$response = Block\await(BufferedSink::createPromise($conn), $loop);
57+
$response = Block\await(BufferedSink::createPromise($conn), $loop, self::TIMEOUT);
5658

5759
$this->assertRegExp('#^HTTP/1\.0#', $response);
5860
}
@@ -78,7 +80,7 @@ public function testSelfSignedRejectsIfVerificationIsEnabled()
7880
);
7981

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

8486
/** @test */
@@ -101,7 +103,7 @@ public function testSelfSignedResolvesIfVerificationIsDisabled()
101103
)
102104
);
103105

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

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)