Skip to content

Commit e67d4fc

Browse files
committed
update: reconnect tests
1 parent 826ed95 commit e67d4fc

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

tests/Feature/QueueTest.php

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ public function setUp(): void
1515
parent::setUp();
1616

1717
$this->withoutExceptionHandling([
18-
AMQPChannelClosedException::class, AMQPConnectionClosedException::class, AMQPProtocolChannelException::class,
18+
AMQPChannelClosedException::class, AMQPConnectionClosedException::class,
19+
AMQPProtocolChannelException::class,
1920
]);
2021
}
2122

@@ -39,24 +40,4 @@ public function testWithoutReconnect(): void
3940
$this->expectException(AMQPChannelClosedException::class);
4041
$queue->push(new TestJob());
4142
}
42-
43-
public function testReconnect(): void
44-
{
45-
$this->markTestSkipped();
46-
47-
$queue = $this->connection('octane');
48-
49-
$queue->push(new TestJob());
50-
sleep(1);
51-
$this->assertSame(1, $queue->size());
52-
53-
// close connection
54-
$queue->getConnection()->close();
55-
$this->assertFalse($queue->getConnection()->isConnected());
56-
57-
$queue->push(new TestJob());
58-
sleep(1);
59-
$this->assertTrue($queue->getConnection()->isConnected());
60-
$this->assertSame(2, $queue->size());
61-
}
6243
}

tests/Functional/TestCase.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace VladimirYuldashev\LaravelQueueRabbitMQ\Tests\Functional;
44

55
use Exception;
6+
use PhpAmqpLib\Channel\AMQPChannel;
67
use ReflectionClass;
78
use ReflectionException;
89
use VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase as BaseTestCase;
@@ -234,4 +235,34 @@ protected function callProperty($object, string $property): mixed
234235

235236
return $property->getValue($object);
236237
}
238+
239+
public function testConnectChannel(): void
240+
{
241+
$queue = $this->connection();
242+
$this->assertFalse($queue->getConnection()->isConnected());
243+
244+
/** @var AMQPChannel $channel */
245+
$channel = $this->callMethod($queue, 'getChannel');
246+
$this->assertTrue($queue->getConnection()->isConnected());
247+
$this->assertSame($channel, $this->callProperty($queue, 'channel'));
248+
$this->assertTrue($channel->is_open());
249+
}
250+
251+
public function testReconnect(): void
252+
{
253+
$queue = $this->connection();
254+
$this->assertFalse($queue->getConnection()->isConnected());
255+
256+
// connect
257+
$channel = $this->callMethod($queue, 'getChannel');
258+
$this->assertTrue($queue->getConnection()->isConnected());
259+
$this->assertSame($channel, $this->callProperty($queue, 'channel'));
260+
261+
// reconnect
262+
$queue->getConnection()->close();
263+
$this->assertFalse($queue->getConnection()->isConnected());
264+
$this->callMethod($queue, 'reconnect');
265+
$this->assertTrue($queue->getConnection()->isConnected());
266+
$this->assertTrue($queue->getChannel()->is_open());
267+
}
237268
}

0 commit comments

Comments
 (0)