From 699e9723bf0c26ed1fa41191a03b2b9ab15e8062 Mon Sep 17 00:00:00 2001 From: Leterax <38299494+Leterax@users.noreply.github.com> Date: Fri, 25 Jun 2021 23:10:01 +0200 Subject: [PATCH] fix scheduling test now uses real timing data instead of just assuming all code executes in 0 sec. --- tests/test_scheduler.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/test_scheduler.py b/tests/test_scheduler.py index 45dcaa11..7a62b989 100644 --- a/tests/test_scheduler.py +++ b/tests/test_scheduler.py @@ -25,13 +25,17 @@ def test_clock_timer(self): self.test_value = 0 event = scheduler.run_every(self.increase_value, 0.1) - for _ in range(30): + start = time.time() + delta = time.time() + while (delta - start) <= 0.5: # simulate a render loop - scheduler.execute() + print(self.test_value) time.sleep(0.01) - self.assertEqual(self.test_value, 3) - + scheduler.execute() + delta = time.time() + self.assertEqual(self.test_value, 5) + # make sure it stays 5 once we cancel the event scheduler.cancel(event) - time.sleep(0.2) + time.sleep(0.11) scheduler.execute() - self.assertEqual(self.test_value, 3) + self.assertEqual(self.test_value, 5)