Browse Source

Adding additional test for latency

tags/0.3.8-rc
haixuanTao 1 year ago
parent
commit
1aeaa1b5ff
4 changed files with 19 additions and 7 deletions
  1. +1
    -1
      tests/queue_size_latest_data_python/dataflow.yaml
  2. +5
    -0
      tests/queue_size_latest_data_python/send_data.py
  3. +1
    -1
      tests/queue_size_latest_data_rust/dataflow.yaml
  4. +12
    -5
      tests/queue_size_latest_data_rust/receive_data/src/main.rs

+ 1
- 1
tests/queue_size_latest_data_python/dataflow.yaml View File

@@ -2,7 +2,7 @@ nodes:
- id: send_data
path: ./send_data.py
inputs:
tick: dora/timer/millis/20
tick: dora/timer/millis/10
outputs:
- data



+ 5
- 0
tests/queue_size_latest_data_python/send_data.py View File

@@ -5,6 +5,11 @@ import numpy as np

node = Node()

i = 0
for event in node:
if i == 1000:
break
else:
i += 1
now = time.clock_gettime_ns(0)
node.send_output("data", pa.array([np.uint64(now)]))

+ 1
- 1
tests/queue_size_latest_data_rust/dataflow.yaml View File

@@ -2,7 +2,7 @@ nodes:
- id: send_data
path: ../queue_size_latest_data_python/send_data.py
inputs:
tick: dora/timer/millis/1
tick: dora/timer/millis/10
outputs:
- data



+ 12
- 5
tests/queue_size_latest_data_rust/receive_data/src/main.rs View File

@@ -20,20 +20,27 @@ fn main() -> eyre::Result<()> {
match event {
dora_node_api::Event::Input {
id: _,
metadata: _,
metadata,
data,
} => {
let data: &PrimitiveArray<UInt64Type> = data.as_primitive();
let time: u64 = data.values()[0];
let time_metadata = metadata.timestamp();
let duration_metadata = time_metadata.get_time().to_system_time().elapsed()?;
println!("Latency duration: {:?}", duration_metadata);
assert!(
duration_metadata < Duration::from_millis(500),
"Time difference should be less than 500ms"
);
let time = time as f64;
let now = Utc::now();

let timestamp = now.timestamp_nanos_opt().unwrap() as f64;
let duration = (timestamp - time) / 1_000_000_000.;
println!("Time Difference: {:?}", duration);
let duration = Duration::from_nanos((timestamp - time) as u64);
println!("Latency duration: {:?}", duration);
assert!(
duration < 1.,
"Time difference should be less than 2 seconds as data is sent every seconds"
duration < Duration::from_millis(500),
"Time difference should be less than 500ms"
);
}
_ => {}


Loading…
Cancel
Save