Browse Source

Fix scheduler not being used when called through node timeout

tags/v0.3.10-rc0
haixuantao 11 months ago
parent
commit
f33ee1e811
4 changed files with 16 additions and 15 deletions
  1. +6
    -5
      apis/rust/node/src/event_stream/mod.rs
  2. +1
    -3
      tests/queue_size_and_timeout_python/dataflow.yaml
  3. +6
    -6
      tests/queue_size_and_timeout_python/receive_data.py
  4. +3
    -1
      tests/queue_size_and_timeout_python/send_data.py

+ 6
- 5
apis/rust/node/src/event_stream/mod.rs View File

@@ -1,5 +1,6 @@
use std::{
collections::{BTreeMap, HashMap, VecDeque},
pin::pin,
sync::Arc,
time::Duration,
};
@@ -187,13 +188,13 @@ impl EventStream {
}

pub async fn recv_async_timeout(&mut self, dur: Duration) -> Option<Event> {
let next_event = match select(Delay::new(dur), self.receiver.next()).await {
Either::Left((_elapsed, _)) => {
Some(EventItem::TimeoutError(eyre!("Receiver timed out")))
}
let next_event = match select(Delay::new(dur), pin!(self.recv_async())).await {
Either::Left((_elapsed, _)) => Some(Self::convert_event_item(EventItem::TimeoutError(
eyre!("Receiver timed out"),
))),
Either::Right((event, _)) => event,
};
next_event.map(Self::convert_event_item)
next_event
}

fn convert_event_item(item: EventItem) -> Event {


+ 1
- 3
tests/queue_size_and_timeout_python/dataflow.yaml View File

@@ -9,6 +9,4 @@ nodes:
- id: receive_data_with_sleep
path: ./receive_data.py
inputs:
ts:
source: send_data/ts
queue_size: 1
ts: send_data/ts

+ 6
- 6
tests/queue_size_and_timeout_python/receive_data.py View File

@@ -8,23 +8,23 @@ def main() -> None:

i = 0
while True:
message = dora_node.next(timeout=0.001)

message = dora_node.next(timeout=0.05)
if message is None:
break

if message["type"] != "INPUT":
continue
sent = message["value"][0].as_py()
sent_in_s = sent / 1_000_000
j = message["value"][1].as_py()
sent_in_s = sent / 1_000_000_000
received = time.perf_counter_ns()
received_in_s = received / 1_000_000
received_in_s = received / 1_000_000_000

i += 1
print(
f"[{i}] Sent: {sent_in_s}, Received: {received_in_s}, Difference: {received_in_s - sent_in_s}"
f"[{i}, {j}] Sent: {sent_in_s}, Received: {received_in_s}, Difference: {received_in_s - sent_in_s}"
)
assert received_in_s - sent_in_s < 0.1
assert received_in_s - sent_in_s < 1.0
time.sleep(0.1)




+ 3
- 1
tests/queue_size_and_timeout_python/send_data.py View File

@@ -8,10 +8,12 @@ def main() -> None:
dora_node = Node()
i = 0
while True:
dora_node.send_output("ts", pa.array([time.perf_counter_ns()]))
dora_node.send_output("ts", pa.array([time.perf_counter_ns(), i]))
i += 1
# print(f"Sent {i} times", flush=True)
time.sleep(0.001)
if dora_node.next(timeout=0.001) is None:
break


if __name__ == "__main__":


Loading…
Cancel
Save