8000 [Messenger] Fix Redis Connection::get() after reject() by chalasr · Pull Request #31387 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[Messenger] Fix Redis Connection::get() after reject() #31387

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

Merged
merged 1 commit into from
May 6, 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
Original file line number Diff line number Diff line change
Expand Up @@ -112,4 +112,22 @@ public function testUnexpectedRedisError()
$connection = Connection::fromDsn('redis://localhost/queue', [], $redis);
$connection->get();
}

public function testGetAfterReject()
{
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget');
try {
$connection->setup();
} catch (TransportException $e) {
}

$connection->add('1', []);
$connection->add('2', []);

$failing = $connection->get();
$connection->reject($failing['id']);

$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget');
$this->assertNotNull($connection->get());
}
}
8 changes: 4 additions & 4 deletions
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function get(): ?array
} catch (\RedisException $e) {
}

if (false === $messages || $e) {
if ($e || (false === $messages && !$this->couldHavePendingMessages)) {
throw new TransportException(
($e ? $e->getMessage() : $this->connection->getLastError()) ?? 'Could not read messages from the redis stream.'
);
Expand Down Expand Up @@ -123,7 +123,7 @@ public function ack(string $id): void
} catch (\RedisException $e) {
}

if (!$acknowledged || $e) {
if ($e || !$acknowledged) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated: if $e is not null then $acknowledged is undefined.

throw new TransportException(($e ? $e->getMessage() : $this->connection->getLastError()) ?? sprintf('Could not acknowledge redis message "%s".', $id), 0, $e);
}
}
Expand All @@ -136,7 +136,7 @@ public function reject(string $id): void
} catch (\RedisException $e) {
}

if (!$deleted || $e) {
if ($e || !$deleted) {
throw new TransportException(($e ? $e->getMessage() : $this->connection->getLastError()) ?? sprintf('Could not delete message "%s" from the redis stream.', $id), 0, $e);
}
}
Expand All @@ -151,7 +151,7 @@ public function add(string $body, array $headers)
} catch (\RedisException $e) {
}

if (!$added || $e) {
if ($e || !$added) {
throw new TransportException(($e ? $e->getMessage() : $this->connection->getLastError()) ?? 'Could not add a message to the redis stream.', 0, $e);
}
}
Expand Down
0