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 803433fb62 for a lecture
about the internals and all the details involved.
This commit is contained in:
parent
a3934ab947
commit
fc0c75f40e
1 changed files with 5 additions and 4 deletions
|
|
@ -92,11 +92,12 @@ class TestAPI(unittest.TestCase):
|
||||||
osbuild.api.metadata(data, path=path)
|
osbuild.api.metadata(data, path=path)
|
||||||
return 0
|
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 = mp.Process(target=metadata, args=(path, ))
|
||||||
p.start()
|
p.start()
|
||||||
p.join()
|
p.join()
|
||||||
self.assertEqual(p.exitcode, 0)
|
self.assertEqual(p.exitcode, 0)
|
||||||
metadata = api.metadata # pylint: disable=no-member
|
metadata = api.metadata # pylint: disable=no-member
|
||||||
assert metadata
|
assert metadata
|
||||||
self.assertEqual(metadata, {"meta": "42"})
|
self.assertEqual(metadata, {"meta": "42"})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue