Skip to content

Use default loop in testsuite and close server and connection leftovers #283

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
Jan 13, 2022
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
Next Next commit
Close open servers and connections at end of tests
  • Loading branch information
SimonFrings committed Jan 13, 2022
commit 82acd6cf2ab996f68f808858cc0530fca2683a5a
6 changes: 6 additions & 0 deletions tests/FdServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Clue\React\Block;
use React\EventLoop\Loop;
use React\Promise\Promise;
use React\Socket\ConnectionInterface;
use React\Socket\FdServer;

class FdServerTest extends TestCase
Expand Down Expand Up @@ -309,9 +310,14 @@ public function testServerEmitsConnectionEventForNewConnection()

$connection = Block\await($promise, Loop::get(), 1.0);

/**
* @var ConnectionInterface $connection
*/
$this->assertInstanceOf('React\Socket\ConnectionInterface', $connection);

fclose($client);
$connection->close();
$server->close();
}

public function testEmitsErrorWhenAcceptListenerFails()
Expand Down
27 changes: 14 additions & 13 deletions tests/FunctionalConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public function connectionToTcpServerShouldSucceedWithLocalhost()
{
$loop = Loop::get();

$server = new TcpServer(9998, $loop);
$server = new TcpServer(9998);

$connector = new Connector(array(), $loop);
$connector = new Connector(array());

$connection = Block\await($connector->connect('localhost:9998'), $loop, self::TIMEOUT);

Expand All @@ -44,18 +44,16 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo
$this->markTestSkipped('Not supported on Windows for PHP versions < 7.0 and legacy HHVM');
}

$loop = Loop::get();

$socket = stream_socket_server('udp://127.0.0.1:0', $errno, $errstr, STREAM_SERVER_BIND);

$connector = new Connector(array(
'dns' => 'udp://' . stream_socket_get_name($socket, false),
'happy_eyeballs' => false
), $loop);
));

// minimal DNS proxy stub which forwards DNS messages to actual DNS server
$received = 0;
$loop->addReadStream($socket, function ($socket) use (&$received) {
Loop::addReadStream($socket, function ($socket) use (&$received) {
$request = stream_socket_recvfrom($socket, 65536, 0, $peer);

$client = stream_socket_client('udp://8.8.8.8:53');
Expand All @@ -64,15 +62,18 @@ public function testConnectTwiceWithoutHappyEyeBallsOnlySendsSingleDnsQueryDueTo

stream_socket_sendto($socket, $response, 0, $peer);
++$received;
fclose($client);
});

$connection = Block\await($connector->connect('example.com:80'), $loop);
$connection = Block\await($connector->connect('example.com:80'), Loop::get());
$connection->close();
$this->assertEquals(1, $received);

$connection = Block\await($connector->connect('example.com:80'), $loop);
$connection = Block\await($connector->connect('example.com:80'), Loop::get());
$connection->close();
$this->assertEquals(1, $received);

Loop::removeReadStream($socket);
}

/**
Expand All @@ -86,7 +87,7 @@ public function connectionToRemoteTCP4n6ServerShouldResultInOurIP()

$loop = Loop::get();

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

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

Expand All @@ -101,7 +102,7 @@ public function connectionToRemoteTCP4ServerShouldResultInOurIP()
{
$loop = Loop::get();

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

try {
$ip = Block\await($this->request('ipv4.tlund.se', $connector), $loop, self::TIMEOUT);
Expand All @@ -122,7 +123,7 @@ public function connectionToRemoteTCP6ServerShouldResultInOurIP()
{
$loop = Loop::get();

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

try {
$ip = Block\await($this->request('ipv6.tlund.se', $connector), $loop, self::TIMEOUT);
Expand All @@ -143,10 +144,10 @@ public function testCancelPendingTlsConnectionDuringTlsHandshakeShouldCloseTcpCo

$loop = Loop::get();

$server = new TcpServer(0, $loop);
$server = new TcpServer(0);
$uri = str_replace('tcp://', 'tls://', $server->getAddress());

$connector = new Connector(array(), $loop);
$connector = new Connector(array());
$promise = $connector->connect($uri);

$deferred = new Deferred();
Expand Down
Loading
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