Update tests, add more invalid metrics to be ignored, add sql metrics count check

This commit is contained in:
xbgmsharp
2023-12-31 21:13:40 +01:00
parent db3bd6b06f
commit c46a428fc2
5 changed files with 67 additions and 5 deletions

View File

@@ -604,8 +604,12 @@ request.set('User-Agent', 'PostgSail unit tests');
// Override client_id // Override client_id
data[i]['client_id'] = test.vessel_metadata.client_id; data[i]['client_id'] = test.vessel_metadata.client_id;
} }
// Force last entry to be back in time from previous, it should be ignore silently // The last entry are invalid and should be ignore.
data.at(-1).time = moment.utc(data.at(-2).time).subtract(1, 'minutes').format(); // - Invalid status
// - Invalid speedoverground
// - Invalid time previous time is duplicate
// Force last valid entry to be back in time from previous, it should be ignore silently
data.at(-1).time = moment.utc(data.at(-3).time).subtract(1, 'minutes').format();
//console.log(data[0]); //console.log(data[0]);
it('/metrics?select=time', function(done) { it('/metrics?select=time', function(done) {
@@ -625,7 +629,7 @@ request.set('User-Agent', 'PostgSail unit tests');
res.header['content-type'].should.match(new RegExp('json','g')); res.header['content-type'].should.match(new RegExp('json','g'));
res.header['server'].should.match(new RegExp('postgrest','g')); res.header['server'].should.match(new RegExp('postgrest','g'));
should.exist(res.body); should.exist(res.body);
res.body.length.should.match(test.vessel_metrics['metrics'].length-1); res.body.length.should.match(test.vessel_metrics['metrics'].length-3);
done(err); done(err);
}); });
}); });

View File

@@ -573,7 +573,31 @@
"courseovergroundtrue" : 197.6, "courseovergroundtrue" : 197.6,
"windspeedapparent" : 15.9, "windspeedapparent" : 15.9,
"anglespeedapparent" : 31.0, "anglespeedapparent" : 31.0,
"status" : "ais-sart",
"metrics" : {}
},
{
"time" : "2022-07-31T12:14:29.168Z",
"client_id" : "vessels.urn:mrn:imo:mmsi:987654321",
"latitude" : 59.7124174,
"longitude" : 24.7289112,
"speedoverground" : 55.7,
"courseovergroundtrue" : 197.6,
"windspeedapparent" : 15.9,
"anglespeedapparent" : 31.0,
"status" : "anchored", "status" : "anchored",
"metrics" : {"navigation.log": 17442506, "navigation.trip.log": 81321, "navigation.headingTrue": 3.571, "navigation.gnss.satellites": 10, "environment.depth.belowKeel": 13.749, "navigation.magneticVariation": 0.1414, "navigation.speedThroughWater": 3.07, "environment.water.temperature": 313.15, "electrical.batteries.1.current": 43.9, "electrical.batteries.1.voltage": 14.54, "navigation.gnss.antennaAltitude": 2.05, "network.n2k.ngt-1.130356.errorID": 0, "network.n2k.ngt-1.130356.modelID": 14, "environment.depth.belowTransducer": 13.75, "electrical.batteries.1.temperature": 299.82, "environment.depth.transducerToKeel": -0.001, "navigation.gnss.horizontalDilution": 0.8, "network.n2k.ngt-1.130356.ch1.rxLoad": 4, "network.n2k.ngt-1.130356.ch1.txLoad": 0, "network.n2k.ngt-1.130356.ch2.rxLoad": 0, "network.n2k.ngt-1.130356.ch2.txLoad": 40, "network.n2k.ngt-1.130356.ch1.deleted": 0, "network.n2k.ngt-1.130356.ch2.deleted": 0, "network.n2k.ngt-1.130356.ch2Bandwidth": 4, "network.n2k.ngt-1.130356.ch1.bandwidth": 3, "network.n2k.ngt-1.130356.ch1.rxDropped": 0, "network.n2k.ngt-1.130356.ch2.rxDropped": 0, "network.n2k.ngt-1.130356.ch1.rxFiltered": 0, "network.n2k.ngt-1.130356.ch2.rxFiltered": 0, "network.n2k.ngt-1.130356.ch1.rxBandwidth": 5, "network.n2k.ngt-1.130356.ch1.txBandwidth": 0, "network.n2k.ngt-1.130356.ch2.rxBandwidth": 0, "network.n2k.ngt-1.130356.ch2.txBandwidth": 10, "network.n2k.ngt-1.130356.uniChannelCount": 2, "network.n2k.ngt-1.130356.indiChannelCount": 2, "network.n2k.ngt-1.130356.ch1.BufferLoading": 0, "network.n2k.ngt-1.130356.ch2.bufferLoading": 0, "network.n2k.ngt-1.130356.ch1.PointerLoading": 0, "network.n2k.ngt-1.130356.ch2.pointerLoading": 0} "metrics" : {}
},
{
"time" : "2022-07-31T12:14:29.168Z",
"client_id" : "vessels.urn:mrn:imo:mmsi:987654321",
"latitude" : 59.7124174,
"longitude" : 24.7289112,
"speedoverground" : 5.7,
"courseovergroundtrue" : 197.6,
"windspeedapparent" : 15.9,
"anglespeedapparent" : 31.0,
"status" : "anchored",
"metrics" : {}
} }
]} ]}

View File

@@ -633,7 +633,31 @@
"courseovergroundtrue" : 122.0, "courseovergroundtrue" : 122.0,
"windspeedapparent" : 7.2, "windspeedapparent" : 7.2,
"anglespeedapparent" : 10.0, "anglespeedapparent" : 10.0,
"status" : "unknown",
"metrics" : {}
},
{
"time" : "2022-07-30T15:41:28.867Z",
"client_id" : "vessels.urn:mrn:imo:mmsi:123456789",
"latitude" : 59.86,
"longitude" : 23.365766666666666,
"speedoverground" : 60.0,
"courseovergroundtrue" : 122.0,
"windspeedapparent" : 7.2,
"anglespeedapparent" : 10.0,
"status" : "anchored", "status" : "anchored",
"metrics" : {"environment.wind.speedTrue": 0.63, "navigation.speedThroughWater": 3.2255674838104293, "performance.velocityMadeGood": -2.242978345998959, "environment.wind.angleTrueWater": 2.3038346131585485, "environment.depth.belowTransducer": 17.73, "navigation.courseOverGroundMagnetic": 2.129127154994025, "navigation.courseRhumbline.crossTrackError": 0} "metrics" : {}
},
{
"time" : "2022-07-30T15:41:28.867Z",
"client_id" : "vessels.urn:mrn:imo:mmsi:123456789",
"latitude" : 59.86,
"longitude" : 23.365766666666666,
"speedoverground" : 0.0,
"courseovergroundtrue" : 122.0,
"windspeedapparent" : 7.2,
"anglespeedapparent" : 10.0,
"status" : "anchored",
"metrics" : {}
} }
]} ]}

View File

@@ -12,9 +12,14 @@ select current_database();
\x on \x on
-- Check the number of process pending -- Check the number of process pending
\echo 'Check the number of process pending'
-- Should be 22 -- Should be 22
SELECT count(*) as jobs from public.process_queue pq where pq.processed is null; SELECT count(*) as jobs from public.process_queue pq where pq.processed is null;
--set role scheduler --set role scheduler
SELECT public.run_cron_jobs(); SELECT public.run_cron_jobs();
-- Check any pending job -- Check any pending job
SELECT count(*) as any_pending_jobs from public.process_queue pq where pq.processed is null; SELECT count(*) as any_pending_jobs from public.process_queue pq where pq.processed is null;
-- Check the number of metrics entries
\echo 'Check the number of metrics entries'
SELECT count(*) as metrics_count from api.metrics;

View File

@@ -5,6 +5,7 @@
You are now connected to database "signalk" as user "username". You are now connected to database "signalk" as user "username".
Expanded display is on. Expanded display is on.
Check the number of process pending
-[ RECORD 1 ] -[ RECORD 1 ]
jobs | 26 jobs | 26
@@ -14,3 +15,7 @@ run_cron_jobs |
-[ RECORD 1 ]----+-- -[ RECORD 1 ]----+--
any_pending_jobs | 2 any_pending_jobs | 2
Check the number of metrics entries
-[ RECORD 1 ]-+----
metrics_count | 172