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

Function test_gateway_stats

chirpstack/src/api/gateway.rs:1148–1242  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1146
1147 #[tokio::test]
1148 async fn test_gateway_stats() {
1149 let _guard = test::prepare().await;
1150
1151 // setup admin user
1152 let u = user::User {
1153 is_admin: true,
1154 is_active: true,
1155 email: "admin@admin".into(),
1156 email_verified: true,
1157 ..Default::default()
1158 };
1159 let u = user::create(u).await.unwrap();
1160
1161 // create tenant
1162 let t = tenant::create(tenant::Tenant {
1163 name: "test-tenant".into(),
1164 can_have_gateways: true,
1165 max_gateway_count: 10,
1166 ..Default::default()
1167 })
1168 .await
1169 .unwrap();
1170
1171 // create gateway
1172 let _ = gateway::create(gateway::Gateway {
1173 gateway_id: EUI64::from_be_bytes([1, 2, 3, 4, 5, 6, 7, 8]),
1174 tenant_id: t.id,
1175 name: "test-gw".into(),
1176 ..Default::default()
1177 })
1178 .await
1179 .unwrap();
1180
1181 let now = Local::now();
1182
1183 // insert stats
1184 let mut m = metrics::Record {
1185 kind: metrics::Kind::ABSOLUTE,
1186 time: now,
1187 metrics: HashMap::new(),
1188 };
1189
1190 m.metrics.insert("rx_count".into(), 10.0);
1191 m.metrics.insert("rx_freq_868100000".into(), 10.0);
1192 m.metrics.insert("rx_dr_5".into(), 10.0);
1193
1194 m.metrics.insert("tx_count".into(), 5.0);
1195 m.metrics.insert("tx_freq_868200000".into(), 5.0);
1196 m.metrics.insert("tx_dr_4".into(), 5.0);
1197
1198 metrics::save(
1199 "gw:0102030405060708",
1200 &m,
1201 &metrics::Aggregation::default_aggregations(),
1202 )
1203 .await
1204 .unwrap();
1205

Callers

nothing calls this directly

Calls 8

prepareFunction · 0.85
unwrapMethod · 0.80
insertMethod · 0.80
UserClass · 0.70
createFunction · 0.50
saveFunction · 0.50
intoMethod · 0.45
get_metricsMethod · 0.45

Tested by

no test coverage detected