From 5695d1a719c5446ac2b56df957b225b689269891 Mon Sep 17 00:00:00 2001 From: rdb Date: Thu, 24 Feb 2022 11:43:11 +0100 Subject: [PATCH] tests: Add separate unit test for AsyncFuture.wait() with timeout Since it's using a different implementation than the no-timeout version now --- tests/event/test_futures.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/event/test_futures.py b/tests/event/test_futures.py index db09d8c677..13531db55b 100644 --- a/tests/event/test_futures.py +++ b/tests/event/test_futures.py @@ -88,6 +88,30 @@ def test_future_wait(): assert fut.result() is None +@pytest.mark.skipif(not core.Thread.is_threading_supported(), + reason="Threading support disabled") +def test_future_wait_timeout(): + threading = pytest.importorskip("direct.stdpy.threading") + + fut = core.AsyncFuture() + + # Launch a thread to set the result value. + def thread_main(): + time.sleep(0.001) + fut.set_result(None) + + thread = threading.Thread(target=thread_main) + + assert not fut.done() + thread.start() + + assert fut.result(1.0) is None + + assert fut.done() + assert not fut.cancelled() + assert fut.result() is None + + @pytest.mark.skipif(not core.Thread.is_threading_supported(), reason="Threading support disabled") def test_future_wait_cancel():