|
3 | 3 | namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Controllers;
|
4 | 4 |
|
5 | 5 | use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
|
| 6 | +use BeyondCode\LaravelWebSockets\Statistics\Logger\MemoryStatisticsLogger; |
| 7 | +use BeyondCode\LaravelWebSockets\Statistics\Logger\NullStatisticsLogger; |
| 8 | +use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry; |
6 | 9 | use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
7 | 10 |
|
8 | 11 | class StatisticsLoggerTest extends TestCase
|
@@ -43,4 +46,50 @@ public function it_counts_unique_connections_no_channel_subscriptions()
|
43 | 46 |
|
44 | 47 | $this->assertEquals(1, StatisticsLogger::getForAppId(1234)['peak_connection_count']);
|
45 | 48 | }
|
| 49 | + |
| 50 | + /** @test */ |
| 51 | + public function it_counts_connections_with_memory_logger() |
| 52 | + { |
| 53 | + $connection = $this->getConnectedWebSocketConnection(['channel-1']); |
| 54 | + |
| 55 | + $logger = new MemoryStatisticsLogger( |
| 56 | + $this->channelManager, |
| 57 | + $this->statisticsDriver |
| 58 | + ); |
| 59 | + |
| 60 | + $logger->webSocketMessage($connection->app->id); |
| 61 | + $logger->apiMessage($connection->app->id); |
| 62 | + $logger->connection($connection->app->id); |
| 63 | + $logger->disconnection($connection->app->id); |
| 64 | + |
| 65 | + $logger->save(); |
| 66 | + |
| 67 | + $this->assertCount(1, WebSocketsStatisticsEntry::all()); |
| 68 | + |
| 69 | + $entry = WebSocketsStatisticsEntry::first(); |
| 70 | + |
| 71 | + $this->assertEquals(1, $entry->peak_connection_count); |
| 72 | + $this->assertEquals(1, $entry->websocket_message_count); |
| 73 | + $this->assertEquals(1, $entry->api_message_count); |
| 74 | + } |
| 75 | + |
| 76 | + /** @test */ |
| 77 | + public function it_counts_connections_with_null_logger() |
| 78 | + { |
| 79 | + $connection = $this->getConnectedWebSocketConnection(['channel-1']); |
| 80 | + |
| 81 | + $logger = new NullStatisticsLogger( |
| 82 | + $this->channelManager, |
| 83 | + $this->statisticsDriver |
| 84 | + ); |
| 85 | + |
| 86 | + $logger->webSocketMessage($connection->app->id); |
| 87 | + $logger->apiMessage($connection->app->id); |
| 88 | + $logger->connection($connection->app->id); |
| 89 | + $logger->disconnection($connection->app->id); |
| 90 | + |
| 91 | + $logger->save(); |
| 92 | + |
| 93 | + $this->assertCount(0, WebSocketsStatisticsEntry::all()); |
| 94 | + } |
46 | 95 | }
|
0 commit comments