From fc0c75f40ee741304a8e831450d488a86c4b62ce Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Fri, 28 Aug 2020 18:54:48 +0200 Subject: [PATCH] test/api: race-free api.metadata access Access metadata.api only after `api` has exited the context and thus the event loop has stopped and all incoming messages, like the one setting the metadata, have been processed. See commit 803433fb6200b3c7f607a5a0f925086ff64e74e8 for a lecture about the internals and all the details involved. --- test/mod/test_api.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/mod/test_api.py b/test/mod/test_api.py index 3b600d03..7f224af4 100644 --- a/test/mod/test_api.py +++ b/test/mod/test_api.py @@ -92,11 +92,12 @@ class TestAPI(unittest.TestCase): osbuild.api.metadata(data, path=path) return 0 - with osbuild.api.API(args, monitor, socket_address=path) as api: + api = osbuild.api.API(args, monitor, socket_address=path) + with api: p = mp.Process(target=metadata, args=(path, )) p.start() p.join() self.assertEqual(p.exitcode, 0) - metadata = api.metadata # pylint: disable=no-member - assert metadata - self.assertEqual(metadata, {"meta": "42"}) + metadata = api.metadata # pylint: disable=no-member + assert metadata + self.assertEqual(metadata, {"meta": "42"})