1
0
mirror of https://github.com/danog/dns.git synced 2025-01-22 21:41:11 +01:00

Update for async-interop merge and other Amp changes

This commit is contained in:
Aaron Piotrowski 2017-03-16 23:01:58 -05:00
parent badf3a9100
commit 1d8dc615bf
6 changed files with 16 additions and 18 deletions

View File

@ -39,7 +39,6 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"amphp/loop": "dev-master",
"phpunit/phpunit": "^5.2.8",
"friendsofphp/php-cs-fixer": "^1.9"
},

View File

@ -2,11 +2,10 @@
namespace Amp\Dns;
use Amp\{ CallableMaker, Coroutine, Deferred, Failure, MultiReasonException, Success, TimeoutException };
use Amp\{ CallableMaker, Coroutine, Deferred, Failure, Loop, MultiReasonException, Promise, Success, TimeoutException };
use Amp\Cache\ArrayCache;
use Amp\File\FilesystemException;
use Amp\WindowsRegistry\{ KeyNotFoundException, WindowsRegistry };
use AsyncInterop\{ Loop, Promise };
use LibDNS\{ Decoder\DecoderFactory, Encoder\EncoderFactory };
use LibDNS\Messages\{ MessageFactory, MessageTypes };
use LibDNS\Records\QuestionFactory;
@ -92,7 +91,7 @@ class DefaultResolver implements Resolver {
// flatten $result while preserving order according to $types (append unspecified types for e.g. Record::ALL queries)
private function pipeResult($promise, array $types) {
return \Amp\pipe($promise, function (array $result) use ($types) {
return Promise\pipe($promise, function (array $result) use ($types) {
$retval = [];
foreach ($types as $type) {
if (isset($result[$type])) {
@ -109,7 +108,7 @@ class DefaultResolver implements Resolver {
if (!isset($options["hosts"]) || $options["hosts"]) {
static $hosts = null;
if ($hosts === null || !empty($options["reload_hosts"])) {
return \Amp\pipe(new Coroutine($this->loadHostsFile()), function ($value) use (&$hosts, $name, $types, $options) {
return Promise\pipe(new Coroutine($this->loadHostsFile()), function ($value) use (&$hosts, $name, $types, $options) {
unset($options["reload_hosts"]); // avoid recursion
$hosts = $value;
return $this->recurseWithHosts($name, $types, $options);
@ -160,7 +159,7 @@ class DefaultResolver implements Resolver {
$useTCP = \substr($uri, 0, 6) == "tcp://";
if ($useTCP && isset($server->connect)) {
return \Amp\pipe($server->connect, function() use ($uri, $name, $type) {
return Promise\pipe($server->connect, function() use ($uri, $name, $type) {
return $this->doRequest($uri, $name, $type);
});
}
@ -260,7 +259,7 @@ class DefaultResolver implements Resolver {
}
try {
list( , $resultArr) = yield \Amp\timeout(\Amp\some($promises), $timeout);
list( , $resultArr) = yield Promise\timeout(Promise\some($promises), $timeout);
foreach ($resultArr as $value) {
$result += $value;
}

View File

@ -2,7 +2,7 @@
namespace Amp\Dns;
use AsyncInterop\Promise;
use Amp\Promise;
interface Resolver {
/**

View File

@ -2,7 +2,7 @@
namespace Amp\Dns;
use AsyncInterop\{ Loop, Promise };
use Amp\{ Loop, Promise };
const LOOP_STATE_IDENTIFIER = Resolver::class;
@ -61,7 +61,7 @@ function driver(): Resolver {
*
* @param string $name The hostname to resolve
* @param array $options
* @return \AsyncInterop\Promise
* @return \Amp\Promise
* @TODO add boolean "clear_cache" option flag
*/
function resolve(string $name, array $options = []): Promise {
@ -73,7 +73,7 @@ function resolve(string $name, array $options = []): Promise {
* @param string $name Unlike resolve(), query() allows for requesting _any_ name (as DNS RFC allows for arbitrary strings)
* @param int|int[] $type Use constants of Amp\Dns\Record
* @param array $options @see resolve documentation
* @return \AsyncInterop\Promise
* @return \Amp\Promise
*/
function query(string $name, $type, array $options = []): Promise {
return resolver()->query($name, $type, $options);

View File

@ -2,7 +2,7 @@
namespace Amp\Dns\Test;
use AsyncInterop\Loop;
use Amp\Loop;
class IntegrationTest extends \PHPUnit_Framework_TestCase {
/**
@ -10,7 +10,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase {
* @dataProvider provideHostnames
*/
public function testResolve($hostname) {
Loop::execute(\Amp\wrap(function () use ($hostname) {
Loop::run(function () use ($hostname) {
$result = (yield \Amp\Dns\resolve($hostname));
list($addr, $type, $ttl) = $result[0];
$inAddr = @\inet_pton($addr);
@ -18,7 +18,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase {
$inAddr,
"Server name $hostname did not resolve to a valid IP address"
);
}));
});
}
/**
@ -26,7 +26,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase {
* @dataProvider provideServers
*/
public function testResolveWithCustomServer($server) {
Loop::execute(\Amp\wrap(function () use ($server) {
Loop::run(function () use ($server) {
$result = (yield \Amp\Dns\resolve("google.com", [
"server" => $server
]));
@ -36,7 +36,7 @@ class IntegrationTest extends \PHPUnit_Framework_TestCase {
$inAddr,
"Server name google.com did not resolve to a valid IP address via $server"
);
}));
});
}
public function provideHostnames() {

View File

@ -11,7 +11,7 @@ class ResolvConfTest extends \PHPUnit_Framework_TestCase {
$method = $reflector->getMethod("loadResolvConf");
$method->setAccessible(true);
$result = \Amp\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/resolv.conf")));
$result = \Amp\Promise\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/resolv.conf")));
$this->assertSame([
"nameservers" => [
@ -28,7 +28,7 @@ class ResolvConfTest extends \PHPUnit_Framework_TestCase {
$method = $reflector->getMethod("loadResolvConf");
$method->setAccessible(true);
$result = \Amp\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/invalid.conf")));
$result = \Amp\Promise\wait(new Coroutine($method->invoke(\Amp\Dns\resolver(), __DIR__ . "/data/invalid.conf")));
$this->assertSame([
"nameservers" => [