Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit c7aea38

Browse files
committed
Testing
1 parent 9a0d56d commit c7aea38

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

tests/PresenceChannelTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,18 @@ public function test_connect_to_presence_channel_when_user_with_same_ids_is_alre
117117
$this->channelManager->getChannelMembers('1234', 'presence-channel')->then(function ($members) {
118118
$this->assertCount(2, $members);
119119
});
120+
121+
$this->pusherServer->onClose($rick);
122+
$this->pusherServer->onClose($morty);
123+
$this->pusherServer->onClose($pickleRick);
124+
125+
$this->channelManager->getGlobalConnectionsCount('1234', 'presence-channel')->then(function ($total) {
126+
$this->assertEquals(3, $total);
127+
});
128+
129+
$this->channelManager->getChannelMembers('1234', 'presence-channel')->then(function ($members) {
130+
$this->assertCount(2, $members);
131+
});
120132
}
121133

122134
public function test_presence_channel_broadcast_member_events()

tests/StatisticsStoreTest.php

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,23 @@ public function test_store_statistics_on_public_channel()
1616
$this->assertEquals('2', $records[0]['peak_connections_count']);
1717
$this->assertEquals('2', $records[0]['websocket_messages_count']);
1818
$this->assertEquals('0', $records[0]['api_messages_count']);
19+
20+
$this->pusherServer->onClose($rick);
21+
$this->pusherServer->onClose($morty);
22+
23+
$this->statisticsCollector->save();
24+
25+
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
26+
27+
$this->assertEquals('2', $records[1]['peak_connections_count']);
28+
$this->assertEquals('0', $records[1]['websocket_messages_count']);
29+
$this->assertEquals('0', $records[1]['api_messages_count']);
30+
31+
$this->statisticsCollector->save();
32+
33+
// The last one should not generate any more records
34+
// since the current state is empty.
35+
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
1936
}
2037

2138
public function test_store_statistics_on_private_channel()
@@ -30,19 +47,55 @@ public function test_store_statistics_on_private_channel()
3047
$this->assertEquals('2', $records[0]['peak_connections_count']);
3148
$this->assertEquals('2', $records[0]['websocket_messages_count']);
3249
$this->assertEquals('0', $records[0]['api_messages_count']);
50+
51+
$this->pusherServer->onClose($rick);
52+
$this->pusherServer->onClose($morty);
53+
54+
$this->statisticsCollector->save();
55+
56+
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
57+
58+
$this->assertEquals('2', $records[1]['peak_connections_count']);
59+
$this->assertEquals('0', $records[1]['websocket_messages_count']);
60+
$this->assertEquals('0', $records[1]['api_messages_count']);
61+
62+
$this->statisticsCollector->save();
63+
64+
// The last one should not generate any more records
65+
// since the current state is empty.
66+
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
3367
}
3468

3569
public function test_store_statistics_on_presence_channel()
3670
{
3771
$rick = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
3872
$morty = $this->newPresenceConnection('presence-channel', ['user_id' => 2]);
73+
$pickleRick = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
3974

4075
$this->statisticsCollector->save();
4176

4277
$this->assertCount(1, $records = $this->statisticsStore->getRecords());
4378

44-
$this->assertEquals('2', $records[0]['peak_connections_count']);
45-
$this->assertEquals('2', $records[0]['websocket_messages_count']);
79+
$this->assertEquals('3', $records[0]['peak_connections_count']);
80+
$this->assertEquals('3', $records[0]['websocket_messages_count']);
4681
$this->assertEquals('0', $records[0]['api_messages_count']);
82+
83+
$this->pusherServer->onClose($rick);
84+
$this->pusherServer->onClose($morty);
85+
$this->pusherServer->onClose($pickleRick);
86+
87+
$this->statisticsCollector->save();
88+
89+
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
90+
91+
$this->assertEquals('3', $records[1]['peak_connections_count']);
92+
$this->assertEquals('0', $records[1]['websocket_messages_count']);
93+
$this->assertEquals('0', $records[1]['api_messages_count']);
94+
95+
$this->statisticsCollector->save();
96+
97+
// The last one should not generate any more records
98+
// since the current state is empty.
99+
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
47100
}
48101
}

0 commit comments

Comments
 (0)