diff --git a/tests/PresenceChannelTest.php b/tests/PresenceChannelTest.php index 9234ab8..1660e50 100644 --- a/tests/PresenceChannelTest.php +++ b/tests/PresenceChannelTest.php @@ -318,58 +318,6 @@ class PresenceChannelTest extends TestCase }); } - public function test_not_ponged_connections_do_get_removed_for_presence_channels() - { - $this->runOnlyOnRedisReplication(); - - $activeConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 1]); - $obsoleteConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 2]); - - // The active connection just pinged, it should not be closed. - $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); - - // Make the connection look like it was lost 1 day ago. - $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'presence-channel') - ->then(function ($count) { - $this->assertEquals(2, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(1, $expiredConnections); - }); - - $this->channelManager - ->getChannelMembers('1234', 'presence-channel') - ->then(function ($members) { - $this->assertCount(2, $members); - }); - - $this->channelManager->removeObsoleteConnections(); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'presence-channel') - ->then(function ($count) { - $this->assertEquals(1, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(0, $expiredConnections); - }); - - $this->channelManager - ->getChannelMembers('1234', 'presence-channel') - ->then(function ($members) { - $this->assertCount(1, $members); - }); - } - public function test_events_are_processed_by_on_message_on_presence_channels() { $this->runOnlyOnRedisReplication(); diff --git a/tests/PrivateChannelTest.php b/tests/PrivateChannelTest.php index 8708bda..1cca6d3 100644 --- a/tests/PrivateChannelTest.php +++ b/tests/PrivateChannelTest.php @@ -159,46 +159,6 @@ class PrivateChannelTest extends TestCase }); } - public function test_not_ponged_connections_do_get_removed_for_private_channels() - { - $this->runOnlyOnRedisReplication(); - - $activeConnection = $this->newPrivateConnection('private-channel'); - $obsoleteConnection = $this->newPrivateConnection('private-channel'); - - // The active connection just pinged, it should not be closed. - $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); - - // Make the connection look like it was lost 1 day ago. - $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'private-channel') - ->then(function ($count) { - $this->assertEquals(2, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(1, $expiredConnections); - }); - - $this->channelManager->removeObsoleteConnections(); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'private-channel') - ->then(function ($count) { - $this->assertEquals(1, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(0, $expiredConnections); - }); - } - public function test_events_are_processed_by_on_message_on_private_channels() { $this->runOnlyOnRedisReplication(); diff --git a/tests/PublicChannelTest.php b/tests/PublicChannelTest.php index 84f0d17..50ebc5b 100644 --- a/tests/PublicChannelTest.php +++ b/tests/PublicChannelTest.php @@ -140,46 +140,6 @@ class PublicChannelTest extends TestCase }); } - public function test_not_ponged_connections_do_get_removed_for_public_channels() - { - $this->runOnlyOnRedisReplication(); - - $activeConnection = $this->newActiveConnection(['public-channel']); - $obsoleteConnection = $this->newActiveConnection(['public-channel']); - - // The active connection just pinged, it should not be closed. - $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); - - // Make the connection look like it was lost 1 day ago. - $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'public-channel') - ->then(function ($count) { - $this->assertEquals(2, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(1, $expiredConnections); - }); - - $this->channelManager->removeObsoleteConnections(); - - $this->channelManager - ->getGlobalConnectionsCount('1234', 'public-channel') - ->then(function ($count) { - $this->assertEquals(1, $count); - }); - - $this->channelManager - ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) - ->then(function ($expiredConnections) { - $this->assertCount(0, $expiredConnections); - }); - } - public function test_events_are_processed_by_on_message_on_public_channels() { $this->runOnlyOnRedisReplication(); diff --git a/tests/RedisPongRemovalTest.php b/tests/RedisPongRemovalTest.php new file mode 100644 index 0000000..14410fb --- /dev/null +++ b/tests/RedisPongRemovalTest.php @@ -0,0 +1,140 @@ +runOnlyOnRedisReplication(); + + $activeConnection = $this->newActiveConnection(['public-channel']); + $obsoleteConnection = $this->newActiveConnection(['public-channel']); + + // The active connection just pinged, it should not be closed. + $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); + + // Make the connection look like it was lost 1 day ago. + $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'public-channel') + ->then(function ($count) { + $this->assertEquals(2, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(1, $expiredConnections); + }); + + $this->channelManager->removeObsoleteConnections(); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'public-channel') + ->then(function ($count) { + $this->assertEquals(1, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(0, $expiredConnections); + }); + } + + public function test_not_ponged_connections_do_get_removed_on_redis_for_private_channels() + { + $this->runOnlyOnRedisReplication(); + + $activeConnection = $this->newPrivateConnection('private-channel'); + $obsoleteConnection = $this->newPrivateConnection('private-channel'); + + // The active connection just pinged, it should not be closed. + $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); + + // Make the connection look like it was lost 1 day ago. + $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'private-channel') + ->then(function ($count) { + $this->assertEquals(2, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(1, $expiredConnections); + }); + + $this->channelManager->removeObsoleteConnections(); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'private-channel') + ->then(function ($count) { + $this->assertEquals(1, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(0, $expiredConnections); + }); + } + + public function test_not_ponged_connections_do_get_removed_on_redis_for_presence_channels() + { + $this->runOnlyOnRedisReplication(); + + $activeConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 1]); + $obsoleteConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 2]); + + // The active connection just pinged, it should not be closed. + $this->channelManager->addConnectionToSet($activeConnection, Carbon::now()); + + // Make the connection look like it was lost 1 day ago. + $this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1)); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'presence-channel') + ->then(function ($count) { + $this->assertEquals(2, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(1, $expiredConnections); + }); + + $this->channelManager + ->getChannelMembers('1234', 'presence-channel') + ->then(function ($members) { + $this->assertCount(2, $members); + }); + + $this->channelManager->removeObsoleteConnections(); + + $this->channelManager + ->getGlobalConnectionsCount('1234', 'presence-channel') + ->then(function ($count) { + $this->assertEquals(1, $count); + }); + + $this->channelManager + ->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U')) + ->then(function ($expiredConnections) { + $this->assertCount(0, $expiredConnections); + }); + + $this->channelManager + ->getChannelMembers('1234', 'presence-channel') + ->then(function ($members) { + $this->assertCount(1, $members); + }); + } +}