MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / test_hour

Function test_hour

chirpstack/src/storage/metrics.rs:352–416  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

350
351 #[tokio::test]
352 async fn test_hour() {
353 let _guard = test::prepare().await;
354
355 let records = vec![
356 Record {
357 time: Local.with_ymd_and_hms(2018, 1, 1, 1, 1, 0).unwrap(),
358 kind: Kind::ABSOLUTE,
359 metrics: [("foo".into(), 1f64), ("bar".into(), 2f64)]
360 .iter()
361 .cloned()
362 .collect(),
363 },
364 Record {
365 time: Local.with_ymd_and_hms(2018, 1, 1, 1, 2, 0).unwrap(),
366 kind: Kind::ABSOLUTE,
367 metrics: [("foo".into(), 3f64), ("bar".into(), 4f64)]
368 .iter()
369 .cloned()
370 .collect(),
371 },
372 Record {
373 time: Local.with_ymd_and_hms(2018, 1, 1, 2, 1, 0).unwrap(),
374 kind: Kind::ABSOLUTE,
375 metrics: [("foo".into(), 5f64), ("bar".into(), 6f64)]
376 .iter()
377 .cloned()
378 .collect(),
379 },
380 ];
381 for r in &records {
382 save("test", r, &[Aggregation::HOUR]).await.unwrap();
383 }
384
385 let resp = get(
386 "test",
387 Kind::ABSOLUTE,
388 Aggregation::HOUR,
389 Local.with_ymd_and_hms(2018, 1, 1, 1, 0, 0).unwrap(),
390 Local.with_ymd_and_hms(2018, 1, 1, 2, 0, 0).unwrap(),
391 )
392 .await
393 .unwrap();
394
395 assert_eq!(
396 vec![
397 Record {
398 time: Local.with_ymd_and_hms(2018, 1, 1, 1, 0, 0).unwrap(),
399 kind: Kind::ABSOLUTE,
400 metrics: [("foo".into(), 4f64), ("bar".into(), 6f64)]
401 .iter()
402 .cloned()
403 .collect(),
404 },
405 Record {
406 time: Local.with_ymd_and_hms(2018, 1, 1, 2, 0, 0).unwrap(),
407 kind: Kind::ABSOLUTE,
408 metrics: [("foo".into(), 5f64), ("bar".into(), 6f64)]
409 .iter()

Callers

nothing calls this directly

Calls 4

prepareFunction · 0.85
unwrapMethod · 0.80
saveFunction · 0.70
getFunction · 0.70

Tested by

no test coverage detected