This repository has been archived by the owner on Feb 7, 2024. It is now read-only.
/
StatisticsStoreTest.php
95 lines (64 loc) · 3.42 KB
/
StatisticsStoreTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<?php
namespace BeyondCode\LaravelWebSockets\Test;
class StatisticsStoreTest extends TestCase
{
public function test_store_statistics_on_public_channel()
{
$rick = $this->newActiveConnection(['public-channel']);
$morty = $this->newActiveConnection(['public-channel']);
$this->statisticsCollector->save();
$this->assertCount(1, $records = $this->statisticsStore->getRecords());
$this->assertEquals('2', $records[0]['peak_connections_count']);
$this->assertEquals('2', $records[0]['websocket_messages_count']);
$this->assertEquals('0', $records[0]['api_messages_count']);
$this->pusherServer->onClose($rick);
$this->pusherServer->onClose($morty);
$this->statisticsCollector->save();
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
$this->assertEquals('2', $records[1]['peak_connections_count']);
$this->statisticsCollector->save();
// The last one should not generate any more records
// since the current state is empty.
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
}
public function test_store_statistics_on_private_channel()
{
$rick = $this->newPrivateConnection('private-channel');
$morty = $this->newPrivateConnection('private-channel');
$this->statisticsCollector->save();
$this->assertCount(1, $records = $this->statisticsStore->getRecords());
$this->assertEquals('2', $records[0]['peak_connections_count']);
$this->assertEquals('2', $records[0]['websocket_messages_count']);
$this->assertEquals('0', $records[0]['api_messages_count']);
$this->pusherServer->onClose($rick);
$this->pusherServer->onClose($morty);
$this->statisticsCollector->save();
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
$this->assertEquals('2', $records[1]['peak_connections_count']);
$this->statisticsCollector->save();
// The last one should not generate any more records
// since the current state is empty.
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
}
public function test_store_statistics_on_presence_channel()
{
$rick = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
$morty = $this->newPresenceConnection('presence-channel', ['user_id' => 2]);
$pickleRick = $this->newPresenceConnection('presence-channel', ['user_id' => 1]);
$this->statisticsCollector->save();
$this->assertCount(1, $records = $this->statisticsStore->getRecords());
$this->assertEquals('3', $records[0]['peak_connections_count']);
$this->assertEquals('3', $records[0]['websocket_messages_count']);
$this->assertEquals('0', $records[0]['api_messages_count']);
$this->pusherServer->onClose($rick);
$this->pusherServer->onClose($morty);
$this->pusherServer->onClose($pickleRick);
$this->statisticsCollector->save();
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
$this->assertEquals('3', $records[1]['peak_connections_count']);
$this->statisticsCollector->save();
// The last one should not generate any more records
// since the current state is empty.
$this->assertCount(2, $records = $this->statisticsStore->getRecords());
}
}