From b7cf3407e7e3c823d85325a6c3423071cb1c04ac Mon Sep 17 00:00:00 2001 From: Gaultier Boniface Date: Tue, 29 Aug 2017 14:14:12 +0200 Subject: [PATCH 1/3] Change docker container IP detection MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docker container IP detection is not really working when using docker for Mac. --- src/Middleware/WorkerMiddleware.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Middleware/WorkerMiddleware.php b/src/Middleware/WorkerMiddleware.php index 1177017..8425847 100644 --- a/src/Middleware/WorkerMiddleware.php +++ b/src/Middleware/WorkerMiddleware.php @@ -154,7 +154,7 @@ private function assertLocalhost(ServerRequestInterface $request) $remoteAddr = $serverParams['REMOTE_ADDR'] ?? 'unknown IP address'; // If request is not originating from localhost or from Docker local IP, we throw an RuntimeException - if (!in_array($remoteAddr, self::LOCALHOST_ADDRESSES) && !fnmatch('172.17.*', $remoteAddr)) { + if (!in_array($remoteAddr, self::LOCALHOST_ADDRESSES) && !fnmatch('172.1*.*', $remoteAddr)) { throw new RuntimeException(sprintf( 'Worker requests must come from localhost, request originated from %s given', $remoteAddr From a4e1e790d3b020f8b188bbd94c2729de122d3143 Mon Sep 17 00:00:00 2001 From: Gaultier Boniface Date: Tue, 29 Aug 2017 16:34:29 +0200 Subject: [PATCH 2/3] Fix async call to SQS send message batch to really send messages. --- src/MessageQueue/MessageQueue.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/MessageQueue/MessageQueue.php b/src/MessageQueue/MessageQueue.php index 6dd1e06..a54a9c1 100644 --- a/src/MessageQueue/MessageQueue.php +++ b/src/MessageQueue/MessageQueue.php @@ -151,7 +151,9 @@ private function doFlush(bool $async) } if ($async) { - $this->sqsClient->sendMessageBatchAsync($parameters); + $promise = $this->sqsClient->sendMessageBatchAsync($parameters); + + $promise->wait(); } else { $this->sqsClient->sendMessageBatch($parameters); } From ecb4d475f7b145027aa9cc77d1974eec7c57c108 Mon Sep 17 00:00:00 2001 From: Gaultier Boniface Date: Tue, 29 Aug 2017 18:29:20 +0200 Subject: [PATCH 3/3] Fixing tests. --- test/MessageQueue/MessageQueueTest.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/MessageQueue/MessageQueueTest.php b/test/MessageQueue/MessageQueueTest.php index 6415fb2..dc50296 100644 --- a/test/MessageQueue/MessageQueueTest.php +++ b/test/MessageQueue/MessageQueueTest.php @@ -19,6 +19,7 @@ namespace ZfrEbWorkerTest\MessageQueue; use Aws\Sqs\SqsClient; +use GuzzleHttp\Promise\Promise; use Prophecy\Argument; use ZfrEbWorker\Message\DelayedMessage; use ZfrEbWorker\Message\Message; @@ -31,9 +32,15 @@ class MessageQueueTest extends \PHPUnit_Framework_TestCase */ private $sqsClient; + /** + * @var \Prophecy\Prophecy\ObjectProphecy + */ + private $promise; + public function setUp() { $this->sqsClient = $this->prophesize(SqsClient::class); + $this->promise = $this->prophesize(Promise::class); } public function pushMode() @@ -67,6 +74,8 @@ public function testCanPushToQueue(bool $async) ]; if ($async) { + $this->promise->wait()->shouldBeCalled(); + $this->sqsClient->sendMessageBatchAsync($expectedPayload)->willReturn($this->promise); $this->sqsClient->sendMessageBatchAsync($expectedPayload)->shouldBeCalled(); } else { $this->sqsClient->sendMessageBatch($expectedPayload)->shouldBeCalled();