Fixed tests
This commit is contained in:
parent
bb1a03051a
commit
7365189aaa
|
|
@ -152,9 +152,9 @@ class PresenceChannelTest extends TestCase
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getChannelMembers('1234', 'presence-channel')
|
->getChannelMembers('1234', 'presence-channel')
|
||||||
->then(function ($members) {
|
->then(function ($members) use ($rick) {
|
||||||
$this->assertCount(1, $members);
|
$this->assertCount(1, $members);
|
||||||
$this->assertEquals(1, $members[0]->user_id);
|
$this->assertEquals(1, $members[$rick->socketId]->user_id);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Test;
|
namespace BeyondCode\LaravelWebSockets\Test;
|
||||||
|
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class ReplicationTest extends TestCase
|
class ReplicationTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|
@ -61,13 +63,23 @@ class ReplicationTest extends TestCase
|
||||||
|
|
||||||
public function test_not_ponged_connections_do_get_removed_for_public_channels()
|
public function test_not_ponged_connections_do_get_removed_for_public_channels()
|
||||||
{
|
{
|
||||||
$connection = $this->newActiveConnection(['public-channel']);
|
$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.
|
// Make the connection look like it was lost 1 day ago.
|
||||||
$this->channelManager->addConnectionToSet($connection, now()->subDays(1));
|
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))
|
->getGlobalConnectionsCount('1234', 'public-channel')
|
||||||
|
->then(function ($count) {
|
||||||
|
$this->assertEquals(2, $count);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->channelManager
|
||||||
|
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
|
||||||
->then(function ($expiredConnections) {
|
->then(function ($expiredConnections) {
|
||||||
$this->assertCount(1, $expiredConnections);
|
$this->assertCount(1, $expiredConnections);
|
||||||
});
|
});
|
||||||
|
|
@ -77,11 +89,11 @@ class ReplicationTest extends TestCase
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getGlobalConnectionsCount('1234', 'public-channel')
|
->getGlobalConnectionsCount('1234', 'public-channel')
|
||||||
->then(function ($count) {
|
->then(function ($count) {
|
||||||
$this->assertEquals(0, $count);
|
$this->assertEquals(1, $count);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))
|
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
|
||||||
->then(function ($expiredConnections) {
|
->then(function ($expiredConnections) {
|
||||||
$this->assertCount(0, $expiredConnections);
|
$this->assertCount(0, $expiredConnections);
|
||||||
});
|
});
|
||||||
|
|
@ -89,13 +101,23 @@ class ReplicationTest extends TestCase
|
||||||
|
|
||||||
public function test_not_ponged_connections_do_get_removed_for_private_channels()
|
public function test_not_ponged_connections_do_get_removed_for_private_channels()
|
||||||
{
|
{
|
||||||
$connection = $this->newPrivateConnection('private-channel');
|
$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.
|
// Make the connection look like it was lost 1 day ago.
|
||||||
$this->channelManager->addConnectionToSet($connection, now()->subDays(1));
|
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))
|
->getGlobalConnectionsCount('1234', 'private-channel')
|
||||||
|
->then(function ($count) {
|
||||||
|
$this->assertEquals(2, $count);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->channelManager
|
||||||
|
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
|
||||||
->then(function ($expiredConnections) {
|
->then(function ($expiredConnections) {
|
||||||
$this->assertCount(1, $expiredConnections);
|
$this->assertCount(1, $expiredConnections);
|
||||||
});
|
});
|
||||||
|
|
@ -105,11 +127,11 @@ class ReplicationTest extends TestCase
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getGlobalConnectionsCount('1234', 'private-channel')
|
->getGlobalConnectionsCount('1234', 'private-channel')
|
||||||
->then(function ($count) {
|
->then(function ($count) {
|
||||||
$this->assertEquals(0, $count);
|
$this->assertEquals(1, $count);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))
|
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
|
||||||
->then(function ($expiredConnections) {
|
->then(function ($expiredConnections) {
|
||||||
$this->assertCount(0, $expiredConnections);
|
$this->assertCount(0, $expiredConnections);
|
||||||
});
|
});
|
||||||
|
|
@ -117,13 +139,23 @@ class ReplicationTest extends TestCase
|
||||||
|
|
||||||
public function test_not_ponged_connections_do_get_removed_for_presence_channels()
|
public function test_not_ponged_connections_do_get_removed_for_presence_channels()
|
||||||
{
|
{
|
||||||
$connection = $this->newPresenceConnection('presence-channel');
|
$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.
|
// Make the connection look like it was lost 1 day ago.
|
||||||
$this->channelManager->addConnectionToSet($connection, now()->subDays(1));
|
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))
|
->getGlobalConnectionsCount('1234', 'presence-channel')
|
||||||
|
->then(function ($count) {
|
||||||
|
$this->assertEquals(2, $count);
|
||||||
|
});
|
||||||
|
|
||||||
|
$this->channelManager
|
||||||
|
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
|
||||||
->then(function ($expiredConnections) {
|
->then(function ($expiredConnections) {
|
||||||
$this->assertCount(1, $expiredConnections);
|
$this->assertCount(1, $expiredConnections);
|
||||||
});
|
});
|
||||||
|
|
@ -131,19 +163,19 @@ class ReplicationTest extends TestCase
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getChannelMembers('1234', 'presence-channel')
|
->getChannelMembers('1234', 'presence-channel')
|
||||||
->then(function ($members) {
|
->then(function ($members) {
|
||||||
$this->assertCount(1, $members);
|
$this->assertCount(2, $members);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->channelManager->removeObsoleteConnections();
|
$this->channelManager->removeObsoleteConnections();
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getGlobalConnectionsCount('1234', 'private-channel')
|
->getGlobalConnectionsCount('1234', 'presence-channel')
|
||||||
->then(function ($count) {
|
->then(function ($count) {
|
||||||
$this->assertEquals(0, $count);
|
$this->assertEquals(1, $count);
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getConnectionsFromSet(0, now()->subMinutes(2)->format('U'))
|
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
|
||||||
->then(function ($expiredConnections) {
|
->then(function ($expiredConnections) {
|
||||||
$this->assertCount(0, $expiredConnections);
|
$this->assertCount(0, $expiredConnections);
|
||||||
});
|
});
|
||||||
|
|
@ -151,7 +183,7 @@ class ReplicationTest extends TestCase
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
->getChannelMembers('1234', 'presence-channel')
|
->getChannelMembers('1234', 'presence-channel')
|
||||||
->then(function ($members) {
|
->then(function ($members) {
|
||||||
$this->assertCount(0, $members);
|
$this->assertCount(1, $members);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -65,7 +65,7 @@ class TriggerEventTest extends TestCase
|
||||||
|
|
||||||
$this->statisticsCollector
|
$this->statisticsCollector
|
||||||
->getAppStatistics('1234')
|
->getAppStatistics('1234')
|
||||||
->then(function ($statistics) {
|
->then(function ($statistic) {
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'peak_connections_count' => 1,
|
'peak_connections_count' => 1,
|
||||||
'websocket_messages_count' => 1,
|
'websocket_messages_count' => 1,
|
||||||
|
|
@ -106,7 +106,7 @@ class TriggerEventTest extends TestCase
|
||||||
|
|
||||||
$this->statisticsCollector
|
$this->statisticsCollector
|
||||||
->getAppStatistics('1234')
|
->getAppStatistics('1234')
|
||||||
->then(function ($statistics) {
|
->then(function ($statistic) {
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'peak_connections_count' => 1,
|
'peak_connections_count' => 1,
|
||||||
'websocket_messages_count' => 1,
|
'websocket_messages_count' => 1,
|
||||||
|
|
@ -147,7 +147,7 @@ class TriggerEventTest extends TestCase
|
||||||
|
|
||||||
$this->statisticsCollector
|
$this->statisticsCollector
|
||||||
->getAppStatistics('1234')
|
->getAppStatistics('1234')
|
||||||
->then(function ($statistics) {
|
->then(function ($statistic) {
|
||||||
$this->assertEquals([
|
$this->assertEquals([
|
||||||
'peak_connections_count' => 1,
|
'peak_connections_count' => 1,
|
||||||
'websocket_messages_count' => 1,
|
'websocket_messages_count' => 1,
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue