8000 Make tests less fragile by improving test timeouts and skip unsupported · reactphp/socket@cea7c78 · GitHub
[go: up one dir, main page]

Skip to content

Commit cea7c78

Browse files
committed
Make tests less fragile by improving test timeouts and skip unsupported
1 parent a2ee3c0 commit cea7c78

File tree

2 files changed

+14
-78
lines changed

2 files changed

+14
-78
lines changed

tests/FunctionalConnectorTest.php

Lines changed: 2 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()
5757
public function connectionToRemoteTCP4ServerShouldResultInOurIP()
5858
{
5959
if ($this->ipv4() === false) {
60-
// IPv4 not supported on this system
61-
$this->assertFalse($this->ipv4());
62-
return;
60+
$this->markTestSkipped('IPv4 connection not supported on this system');
6361
}
6462

6563
$loop = Factory::create();
@@ -79,9 +77,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
7977
public function connectionToRemoteTCP6ServerShouldResultInOurIP()
8078
{
8179
if ($this->ipv6() === false) {
82-
// IPv6 not supported on this system
83-
$this->assertFalse($this->ipv6());
84-
return;
80+
$this->markTestSkipped('IPv6 connection not supported on this system');
8581
}
8682

8783
$loop = Factory::create();
@@ -94,72 +90,6 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP()
9490
$this->assertSame($ip, filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6), $ip);
9591
}
9692

97-
/**
98-
* @test
99-
* @group internet
100-
*
101-
* @expectedException \RuntimeException
102-
* @expectedExceptionMessageRegExp /Connection to ipv6.tlund.se:80 failed/
103-
*/
104-
public function tryingToConnectToAnIPv6OnlyHostWithOutHappyEyeBallsShouldResultInFailure()
105-
{
106-
$loop = Factory::create();
107-
108-
$connector = new Connector($loop, array('happy_eyeballs' => false));
109-
110-
Block\await($this->request('ipv6.tlund.se', $connector), $loop, self::TIMEOUT);
111-
}
112-
113-
/**
114-
* @test
115-
* @group internet
116-
*
117-
* @expectedException \RuntimeException
118-
* @expectedExceptionMessageRegExp /Connection to tcp:\/\/193.15.228.195:80 failed:/
119-
*/
120-
public function connectingDirectlyToAnIPv4AddressShouldFailWhenIPv4IsntAvailable()
121-
{
122-
if ($this->ipv4() === true) {
123-
// IPv4 supported on this system
124-
throw new \RuntimeException('Connection to tcp://193.15.228.195:80 failed:');
125-
}
126-
127-
$loop = Factory::create();
128-
129-
$connector = new Connector($loop);
130-
131-
$host = current(dns_get_record('ipv4.tlund.se', DNS_A));
132-
$host = $host['ip'];
133-
Block\await($this->request($host, $connector), $loop, self::TIMEOUT);
134-
}
135-
136-
/**
137-
* @test
138-
* @group internet
139-
*
140-
* @expectedException \RuntimeException
141-
* @expectedExceptionMessageRegExp /Connection to tcp:\/\/\[2a00:801:f::195\]:80 failed:/
142-
*/
143-
public function connectingDirectlyToAnIPv6AddressShouldFailWhenIPv6IsntAvailable()
144-
{
145-
if ($this->ipv6() === true) {
146-
// IPv6 supported on this system
147-
throw new \RuntimeException('Connection to tcp://[2a00:801:f::195]:80 failed:');
148-
}
149-
150-
$loop = Factory::create();
151-
152-
$connector = new Connector($loop);
153-
154-
$host = current(dns_get_record('ipv6.tlund.se', DNS_AAAA));
155-
$host = $host['ipv6'];
156-
$host = '[' . $host . ']';
157-
$ip = Block\await($this->request($host, $connector), $loop, self::TIMEOUT);
158-
159-
$this->assertFalse(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4), $ip);
160-
$this->assertSame($ip, filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6), $ip);
161-
}
162-
16393
/**
16494
* @internal
16595
*/

tests/IntegrationTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ function ($e) use (&$wait) {
203203
}
204204
);
205205

206-
// run loop for short period to ensure we detect connection timeout error
206+
// run loop for short period to ensure we detect a connection timeout error
207207
Block\sleep(0.01, $loop);
208208
if ($wait) {
209209
Block\sleep(0.2, $loop);
@@ -236,7 +236,7 @@ function ($e) use (&$wait) {
236236
}
237237
);
238238

239-
// run loop for short period to ensure we detect connection timeout error
239+
// run loop for short period to ensure we detect a connection timeout error
240240
Block\sleep(0.01, $loop);
241241
if ($wait) {
242242
Block\sleep(0.2, $loop);
@@ -269,12 +269,15 @@ function ($e) use (&$wait) {
269269
}
270270
);
271271

272-
// run loop for short period to ensure we detect DNS error
272+
// run loop for short period to ensure we detect a DNS error
273273
Block\sleep(0.01, $loop);
274274
if ($wait) {
275275
Block\sleep(0.2, $loop);
276276
if ($wait) {
277-
$this->fail('Connection attempt did not fail');
277+
Block\sleep(2.0, $loop);
278+
if ($wait) {
279+
$this->fail('Connection attempt did not fail');
280+
}
278281
}
279282
}
280283
unset($promise);
@@ -309,12 +312,15 @@ function ($e) use (&$wait) {
309312
}
310313
);
311314

312-
// run loop for short period to ensure we detect DNS error
315+
// run loop for short period to ensure we detect a TLS error
313316
Block\sleep(0.1, $loop);
314317
if ($wait) {
315318
Block\sleep(0.4, $loop);
316319
if ($wait) {
317-
$this->fail('Connection attempt did not fail');
320+
Block\sleep(self::TIMEOUT - 0.5, $loop);
321+
if ($wait) {
322+
$this->fail('Connection attempt did not fail');
323+
}
318324
}
319325
}
320326
unset($promise);

0 commit comments

Comments
 (0)
0