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

[Redis] Fix messages sent with incorrect delivery delay #738

Merged
merged 2 commits into from
Jan 22, 2019
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
2 changes: 1 addition & 1 deletion pkg/redis/RedisProducer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function send(Destination $destination, Message $message): void
$payload = $this->context->getSerializer()->toString($message);

if ($message->getDeliveryDelay()) {
$deliveryAt = time() + $message->getDeliveryDelay();
$deliveryAt = time() + $message->getDeliveryDelay() / 1000;
$this->context->getRedis()->zadd($destination->getName().':delayed', $payload, $deliveryAt);
} else {
$this->context->getRedis()->lpush($destination->getName(), $payload);
Expand Down
39 changes: 39 additions & 0 deletions pkg/redis/Tests/RedisProducerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,45 @@ public function testShouldCallLPushOnSend()
$producer->send($destination, new RedisMessage());
}

/**
* Tests if Redis::zadd is called with the expected 'score' (used as delivery timestamp).
*
* @depends testShouldCallLPushOnSend
*/
public function testShouldCallZaddOnSendWithDeliveryDelay()
{
$destination = new RedisDestination('aDestination');

$redisMock = $this->createRedisMock();
$redisMock
->expects($this->once())
->method('zadd')
->with(
'aDestination:delayed',
$this->isJson(),
$this->equalTo(time() + 5)
)
;

$context = $this->createContextMock();
$context
->expects($this->once())
->method('getRedis')
->willReturn($redisMock)
;
$context
->expects($this->once())
->method('getSerializer')
->willReturn(new JsonSerializer())
;

$message = new RedisMessage();
$message->setDeliveryDelay(5000); // 5 seconds in milliseconds

$producer = new RedisProducer($context);
$producer->send($destination, $message);
}

/**
* @return \PHPUnit_Framework_MockObject_MockObject|RedisContext
*/
Expand Down