8000 bug #53187 [Messenger] Fix using negative delay (J-roen) · symfony/symfony@508c256 · GitHub
[go: up one dir, main page]

Skip to content

Commit 508c256

Browse files
committed
bug #53187 [Messenger] Fix using negative delay (J-roen)
This PR was squashed before being merged into the 5.4 branch. Discussion ---------- [Messenger] Fix using negative delay | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | Fix #50833 | License | MIT Fixes using negative delays when sending messages. Cherry-picked from #53088. Commits ------- af1517e [Messenger] Fix using negative delay
2 parents d34c8c4 + af1517e commit 508c256

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/DoctrineIntegrationTest.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,33 @@ public function testSendWithDelay()
7373
$stmt = $stmt->execute();
7474
}
7575

76-
$available_at = new \DateTime($stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchOne() : $stmt->fetchColumn());
76+
$availableAt = new \DateTime($stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchOne() : $stmt->fetchColumn());
7777

7878
$now = new \DateTime();
7979
$now->modify('+60 seconds');
80-
$this->assertGreaterThan($now, $available_at);
80+
$this->assertGreaterThan($now, $availableAt);
81+
}
82+
83+
public function testSendWithNegativeDelay()
84+
{
85+
$this->connection->send('{"message": "Hi I am not actually delayed"}', ['type' => DummyMessage::class], -600000);
86+
87+
$stmt = $this->driverConnection->createQueryBuilder()
88+
->select('m.available_at')
89+
->from('messenger_messages', 'm')
90+
->where('m.body = :body')
91+
->setParameter('body', '{"message": "Hi I am not actually delayed"}');
92+
if (method_exists($stmt, 'executeQuery')) {
93+
$stmt = $stmt->executeQuery();
94+
} else {
95+
$stmt = $stmt->execute();
96+
}
97+
98+
$availableAt = new \DateTime($stmt instanceof Result || $stmt instanceof DriverResult ? $stmt->fetchOne() : $stmt->fetchColumn());
99+
100+
$now = new \DateTime();
101+
$now->modify('-60 seconds');
102+
$this->assertLessThan($now, $availableAt);
81103
}
82104

83105
public function testItRetrieveTheFirstAvailableMessage()

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public static function buildConfiguration(string $dsn, array $options = []): arr
125125
public function send(string $body, array $headers, int $delay = 0): string
126126
{
127127
$now = new \DateTime();
128-
$availableAt = (clone $now)->modify(sprintf('+%d seconds', $delay / 1000));
128+
$availableAt = (clone $now)->modify(sprintf('%+d seconds', $delay / 1000));
129129

130130
$queryBuilder = $this->driverConnection->createQueryBuilder()
131131
->insert($this->configuration['table_name'])

0 commit comments

Comments
 (0)
0