-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Re-subscribes to the scaling channel when the underlying connec…
…tion is lost (#251) * Re-subscribe to the scaling channel when the connection drops * add tests * Update RedisPubSubProvider.php --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
- Loading branch information
1 parent
1cf239d
commit 65631f1
Showing
2 changed files
with
50 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
tests/Unit/Servers/Reverb/Publishing/RedisPubSubProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
use Clue\React\Redis\Client; | ||
use Laravel\Reverb\Servers\Reverb\Contracts\PubSubIncomingMessageHandler; | ||
use Laravel\Reverb\Servers\Reverb\Publishing\RedisPubSubProvider; | ||
use Laravel\Reverb\Servers\Reverb\Publishing\RedisClientFactory; | ||
use React\EventLoop\LoopInterface; | ||
|
||
it('resubscribes to the scaling channel on unsubscribe event', function (){ | ||
|
||
$channel = "reverb"; | ||
$subscribingClient = Mockery::mock(Client::class); | ||
|
||
$subscribingClient->shouldReceive('on') | ||
->with('unsubscribe', Mockery::on(function ($callback) use ($channel) { | ||
$callback($channel); | ||
return true; | ||
}))->once(); | ||
|
||
$subscribingClient->shouldReceive('on') | ||
->with('message', Mockery::any()) | ||
->zeroOrMoreTimes(); | ||
|
||
$subscribingClient->shouldReceive('subscribe') | ||
->twice() | ||
->with($channel); | ||
|
||
|
||
$clientFactory = Mockery::mock(RedisClientFactory::class); | ||
|
||
// The first call to make() will return a publishing client | ||
$clientFactory->shouldReceive('make') | ||
->once() | ||
->andReturn(Mockery::mock(Client::class)); | ||
|
||
$clientFactory->shouldReceive('make') | ||
->once() | ||
->andReturn($subscribingClient); | ||
|
||
$provider = new RedisPubSubProvider($clientFactory, Mockery::mock(PubSubIncomingMessageHandler::class), $channel); | ||
$provider->connect(Mockery::mock(LoopInterface::class)); | ||
|
||
$provider->subscribe(); | ||
}); |