Skip to content

Commit

Permalink
Merge pull request #51 from Enoptea/master
Browse files Browse the repository at this point in the history
Change docker container IP detection
  • Loading branch information
bakura10 authored Aug 29, 2017
2 parents 93078f5 + ecb4d47 commit d0a395e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/MessageQueue/MessageQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/WorkerMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/MessageQueue/MessageQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit d0a395e

Please sign in to comment.