Skip to content

[Messenger] [Redis] Remove BC layer around delete_after_ack option #42245

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
Jul 25, 2021
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
1 change: 1 addition & 0 deletions src/Symfony/Component/Messenger/Bridge/Redis/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ CHANGELOG

* Remove option `tls`
* Using invalid options will throw a `LogicException`
* The `delete_after_ack` config option now defaults to `true`

5.4
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testFromInvalidDsn()
public function testFromDsn()
{
$this->assertEquals(
new Connection(['stream' => 'queue', 'delete_after_ack' => true], [
new Connection(['stream' => 'queue'], [
'host' => 'localhost',
'port' => 6379,
]),
Expand All @@ -80,32 +80,32 @@ public function testFromDsnWithMultipleHosts()
}, $hosts);
$dsn = implode(',', $dsn);

$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn, ['delete_after_ack' => true]));
$this->assertInstanceOf(Connection::class, Connection::fromDsn($dsn));
}

public function testFromDsnOnUnixSocket()
{
$this->assertEquals(
new Connection(['stream' => 'queue', 'delete_after_ack' => true], [
new Connection(['stream' => 'queue'], [
'host' => '/var/run/redis/redis.sock',
'port' => 0,
], [], $redis = $this->createMock(\Redis::class)),
Connection::fromDsn('redis:///var/run/redis/redis.sock', ['stream' => 'queue', 'delete_after_ack' => true], $redis)
Connection::fromDsn('redis:///var/run/redis/redis.sock', ['stream' => 'queue'], $redis)
);
}

public function testFromDsnWithOptions()
{
$this->assertEquals(
Connection::fromDsn('redis://localhost', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2, 'delete_after_ack' => true]),
Connection::fromDsn('redis://localhost', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2]),
Connection::fromDsn('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0&delete_after_ack=1')
);
}

