From 0ecb2048fcf2f2e69253290a8aeeb46ab1ecec82 Mon Sep 17 00:00:00 2001 From: marc2332 Date: Thu, 2 Nov 2023 18:55:27 +0100 Subject: [PATCH] fix: Proper event loop ticker for testing runner --- crates/testing/src/test_handler.rs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/crates/testing/src/test_handler.rs b/crates/testing/src/test_handler.rs index 98dc5561d..085250f94 100644 --- a/crates/testing/src/test_handler.rs +++ b/crates/testing/src/test_handler.rs @@ -12,7 +12,7 @@ use torin::geometry::{Area, Size2D}; pub use freya_core::events::FreyaEvent; pub use freya_elements::events::mouse::MouseButton; -use tokio::time::{sleep, timeout}; +use tokio::time::{interval, timeout}; use crate::test_node::TestNode; use crate::test_utils::TestUtils; @@ -71,7 +71,11 @@ impl TestingHandler { self.provide_vdom_contexts(); - let vdom = &mut self.vdom; + let mut ticker = if self.config.run_ticker { + Some(interval(Duration::from_millis(16))) + } else { + None + }; // Handle platform and VDOM events loop { @@ -85,9 +89,12 @@ impl TestingHandler { if let Ok(ev) = platform_ev { match ev { EventMessage::RequestRerender => { - if self.config.run_ticker { - sleep(Duration::from_millis(16)).await; + if let Some(ticker) = ticker.as_mut() { + ticker.tick().await; self.ticker_sender.send(()).unwrap(); + timeout(self.config.vdom_timeout(), self.vdom.wait_for_work()) + .await + .ok(); } } EventMessage::FocusAccessibilityNode(node_id) => { @@ -101,12 +108,13 @@ impl TestingHandler { } if let Ok(ev) = vdom_ev { - vdom.handle_event(&ev.name, ev.data.any(), ev.element_id, false); - vdom.process_events(); + self.vdom + .handle_event(&ev.name, ev.data.any(), ev.element_id, false); + self.vdom.process_events(); } } - timeout(self.config.vdom_timeout(), vdom.wait_for_work()) + timeout(self.config.vdom_timeout(), self.vdom.wait_for_work()) .await .ok();