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

Commit 53a6d0f

Browse files
committed
Added tests
1 parent 223a789 commit 53a6d0f

File tree

4 files changed

+140
-132
lines changed

4 files changed

+140
-132
lines changed

tests/PresenceChannelTest.php

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -318,58 +318,6 @@ public function test_multiple_clients_with_same_user_id_trigger_member_added_and
318318
});
319319
}
320320

321-
public function test_not_ponged_connections_do_get_removed_for_presence_channels()
322-
{
323-
$this->runOnlyOnRedisReplication();
324-
325-
$activeConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
326-
$obsoleteConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 2]);
327-
328-
// The active connection just pinged, it should not be closed.
329-
$this->channelManager->addConnectionToSet($activeConnection, Carbon::now());
330-
331-
// Make the connection look like it was lost 1 day ago.
332-
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
333-
334-
$this->channelManager
335-
->getGlobalConnectionsCount('1234', 'presence-channel')
336-
->then(function ($count) {
337-
$this->assertEquals(2, $count);
338-
});
339-
340-
$this->channelManager
341-
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
342-
->then(function ($expiredConnections) {
343-
$this->assertCount(1, $expiredConnections);
344-
});
345-
346-
$this->channelManager
347-
->getChannelMembers('1234', 'presence-channel')
348-
->then(function ($members) {
349-
$this->assertCount(2, $members);
350-
});
351-
352-
$this->channelManager->removeObsoleteConnections();
353-
354-
$this->channelManager
355-
->getGlobalConnectionsCount('1234', 'presence-channel')
356-
->then(function ($count) {
357-
$this->assertEquals(1, $count);
358-
});
359-
360-
$this->channelManager
361-
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
362-
->then(function ($expiredConnections) {
363-
$this->assertCount(0, $expiredConnections);
364-
});
365-
366-
$this->channelManager
367-
->getChannelMembers('1234', 'presence-channel')
368-
->then(function ($members) {
369-
$this->assertCount(1, $members);
370-
});
371-
}
372-
373321
public function test_events_are_processed_by_on_message_on_presence_channels()
374322
{
375323
$this->runOnlyOnRedisReplication();

tests/PrivateChannelTest.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -159,46 +159,6 @@ public function test_local_connections_for_private_channels()
159159
});
160160
}
161161

162-
public function test_not_ponged_connections_do_get_removed_for_private_channels()
163-
{
164-
$this->runOnlyOnRedisReplication();
165-
166-
$activeConnection = $this->newPrivateConnection('private-channel');
167-
$obsoleteConnection = $this->newPrivateConnection('private-channel');
168-
169-
// The active connection just pinged, it should not be closed.
170-
$this->channelManager->addConnectionToSet($activeConnection, Carbon::now());
171-
172-
// Make the connection look like it was lost 1 day ago.
173-
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
174-
175-
$this->channelManager
176-
->getGlobalConnectionsCount('1234', 'private-channel')
177-
->then(function ($count) {
178-
$this->assertEquals(2, $count);
179-
});
180-
181-
$this->channelManager
182-
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
183-
->then(function ($expiredConnections) {
184-
$this->assertCount(1, $expiredConnections);
185-
});
186-
187-
$this->channelManager->removeObsoleteConnections();
188-
189-
$this->channelManager
190-
->getGlobalConnectionsCount('1234', 'private-channel')
191-
->then(function ($count) {
192-
$this->assertEquals(1, $count);
193-
});
194-
195-
$this->channelManager
196-
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
197-
->then(function ($expiredConnections) {
198-
$this->assertCount(0, $expiredConnections);
199-
});
200-
}
201-
202162
public function test_events_are_processed_by_on_message_on_private_channels()
203163
{
204164
$this->runOnlyOnRedisReplication();

tests/PublicChannelTest.php

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -140,46 +140,6 @@ public function test_local_connections_for_public_channels()
140140
});
141141
}
142142

143-
public function test_not_ponged_connections_do_get_removed_for_public_channels()
144-
{
145-
$this->runOnlyOnRedisReplication();
146-
147-
$activeConnection = $this->newActiveConnection(['public-channel']);
148-
$obsoleteConnection = $this->newActiveConnection(['public-channel']);
149-
150-
// The active connection just pinged, it should not be closed.
151-
$this->channelManager->addConnectionToSet($activeConnection, Carbon::now());
152-
153-
// Make the connection look like it was lost 1 day ago.
154-
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
155-
156-
$this->channelManager
157-
->getGlobalConnectionsCount('1234', 'public-channel')
158-
->then(function ($count) {
159-
$this->assertEquals(2, $count);
160-
});
161-
162-
$this->channelManager
163-
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
164-
->then(function ($expiredConnections) {
165-
$this->assertCount(1, $expiredConnections);
166-
});
167-
168-
$this->channelManager->removeObsoleteConnections();
169-
170-
$this->channelManager
171-
->getGlobalConnectionsCount('1234', 'public-channel')
172-
->then(function ($count) {
173-
$this->assertEquals(1, $count);
174-
});
175-
176-
$this->channelManager
177-
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
178-
->then(function ($expiredConnections) {
179-
$this->assertCount(0, $expiredConnections);
180-
});
181-
}
182-
183143
public function test_events_are_processed_by_on_message_on_public_channels()
184144
{
185145
$this->runOnlyOnRedisReplication();

tests/RedisPongRemovalTest.php

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Test;
4+
5+
use Carbon\Carbon;
6+
7+
class RedisPongRemovalTest extends TestCase
8+
{
9+
public function test_not_ponged_connections_do_get_removed_on_redis_for_public_channels()
10+
{
11+
$this->runOnlyOnRedisReplication();
12+
13+
$activeConnection = $this->newActiveConnection(['public-channel']);
14+
$obsoleteConnection = $this->newActiveConnection(['public-channel']);
15+
16+
// The active connection just pinged, it should not be closed.
17+
$this->channelManager->addConnectionToSet($activeConnection, Carbon::now());
18+
19+
// Make the connection look like it was lost 1 day ago.
20+
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
21+
22+
$this->channelManager
23+
->getGlobalConnectionsCount('1234', 'public-channel')
24+
->then(function ($count) {
25+
$this->assertEquals(2, $count);
26+
});
27+
28+
$this->channelManager
29+
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
30+
->then(function ($expiredConnections) {
31+
$this->assertCount(1, $expiredConnections);
32+
});
33+
34+
$this->channelManager->removeObsoleteConnections();
35+
36+
$this->channelManager
37+
->getGlobalConnectionsCount('1234', 'public-channel')
38+
->then(function ($count) {
39+
$this->assertEquals(1, $count);
40+
});
41+
42+
$this->channelManager
43+
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
44+
->then(function ($expiredConnections) {
45+
$this->assertCount(0, $expiredConnections);
46+
});
47+
}
48+
49+
public function test_not_ponged_connections_do_get_removed_on_redis_for_private_channels()
50+
{
51+
$this->runOnlyOnRedisReplication();
52+
53+
$activeConnection = $this->newPrivateConnection('private-channel');
54+
$obsoleteConnection = $this->newPrivateConnection('private-channel');
55+
56+
// The active connection just pinged, it should not be closed.
57+
$this->channelManager->addConnectionToSet($activeConnection, Carbon::now());
58+
59+
// Make the connection look like it was lost 1 day ago.
60+
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
61+
62+
$this->channelManager
63+
->getGlobalConnectionsCount('1234', 'private-channel')
64+
->then(function ($count) {
65+
$this->assertEquals(2, $count);
66+
});
67+
68+
$this->channelManager
69+
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
70+
->then(function ($expiredConnections) {
71+
$this->assertCount(1, $expiredConnections);
72+
});
73+
74+
$this->channelManager->removeObsoleteConnections();
75+
76+
$this->channelManager
77+
->getGlobalConnectionsCount('1234', 'private-channel')
78+
->then(function ($count) {
79+
$this->assertEquals(1, $count);
80+
});
81+
82+
$this->channelManager
83+
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
84+
->then(function ($expiredConnections) {
85+
$this->assertCount(0, $expiredConnections);
86+
});
87+
}
88+
89+
public function test_not_ponged_connections_do_get_removed_on_redis_for_presence_channels()
90+
{
91+
$this->runOnlyOnRedisReplication();
92+
93+
$activeConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
94+
$obsoleteConnection = $this->newPresenceConnection('presence-channel', ['user_id' => 2]);
95+
96+
// The active connection just pinged, it should not be closed.
97+
$this->channelManager->addConnectionToSet($activeConnection, Carbon::now());
98+
99+
// Make the connection look like it was lost 1 day ago.
100+
$this->channelManager->addConnectionToSet($obsoleteConnection, Carbon::now()->subDays(1));
101+
102+
$this->channelManager
103+
->getGlobalConnectionsCount('1234', 'presence-channel')
104+
->then(function ($count) {
105+
$this->assertEquals(2, $count);
106+
});
107+
108+
$this->channelManager
109+
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
110+
->then(function ($expiredConnections) {
111+
$this->assertCount(1, $expiredConnections);
112+
});
113+
114+
$this->channelManager
115+
->getChannelMembers('1234', 'presence-channel')
116+
->then(function ($members) {
117+
$this->assertCount(2, $members);
118+
});
119+
120+
$this->channelManager->removeObsoleteConnections();
121+
122+
$this->channelManager
123+
->getGlobalConnectionsCount('1234', 'presence-channel')
124+
->then(function ($count) {
125+
$this->assertEquals(1, $count);
126+
});
127+
128+
$this->channelManager
129+
->getConnectionsFromSet(0, Carbon::now()->subMinutes(2)->format('U'))
130+
->then(function ($expiredConnections) {
131+
$this->assertCount(0, $expiredConnections);
132+
});
133+
134+
$this->channelManager
135+
->getChannelMembers('1234', 'presence-channel')
136+
->then(function ($members) {
137+
$this->assertCount(1, $members);
138+
});
139+
}
140+
}

0 commit comments

Comments
 (0)