From a340f98b96e0b3c5f19e82962ff4ac581eb0c1a1 Mon Sep 17 00:00:00 2001 From: Rafa de la Torre Date: Wed, 13 Nov 2019 19:19:39 +0100 Subject: [PATCH] Update tests with latency stats --- test/CDB_FederatedServerDiagnostics.sql | 22 +++++++++++++++++++--- test/CDB_FederatedServerDiagnostics_expect | 9 ++++++--- 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/test/CDB_FederatedServerDiagnostics.sql b/test/CDB_FederatedServerDiagnostics.sql index 9e40773..aadb124 100644 --- a/test/CDB_FederatedServerDiagnostics.sql +++ b/test/CDB_FederatedServerDiagnostics.sql @@ -57,9 +57,25 @@ SELECT '1.5', cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback') @> \echo '%% It returns the remote server options' SELECT '1.6', cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback') @> '{"server_options": {"host": "localhost", "port": "@@PGPORT@@", "updatable": "false", "extensions": "postgis", "fetch_size": "1000", "use_remote_estimate": "true"}}'::jsonb; -\echo '%% It returns the network latency to the remote server' -SELECT '2.1', (cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback')->'server_latency_ms')::text::float > 0.0; -SELECT '2.2', (cartodb.CDB_Federated_Server_Diagnostics(server => 'loopback')->'server_latency_ms')::text::float < 1000.0; +\echo '%% It returns network latency stats to the remote server: min <= avg <= max' +WITH latency AS ( + SELECT CDB_Federated_Server_Diagnostics('loopback')->'server_latency_ms' ms +) SELECT '2.1', (latency.ms->'min')::text::float <= (latency.ms->'avg')::text::float, (latency.ms->'avg')::text::float <= (latency.ms->'max')::text::float +FROM latency; + +\echo '%% Latency stats: 0 <= min <= max <= 1000 ms (local connection)' +WITH latency AS ( + SELECT CDB_Federated_Server_Diagnostics('loopback')->'server_latency_ms' ms +) SELECT '2.2', 0.0 <= (latency.ms->'min')::text::float, (latency.ms->'max')::text::float <= 1000.0 +FROM latency; + +\echo '%% Latency stats: stdev > 0' +WITH latency AS ( + SELECT CDB_Federated_Server_Diagnostics('loopback')->'server_latency_ms' ms +) SELECT '2.3', (latency.ms->'stdev')::text::float >= 0.0 +FROM latency; + + \echo '%% It raises an error if the wrong port is provided' SELECT 'C2', cartodb.CDB_Federated_Server_Register_PG(server => 'wrong-port'::text, config => '{ diff --git a/test/CDB_FederatedServerDiagnostics_expect b/test/CDB_FederatedServerDiagnostics_expect index e030def..df01e73 100644 --- a/test/CDB_FederatedServerDiagnostics_expect +++ b/test/CDB_FederatedServerDiagnostics_expect @@ -11,9 +11,12 @@ ERROR: Server "doesNotExist" does not exist 1.5|t %% It returns the remote server options 1.6|t -%% It returns the network latency to the remote server -2.1|t -2.2|t +%% It returns network latency stats to the remote server: min <= avg <= max +2.1|t|t +%% Latency stats: 0 <= min <= max <= 1000 ms (local connection) +2.2|t|t +%% Latency stats: stdev > 0 +2.3|t %% It raises an error if the wrong port is provided C2| ERROR: could not connect to server "cdb_fs_wrong-port"