Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 94461f9

Browse filesBrowse files
[Messenger] Add missing Redis cleanup in tests
1 parent 52839be commit 94461f9
Copy full SHA for 94461f9

File tree

Expand file treeCollapse file tree

1 file changed

+37
-25
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+37
-25
lines changed

‎src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisExtIntegrationTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Redis/Tests/Transport/RedisExtIntegrationTest.php
+37-25Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -246,15 +246,19 @@ public function testLazy()
246246
$connection = Connection::fromDsn('redis://localhost/messenger-lazy?lazy=1', ['delete_after_ack' => true], $redis);
247247

248248
$connection->add('1', []);
249-
$this->assertNotEmpty($message = $connection->get());
250-
$this->assertSame([
251-
'message' => json_encode([
252-
'body' => '1',
253-
'headers' => [],
254-
]),
255-
], $message['data']);
256-
$connection->reject($message['id']);
257-
$redis->del('messenger-lazy');
249+
250+
try {
251+
$this->assertNotEmpty($message = $connection->get());
252+
$this->assertSame([
253+
'message' => json_encode([
254+
'body' => '1',
255+
'headers' => [],
256+
]),
257+
], $message['data']);
258+
$connection->reject($message['id']);
259+
} finally {
260+
$redis->del('messenger-lazy');
261+
}
258262
}
259263

260264
public function testDbIndex()
@@ -283,13 +287,16 @@ public function testFromDsnWithMultipleHosts()
283287
public function testJsonError()
284288
{
285289
$redis = new \Redis();
286-
$connection = Connection::fromDsn('redis://localhost/json-error', ['delete_after_ack' => true], $redis);
290+
$connection = Connection::fromDsn('redis://localhost/messenger-json-error', ['delete_after_ack' => true], $redis);
287291
try {
288292
$connection->add("\xB1\x31", []);
293+
294+
$this->fail('Expected exception to be thrown.');
289295
} catch (TransportException $e) {
296+
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
297+
} finally {
298+
$redis->del('messenger-json-error');
290299
}
291-
292-
$this->assertSame('Malformed UTF-8 characters, possibly incorrectly encoded', $e->getMessage());
293300
}
294301

295302
public function testGetNonBlocking()
@@ -298,28 +305,33 @@ public function testGetNonBlocking()
298305

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

301-
$this->assertNull($connection->get()); // no message, should return null immediately
302-
$connection->add('1', []);
303-
$this->assertNotEmpty($message = $connection->get());
304-
$connection->reject($message['id']);
305-
$redis->del('messenger-getnonblocking');
308+
try {
309+
$this->assertNull($connection->get()); // no message, should return null immediately
310+
$connection->add('1', []);
311+
$this->assertNotEmpty($message = $connection->get());
312+
$connection->reject($message['id']);
313+
} finally {
314+
$redis->del('messenger-getnonblocking');
315+
}
306316
}
307317

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

313-
$connection->add('1', []);
314-
$connection->add('2', []);
315-
316-
$failing = $connection->get();
317-
$connection->reject($failing['id']);
323+
try {
324+
$connection->add('1', []);
325+
$connection->add('2', []);
318326

319-
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['delete_after_ack' => true]);
320-
$this->assertNotNull($connection->get());
327+
$failing = $connection->get();
328+
$connection->reject($failing['id']);
321329

322-
$redis->del('messenger-rejectthenget');
330+
$connection = Connection::fromDsn('redis://localhost/messenger-rejectthenget', ['delete_after_ack' => true]);
331+
$this->assertNotNull($connection->get());
332+
} finally {
333+
$redis->del('messenger-rejectthenget');
334+
}
323335
}
324336

325337
public function testItProperlyHandlesEmptyMessages()

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.