From ff1c89db248d3c01454a52259425401d7bda398f Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Mon, 18 Dec 2023 16:25:08 +0100 Subject: [PATCH] test: make more stable by waiting for task to finish --- tests/integration/memleak_test.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/integration/memleak_test.py b/tests/integration/memleak_test.py index 8a5a78470..f3ee962bd 100644 --- a/tests/integration/memleak_test.py +++ b/tests/integration/memleak_test.py @@ -1,4 +1,5 @@ import gc +import threading import time import weakref from pathlib import Path @@ -45,6 +46,11 @@ def _scoped_test_memleak( shell = weakref.ref(kernel().shell) session = weakref.ref(kernel().session) page_session.goto("about:blank") + if context()._last_kernel_cull_task: + if not context()._last_kernel_cull_task.done(): + event = threading.Event() + context()._last_kernel_cull_task.add_done_callback(lambda _: event.set()) + assert event.wait() assert context().closed_event.wait(10) if shell(): del shell().__dict__