Skip to content
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

Update test suite to use default loop #204

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
50 changes: 23 additions & 27 deletions tests/FunctionalResolverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,41 +2,37 @@

namespace React\Tests\Dns;

use React\EventLoop\Factory as LoopFactory;
use React\Dns\Resolver\Factory;
use React\Dns\RecordNotFoundException;
use React\Dns\Model\Message;
use React\EventLoop\Loop;

class FunctionalResolverTest extends TestCase
{
private $loop;
private $resolver;

/**
* @before
*/
public function setUpResolver()
{
$this->loop = LoopFactory::create();

$factory = new Factory();
$this->resolver = $factory->create('8.8.8.8', $this->loop);
$this->resolver = $factory->create('8.8.8.8');
}

public function testResolveLocalhostResolves()
{
$promise = $this->resolver->resolve('localhost');
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());

$this->loop->run();
Loop::run();
}

public function testResolveAllLocalhostResolvesWithArray()
{
$promise = $this->resolver->resolveAll('localhost', Message::TYPE_A);
$promise->then($this->expectCallableOnceWith($this->isType('array')), $this->expectCallableNever());

$this->loop->run();
Loop::run();
}

/**
Expand All @@ -47,35 +43,35 @@ public function testResolveGoogleResolves()
$promise = $this->resolver->resolve('google.com');
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());

$this->loop->run();
Loop::run();
}

/**
* @group internet
*/
public function testResolveGoogleOverUdpResolves()
{
$factory = new Factory($this->loop);
$this->resolver = $factory->create('udp://8.8.8.8', $this->loop);
$factory = new Factory();
$this->resolver = $factory->create('udp://8.8.8.8');

$promise = $this->resolver->resolve('google.com');
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());

$this->loop->run();
Loop::run();
}

/**
* @group internet
*/
public function testResolveGoogleOverTcpResolves()
{
$factory = new Factory($this->loop);
$this->resolver = $factory->create('tcp://8.8.8.8', $this->loop);
$factory = new Factory();
$this->resolver = $factory->create('tcp://8.8.8.8');

$promise = $this->resolver->resolve('google.com');
$promise->then($this->expectCallableOnce(), $this->expectCallableNever());

$this->loop->run();
Loop::run();
}

/**
Expand All @@ -84,25 +80,25 @@ public function testResolveGoogleOverTcpResolves()
public function testResolveAllGoogleMxResolvesWithCache()
{
$factory = new Factory();
$this->resolver = $factory->createCached('8.8.8.8', $this->loop);
$this->resolver = $factory->createCached('8.8.8.8');

$promise = $this->resolver->resolveAll('google.com', Message::TYPE_MX);
$promise->then($this->expectCallableOnceWith($this->isType('array')), $this->expectCallableNever());

$this->loop->run();
Loop::run();
}
/**
* @group internet
*/
public function testResolveAllGoogleCaaResolvesWithCache()
{
$factory = new Factory();
$this->resolver = $factory->createCached('8.8.8.8', $this->loop);
$this->resolver = $factory->createCached('8.8.8.8');

$promise = $this->resolver->resolveAll('google.com', Message::TYPE_CAA);
$promise->then($this->expectCallableOnceWith($this->isType('array')), $this->expectCallableNever());

$this->loop->run();
Loop::run();
}

/**
Expand All @@ -112,7 +108,7 @@ public function testResolveInvalidRejects()
{
$promise = $this->resolver->resolve('example.invalid');

$this->loop->run();
Loop::run();

$exception = null;
$promise->then(null, function ($reason) use (&$exception) {
Expand All @@ -134,7 +130,7 @@ public function testResolveCancelledRejectsImmediately()
$promise->cancel();

$time = microtime(true);
$this->loop->run();
Loop::run();
$time = microtime(true) - $time;

$this->assertLessThan(0.1, $time);
Expand All @@ -156,7 +152,7 @@ public function testResolveAllInvalidTypeRejects()
{
$promise = $this->resolver->resolveAll('google.com', Message::TYPE_PTR);

$this->loop->run();
Loop::run();

$exception = null;
$promise->then(null, function ($reason) use (&$exception) {
Expand All @@ -172,7 +168,7 @@ public function testResolveAllInvalidTypeRejects()
public function testInvalidResolverDoesNotResolveGoogle()
{
$factory = new Factory();
$this->resolver = $factory->create('255.255.255.255', $this->loop);
$this->resolver = $factory->create('255.255.255.255');

$promise = $this->resolver->resolve('google.com');
$promise->then($this->expectCallableNever(), $this->expectCallableOnce());
Expand All @@ -185,7 +181,7 @@ public function testResolveShouldNotCauseGarbageReferencesWhenUsingInvalidNamese
}

$factory = new Factory();
$this->resolver = $factory->create('255.255.255.255', $this->loop);
$this->resolver = $factory->create('255.255.255.255');

gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
Expand All @@ -203,7 +199,7 @@ public function testResolveCachedShouldNotCauseGarbageReferencesWhenUsingInvalid
}

$factory = new Factory();
$this->resolver = $factory->createCached('255.255.255.255', $this->loop);
$this->resolver = $factory->createCached('255.255.255.255');

gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
Expand All @@ -221,7 +217,7 @@ public function testCancelResolveShouldNotCauseGarbageReferences()
}

$factory = new Factory();
$this->resolver = $factory->create('127.0.0.1', $this->loop);
$this->resolver = $factory->create('127.0.0.1');

gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
Expand All @@ -240,7 +236,7 @@ public function testCancelResolveCachedShouldNotCauseGarbageReferences()
}

$factory = new Factory();
$this->resolver = $factory->createCached('127.0.0.1', $this->loop);
$this->resolver = $factory->createCached('127.0.0.1');

gc_collect_cycles();
gc_collect_cycles(); // clear twice to avoid leftovers in PHP 7.4 with ext-xdebug and code coverage turned on
Expand Down
Loading