@@ -7,25 +7,31 @@ def test_per_sensor_rate_hz_controls_sampling_frequency():
77 devices_cfg = [{
88 "id" : "A" ,
99 "sensors" : [
10- {"kind" : "temp" , "count" : 1 , "priority" : 5 , "rate_hz" : 5 }, # every 0.2s
11- {"kind" : "vibration" , "count" : 1 , "priority" : 5 , "rate_hz" : 10 }, # every 0.1s
10+ {"kind" : "temp" , "count" : 1 , "priority" : 5 , "rate_hz" : 5 }, # ~ every 0.2s
11+ {"kind" : "vibration" , "count" : 1 , "priority" : 5 , "rate_hz" : 10 }, # ~ every 0.1s
1212 ]
1313 }]
1414
1515 run_stream (
1616 spec_str = "device=A: temp*1,vibration*1" ,
17- rate_hz = 10.0 , # global tick
17+ rate_hz = 10.0 , # global tick
1818 duration_s = None ,
19- total_count = 20 , # ~2.0s
19+ total_count = 20 , # ~2.0s
2020 writer_for_type = {"*" : cap .router ({"*" : cap .writer_for_type ("*" )})},
2121 partition_by = "none" ,
2222 devices_cfg = devices_cfg ,
2323 )
2424
25- n_temp = len ([r for r in cap .per_type ["*" ] if r ["type" ] == "temp" ]) \
26- if "*" in cap .per_type else len ([r for r in cap .per_type .get ("temp" , [])])
27- n_vib = len ([r for r in cap .per_type ["*" ] if r ["type" ] == "vibration" ]) \
28- if "*" in cap .per_type else len ([r for r in cap .per_type .get ("vibration" , [])])
25+ # Count how many samples we collected for each type
26+ all_recs = cap .per_type .get ("*" )
27+ if all_recs is not None :
28+ n_temp = sum (1 for r in all_recs if r ["type" ] == "temp" )
29+ n_vib = sum (1 for r in all_recs if r ["type" ] == "vibration" )
30+ else :
31+ n_temp = len (cap .per_type .get ("temp" , []))
32+ n_vib = len (cap .per_type .get ("vibration" , []))
2933
30- # vibration should have noticeably more samples than temp (timing tolerance)
31- assert n_vib >= n_temp + 5 , f"expected more vib samples than temp; got temp={ n_temp } , vib={ n_vib } "
34+ # Expect significantly more vibration samples (10 Hz) than temperature (5 Hz).
35+ # Leave tolerance for CI timing jitter: require at least 1.5× more vib or +3 samples.
36+ assert n_vib >= max (int (1.5 * n_temp ), n_temp + 3 ), \
37+ f"expected clearly more vib samples than temp; got temp={ n_temp } , vib={ n_vib } "
0 commit comments