public function testFromDsnWithOptionsAndTrailingSlash()
{
$this->assertEquals(
Connection::fromDsn('redis://localhost/', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2, 'delete_after_ack' => true]),
Connection::fromDsn('redis://localhost/', ['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'auto_setup' => false, 'serializer' => 2]),
Connection::fromDsn('redis://localhost/queue/group1/consumer1?serializer=2&auto_setup=0&delete_after_ack=1')
);
}
Expand All @@ -124,7 +124,7 @@ public function testFromDsnWithRedissScheme()
public function testFromDsnWithQueryOptions()
{
$this->assertEquals(
new Connection(['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1', 'delete_after_ack' => true], [
new Connection(['stream' => 'queue', 'group' => 'group1', 'consumer' => 'consumer1'], [
'host' => 'localhost',
'port' => 6379,
], [
Expand All @@ -137,12 +137,12 @@ public function testFromDsnWithQueryOptions()
public function testFromDsnWithMixDsnQueryOptions()
{
$this->assertEquals(
Connection::fromDsn('redis://localhost/queue/group1?serializer=2', ['consumer' => 'specific-consumer', 'delete_after_ack' => true]),
Connection::fromDsn('redis://localhost/queue/group1?serializer=2', ['consumer' => 'specific-consumer']),
Connection::fromDsn('redis://localhost/queue/group1/specific-consumer?serializer=2&delete_after_ack=1')
);

$this->assertEquals(
Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['consumer' => 'specific-consumer', 'delete_after_ack' => true]),
Connection::fromDsn('redis://localhost/queue/group1/consumer1', ['consumer' => 'specific-consumer']),
Connection::fromDsn('redis://localhost/queue/group1/consumer1?delete_after_ack=1')
);
}
Expand All @@ -163,7 +163,7 @@ public function testKeepGettingPendingMessages()
->with('symfony', 'consumer', ['queue' => 0], 1, null)
->willReturn(['queue' => [['message' => '{"body":"Test","headers":[]}']]]);

$connection = Connection::fromDsn('redis://localhost/queue', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/queue', [], $redis);
$this->assertNotNull($connection->get());
$this->assertNotNull($connection->get());
$this->assertNotNull($connection->get());
Expand All @@ -177,7 +177,7 @@ public function testAuth()
->with('password')
->willReturn(true);

Connection::fromDsn('redis://password@localhost/queue', ['delete_after_ack' => true], $redis);
Connection::fromDsn('redis://password@localhost/queue', [], $redis);
}

public function testAuthFromOptions()
Expand All @@ -188,7 +188,7 @@ public function testAuthFromOptions()
->with('password')
->willReturn(true);

Connection::fromDsn('redis://localhost/queue', ['auth' => 'password', 'delete_after_ack' => true], $redis);
Connection::fromDsn('redis://localhost/queue', ['auth' => 'password'], $redis);
}

public function testAuthFromOptionsAndDsn()
Expand All @@ -199,7 +199,7 @@ public function testAuthFromOptionsAndDsn()
->with('password2')
->willReturn(true);

Connection::fromDsn('redis://password1@localhost/queue', ['auth' => 'password2', 'delete_after_ack' => true], $redis);
Connection::fromDsn('redis://password1@localhost/queue', ['auth' => 'password2'], $redis);
}

public function testNoAuthWithEmptyPassword()
Expand All @@ -210,7 +210,7 @@ public function testNoAuthWithEmptyPassword()
->with('')
->willThrowException(new \RuntimeException());

Connection::fromDsn('redis://@localhost/queue', ['delete_after_ack' => true], $redis);
Connection::fromDsn('redis://@localhost/queue', [], $redis);
}

public function testAuthZeroPassword()
Expand All @@ -221,7 +221,7 @@ public function testAuthZeroPassword()
->with('0')
->willReturn(true);

Connection::fromDsn('redis://0@localhost/queue', ['delete_after_ack' => true], $redis);
Connection::fromDsn('redis://0@localhost/queue', [], $redis);
}

public function testFailedAuth()
Expand All @@ -234,14 +234,14 @@ public function testFailedAuth()
->with('password')
->willReturn(false);

Connection::fromDsn('redis://password@localhost/queue', ['delete_after_ack' => true], $redis);
Connection::fromDsn('redis://password@localhost/queue', [], $redis);
}

public function testDbIndex()
{
$redis = new \Redis();

Connection::fromDsn('redis://localhost/queue?dbindex=2', ['delete_after_ack' => true], $redis);
Connection::fromDsn('redis://localhost/queue?dbindex=2', [], $redis);

$this->assertSame(2, $redis->getDbNum());
}
Expand All @@ -254,7 +254,7 @@ public function testGetPendingMessageFirst()
->with('symfony', 'consumer', ['queue' => '0'], 1, null)
->willReturn(['queue' => [['message' => '{"body":"1","headers":[]}']]]);

$connection = Connection::fromDsn('redis://localhost/queue', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/queue', [], $redis);
$connection->get();
}

Expand All @@ -280,7 +280,7 @@ public function testClaimAbandonedMessageWithRaceCondition()
->with('queue', 'symfony', 'consumer', 3600000, ['redisid-123'], ['JUSTID'])
->willReturn([]);

$connection = Connection::fromDsn('redis://localhost/queue', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/queue', [], $redis);
$connection->get();
}

Expand Down Expand Up @@ -308,7 +308,7 @@ public function testClaimAbandonedMessage()
->with('queue', 'symfony', 'consumer', 3600000, ['redisid-123'], ['JUSTID'])
->willReturn([]);

$connection = Connection::fromDsn('redis://localhost/queue', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/queue', [], $redis);
$connection->get();
}

Expand All @@ -320,22 +320,22 @@ public function testUnexpectedRedisError()
$redis->expects($this->once())->method('xreadgroup')->willReturn(false);
$redis->expects($this->once())->method('getLastError')->willReturn('Redis error happens');

$connection = Connection::fromDsn('redis://localhost/queue', ['auto_setup' => false, 'delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/queue', ['auto_setup' => false], $redis);
$connection->get();
}

public function testGetAfterReject()
{
$redis = new \Redis();
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', [], $redis);

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

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

$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['delete_after_ack' => true]);
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget');
$this->assertNotNull($connection->get());

$redis->del('messenger-rejectthenget');
Expand All @@ -345,7 +345,7 @@ public function testGetNonBlocking()
{
$redis = new \Redis();

$connection = Connection::fromDsn('redis://localhost/messenger-getnonblocking', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/messenger-getnonblocking', [], $redis);

$this->assertNull($connection->get()); // no message, should return null immediately
$connection->add('1', []);
Expand All @@ -357,7 +357,7 @@ public function testGetNonBlocking()
public function testJsonError()
{
$redis = new \Redis();
$connection = Connection::fromDsn('redis://localhost/json-error', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/json-error', [], $redis);
try {
$connection->add("\xB1\x31", []);
} catch (TransportException $e) {
Expand All @@ -374,7 +374,7 @@ public function testMaxEntries()
->with('queue', '*', ['message' => '{"body":"1","headers":[]}'], 20000, true)
->willReturn(1);

$connection = Connection::fromDsn('redis://localhost/queue?stream_max_entries=20000', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/queue?stream_max_entries=20000', [], $redis);
$connection->add('1', []);
}

Expand All @@ -393,16 +393,6 @@ public function testDeleteAfterAck()
$connection->ack('1');
}

/**
* @group legacy
*/
public function testLegacyOmitDeleteAfterAck()
{
$this->expectDeprecation('Since symfony/redis-messenger 5.4: Not setting the "delete_after_ack" boolean option explicitly is deprecated, its default value will change to true in 6.0.');

Connection::fromDsn('redis://localhost/queue');
}

public function testDeleteAfterReject()
{
$redis = $this->createMock(\Redis::class);
Expand All @@ -414,7 +404,7 @@ public function testDeleteAfterReject()
->with('queue', ['1'])
->willReturn(1);

$connection = Connection::fromDsn('redis://localhost/queue?delete_after_reject=true', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/queue?delete_after_reject=true', [], $redis);
$connection->reject('1');
}

Expand All @@ -428,7 +418,7 @@ public function testLastErrorGetsCleared()
$redis->method('getLastError')->willReturnOnConsecutiveCalls('xadd error', 'xack error');
$redis->expects($this->exactly(2))->method('clearLastError');

$connection = Connection::fromDsn('redis://localhost/messenger-clearlasterror', ['auto_setup' => false, 'delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/messenger-clearlasterror', ['auto_setup' => false], $redis);

try {
$connection->add('message', []);
Expand All @@ -448,7 +438,7 @@ public function testLastErrorGetsCleared()
public function testLazy()
{
$redis = new \Redis();
$connection = Connection::fromDsn('redis://localhost/messenger-lazy?lazy=1', ['delete_after_ack' => true], $redis);
$connection = Connection::fromDsn('redis://localhost/messenger-lazy?lazy=1', [], $redis);

$connection->add('1', []);
$this->assertNotEmpty($message = $connection->get());
Expand All @@ -464,7 +454,7 @@ public function testLazyCluster()
$connection = new Connection(
['lazy' => true],
['host' => explode(' ', getenv('REDIS_CLUSTER_HOSTS'))],
['delete_after_ack' => true]
[]
);

$connection->add('1', []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ protected function setUp(): void

try {
$this->redis = new \Redis();
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['delete_after_ack' => true], $this->redis);
$this->connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), [], $this->redis);
$this->connection->cleanup();
$this->connection->setup();
} catch (\Exception $e) {
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testConnectionSendDelayedMessagesWithSameContent()
public function testConnectionBelowRedeliverTimeout()
{
// lower redeliver timeout and claim interval
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), ['delete_after_ack' => true], $this->redis);
$connection = Connection::fromDsn(getenv('MESSENGER_REDIS_DSN'), [], $this->redis);

$connection->cleanup();
$connection->setup();
Expand Down Expand Up @@ -137,7 +137,7 @@ public function testConnectionClaimAndRedeliver()
// lower redeliver timeout and claim interval
$connection = Connection::fromDsn(
getenv('MESSENGER_REDIS_DSN'),
['redeliver_timeout' => 0, 'claim_interval' => 500, 'delete_after_ack' => true],
['redeliver_timeout' => 0, 'claim_interval' => 500],
$this->redis
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Connection
'group' => 'symfony',
'consumer' => 'consumer',
'auto_setup' => true,
'delete_after_ack' => false,
'delete_after_ack' => true,
'delete_after_reject' => true,
'stream_max_entries' => 0, // any value higher than 0 defines an approximate maximum number of stream entries
'dbindex' => 0,
Expand Down Expand Up @@ -175,8 +175,6 @@ public static function fromDsn(string $dsn, array $redisOptions = [], \Redis|\Re
if (\array_key_exists('delete_after_ack', $redisOptions)) {
$deleteAfterAck = filter_var($redisOptions['delete_after_ack'], \FILTER_VALIDATE_BOOLEAN);
unset($redisOptions['delete_after_ack']);
} else {
trigger_deprecation('symfony/redis-messenger', '5.4', 'Not setting the "delete_after_ack" boolean option explicitly is deprecated, its default value will change to true in 6.0.');
}

$deleteAfterReject = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@ public function __construct(?string $globalFailureReceiverName, ServiceProviderI
parent::__construct();
}

protected function getReceiverName(): string
{
trigger_deprecation('symfony/messenger', '5.3', 'The method "%s()" is deprecated, use getGlobalFailureReceiverName() instead.', __METHOD__);

return $this->globalFailureReceiverName;
}
Copy link
Member Author

@chalasr chalasr Jul 23, 2021

Choose a reason for hiding this comment

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

unrelated change, but makes the bridge deprec-free. The class is internal so no need for a changelog entry (we didn't even add one when deprecating)


protected function getGlobalFailureReceiverName(): ?string
{
return $this->globalFailureReceiverName;
Expand Down