Skip to content

Make happy eyeballs algorithm (IPv6) the default, add new happy_eyeballs option to Connector #224

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 3 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Diff view
Prev Previous commit
Make tests less fragile by improving test timeouts and skip unsupported
  • Loading branch information
clue committed Mar 8, 2020
commit e243955ea795cf2fcf2e4e2c64c9147ae01ffd8b
74 changes: 2 additions & 72 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()
public function connectionToRemoteTCP4ServerShouldResultInOurIP()
{
if ($this->ipv4() === false) {
// IPv4 not supported on this system
$this->assertFalse($this->ipv4());
return;
$this->markTestSkipped('IPv4 connection not supported on this system');
}

$loop = Factory::create();
Expand All @@ -79,9 +77,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
public function connectionToRemoteTCP6ServerShouldResultInOurIP()
{
if ($this->ipv6() === false) {
// IPv6 not supported on this system
$this->assertFalse($this->ipv6());
return;
$this->markTestSkipped('IPv6 connection not supported on this system');
}

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

/**
* @test
* @group internet
*
* @expectedException \RuntimeException
* @expectedExceptionMessageRegExp /Connection to ipv6.tlund.se:80 failed/
*/
public function tryingToConnectToAnIPv6OnlyHostWithOutHappyEyeBallsShouldResultInFailure()
{
$loop = Factory::create();

$connector = new Connector($loop, array('happy_eyeballs' => false));

Block\await($this->request('ipv6.tlund.se', $connector), $loop, self::TIMEOUT);
}

/**
* @test
* @group internet
*
* @expectedException \RuntimeException
* @expectedExceptionMessageRegExp /Connection to tcp:\/\/193.15.228.195:80 failed:/
*/
public function connectingDirectlyToAnIPv4AddressShouldFailWhenIPv4IsntAvailable()
{
if ($this->ipv4() === true) {
// IPv4 supported on this system
throw new \RuntimeException('Connection to tcp://193.15.228.195:80 failed:');
}

$loop = Factory::create();

$connector = new Connector($loop);

$host = current(dns_get_record('ipv4.tlund.se', DNS_A));
$host = $host['ip'];
Block\await($this->request($host, $connector), $loop, self::TIMEOUT);
}

/**
* @test
* @group internet
*
* @expectedException \RuntimeException
* @expectedExceptionMessageRegExp /Connection to tcp:\/\/\[2a00:801:f::195\]:80 failed:/
*/
public function connectingDirectlyToAnIPv6AddressShouldFailWhenIPv6IsntAvailable()
{
if ($this->ipv6() === true) {
// IPv6 supported on this system
throw new \RuntimeException('Connection to tcp://[2a00:801:f::195]:80 failed:');
}

$loop = Factory::create();

$connector = new Connector($loop);

$host = current(dns_get_record('ipv6.tlund.se', DNS_AAAA));
$host = $host['ipv6'];
$host = '[' . $host . ']';
$ip = Block\await($this->request($host, $connector), $loop, self::TIMEOUT);

$this->assertFalse(filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4), $ip);
$this->assertSame($ip, filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6), $ip);
}

/**
* @internal
*/
Expand Down
18 changes: 12 additions & 6 deletions tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ function ($e) use (&$wait) {
}
);

// run loop for short period to ensure we detect connection timeout error
// run loop for short period to ensure we detect a connection timeout error
Block\sleep(0.01, $loop);
if ($wait) {
Block\sleep(0.2, $loop);
Expand Down Expand Up @@ -236,7 +236,7 @@ function ($e) use (&$wait) {
}
);

// run loop for short period to ensure we detect connection timeout error
// run loop for short period to ensure we detect a connection timeout error
Block\sleep(0.01, $loop);
if ($wait) {
Block\sleep(0.2, $loop);
Expand Down Expand Up @@ -269,12 +269,15 @@ function ($e) use (&$wait) {
}
);

// run loop for short period to ensure we detect DNS error
// run loop for short period to ensure we detect a DNS error
Block\sleep(0.01, $loop);
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 Expand Up @@ -309,12 +312,15 @@ function ($e) use (&$wait) {
}
);

// run loop for short period to ensure we detect DNS error
// run loop for short period to ensure we detect a TLS error
Block\sleep(0.1, $loop);
if ($wait) {
Block\sleep(0.4, $loop);
if ($wait) {
$this->fail('Connection attempt did not fail');
Block\sleep(self::TIMEOUT - 0.5, $loop);
if ($wait) {
$this->fail('Connection attempt did not fail');
}
}
}
unset($promise);
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy