@@ -16,6 +16,23 @@ public function test_store_statistics_on_public_channel()
16
16
$ this ->assertEquals ('2 ' , $ records [0 ]['peak_connections_count ' ]);
17
17
$ this ->assertEquals ('2 ' , $ records [0 ]['websocket_messages_count ' ]);
18
18
$ 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 ());
19
36
}
20
37
21
38
public function test_store_statistics_on_private_channel ()
@@ -30,19 +47,55 @@ public function test_store_statistics_on_private_channel()
30
47
$ this ->assertEquals ('2 ' , $ records [0 ]['peak_connections_count ' ]);
31
48
$ this ->assertEquals ('2 ' , $ records [0 ]['websocket_messages_count ' ]);
32
49
$ 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 ());
33
67
}
34
68
35
69
public function test_store_statistics_on_presence_channel ()
36
70
{
37
71
$ rick = $ this ->newPresenceConnection ('presence-channel ' , ['user_id ' => 1 ]);
38
72
$ morty = $ this ->newPresenceConnection ('presence-channel ' , ['user_id ' => 2 ]);
73
+ $ pickleRick = $ this ->newPresenceConnection ('presence-channel ' , ['user_id ' => 1 ]);
39
74
40
75
$ this ->statisticsCollector ->save ();
41
76
42
77
$ this ->assertCount (1 , $ records = $ this ->statisticsStore ->getRecords ());
43
78
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 ' ]);
46
81
$ 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 ());
47
100
}
48
101
}
0 commit comments