Fixed tests for stats metrics
This commit is contained in:
parent
1c889beff9
commit
5ba24cb80c
|
|
@ -165,6 +165,17 @@ class RedisStatisticsLogger implements StatisticsLogger
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Statistics come into a list where the keys are on even indexes
|
||||||
|
// and the values are on odd indexes. This way, we know which
|
||||||
|
// ones are keys and which ones are values and their get combined
|
||||||
|
// later to form the key => value array
|
||||||
|
|
||||||
|
[$keys, $values] = collect($statistic)->partition(function ($value, $key) {
|
||||||
|
return $key % 2 === 0;
|
||||||
|
});
|
||||||
|
|
||||||
|
$statistic = array_combine($keys->all(), $values->all());
|
||||||
|
|
||||||
$this->createRecord($statistic, $appId);
|
$this->createRecord($statistic, $appId);
|
||||||
|
|
||||||
$this->channelManager
|
$this->channelManager
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ namespace BeyondCode\LaravelWebSockets\Tests\Statistics\Controllers;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
|
use BeyondCode\LaravelWebSockets\Facades\StatisticsLogger;
|
||||||
use BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger;
|
use BeyondCode\LaravelWebSockets\Statistics\Logger\RedisStatisticsLogger;
|
||||||
|
use BeyondCode\LaravelWebSockets\Statistics\Models\WebSocketsStatisticsEntry;
|
||||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||||
|
|
||||||
class RedisStatisticsLoggerTest extends TestCase
|
class RedisStatisticsLoggerTest extends TestCase
|
||||||
|
|
@ -76,50 +77,26 @@ class RedisStatisticsLoggerTest extends TestCase
|
||||||
{
|
{
|
||||||
config(['cache.default' => 'redis']);
|
config(['cache.default' => 'redis']);
|
||||||
|
|
||||||
$connection = $this->getConnectedWebSocketConnection(['channel-1']);
|
|
||||||
|
|
||||||
$logger = new RedisStatisticsLogger(
|
$logger = new RedisStatisticsLogger(
|
||||||
$this->channelManager,
|
$this->channelManager,
|
||||||
$this->statisticsDriver
|
$this->statisticsDriver
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$logger->resetAppTraces('1');
|
||||||
$logger->resetAppTraces('1234');
|
$logger->resetAppTraces('1234');
|
||||||
|
|
||||||
$logger->webSocketMessage($connection->app->id);
|
|
||||||
$logger->apiMessage($connection->app->id);
|
|
||||||
$logger->connection($connection->app->id);
|
|
||||||
$logger->disconnection($connection->app->id);
|
|
||||||
|
|
||||||
$logger->save();
|
|
||||||
|
|
||||||
$this->markTestIncomplete(
|
|
||||||
'The numbers does not seem to match well.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @test */
|
|
||||||
public function it_counts_connections_with_redis_logger_with_existing_data()
|
|
||||||
{
|
|
||||||
config(['cache.default' => 'redis']);
|
|
||||||
|
|
||||||
$connection = $this->getConnectedWebSocketConnection(['channel-1']);
|
$connection = $this->getConnectedWebSocketConnection(['channel-1']);
|
||||||
|
|
||||||
$logger = new RedisStatisticsLogger(
|
|
||||||
$this->channelManager,
|
|
||||||
$this->statisticsDriver
|
|
||||||
);
|
|
||||||
|
|
||||||
$logger->resetStatistics('1234', 0);
|
|
||||||
|
|
||||||
$logger->webSocketMessage($connection->app->id);
|
|
||||||
$logger->apiMessage($connection->app->id);
|
$logger->apiMessage($connection->app->id);
|
||||||
$logger->connection($connection->app->id);
|
|
||||||
$logger->disconnection($connection->app->id);
|
|
||||||
|
|
||||||
$logger->save();
|
$logger->save();
|
||||||
|
|
||||||
$this->markTestIncomplete(
|
$this->assertCount(1, WebSocketsStatisticsEntry::all());
|
||||||
'The numbers does not seem to match well.'
|
|
||||||
);
|
$entry = WebSocketsStatisticsEntry::first();
|
||||||
|
|
||||||
|
$this->assertEquals(1, $entry->peak_connection_count);
|
||||||
|
$this->assertEquals(1, $entry->websocket_message_count);
|
||||||
|
$this->assertEquals(1, $entry->api_message_count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue