From adc1a53c438f81604e0227329c5754addb5bf858 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 11 Jun 2019 20:04:37 +0000 Subject: [PATCH] Delay throwing exception for 500ms when 405 is returned --- lib/Internal/HttpsSocket.php | 5 +++++ test/IntegrationTest.php | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lib/Internal/HttpsSocket.php b/lib/Internal/HttpsSocket.php index 9e3ac9e..09b7f67 100644 --- a/lib/Internal/HttpsSocket.php +++ b/lib/Internal/HttpsSocket.php @@ -5,6 +5,7 @@ namespace Amp\DoH\Internal; use Amp; use Amp\Artax\Client; use Amp\Artax\Request; +use Amp\Delayed; use Amp\Dns\DnsException; use Amp\DoH\JsonDecoderFactory; use Amp\DoH\Nameserver; @@ -84,6 +85,10 @@ final class HttpsSocket extends Socket return call(function () use ($response, $id) { $response = yield $response; if ($response->getStatus() !== 200) { + if ($response->getStatus() !== 405) { + throw new DnsException("HTTP result !== 200: ".$response->getStatus()." ".$response->getReason()); + } + yield new Delayed(500); throw new DnsException("HTTP result !== 200: ".$response->getStatus()." ".$response->getReason()); } $response = yield $response->getBody(); diff --git a/test/IntegrationTest.php b/test/IntegrationTest.php index ff8fb23..15290a5 100644 --- a/test/IntegrationTest.php +++ b/test/IntegrationTest.php @@ -2,6 +2,7 @@ namespace Amp\DoH\Test; +use Amp\Delayed; use Amp\Dns; use Amp\Dns\Record; use Amp\DoH; @@ -38,18 +39,19 @@ class IntegrationTest extends TestCase /** * @group internet - * @dataProvider provideServersAndHostnames + * @dataProvider provideServers */ - public function testWorksAfterConfigReload($hostname, $nameserver) + public function testWorksAfterConfigReload($nameserver) { $nameserver = new Nameserver(...$nameserver); - Loop::run(function () use ($hostname, $nameserver) { + Loop::run(function () use ($nameserver) { $DohConfig = new DoH\DoHConfig([$nameserver]); Dns\resolver(new DoH\Rfc8484StubResolver($DohConfig)); - yield Dns\resolve($hostname); + yield Dns\resolve('google.com'); $this->assertNull(yield Dns\resolver()->reloadConfig()); - $this->assertInternalType("array", yield Dns\resolve($hostname)); + yield new Delayed(500); + $this->assertInternalType("array", yield Dns\resolve('google.com')); }); \usleep(500*1000); } @@ -77,6 +79,7 @@ class IntegrationTest extends TestCase ); } }); + \usleep(500*1000); } /** @@ -102,6 +105,7 @@ class IntegrationTest extends TestCase ); } }); + \usleep(500*1000); } /** @@ -123,6 +127,7 @@ class IntegrationTest extends TestCase $this->assertNotNull($record->getTtl()); $this->assertSame(Record::PTR, $record->getType()); }); + \usleep(500*1000); } /** @@ -141,6 +146,7 @@ class IntegrationTest extends TestCase $this->assertSame($promise1, $promise2); $this->assertSame(yield $promise1, yield $promise2); }); + \usleep(500*1000); } public function provideServersAndHostnames() {