From 301ce3c025c1d84dd42b94deb90bdcf853450529 Mon Sep 17 00:00:00 2001 From: xs5871 Date: Thu, 16 Feb 2023 06:02:06 +0000 Subject: [PATCH] Improve unit test handling of pending/delayed keyboard actions --- tests/keyboard_test.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/keyboard_test.py b/tests/keyboard_test.py index 5cdaf12..1a507c5 100644 --- a/tests/keyboard_test.py +++ b/tests/keyboard_test.py @@ -74,7 +74,14 @@ class KeyboardTest: is_pressed = e[1] self.pins[key_pos].value = is_pressed self.do_main_loop() - self.keyboard._main_loop() + + # wait up to 10s for delayed actions to resolve, if there are any + timeout = time.time_ns() + 10 * 1_000_000_000 + while timeout > time.time_ns(): + self.do_main_loop() + if not self.keyboard._timeouts and not self.keyboard._resume_buffer: + break + assert timeout > time.time_ns(), 'infinite loop detected' matching = True for i in range(max(len(hid_reports), len(assert_reports))):