From 07c0680ff6662e4d3bb8bb128f2fd61d9dd55c1f Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 7 Feb 2023 12:56:37 +0100 Subject: [PATCH] test-client: randomly kill or close the stub test service The test stub service watches stdin, and if it gets closed the service will shut down. Note that the service does not catch any signals, so sending a signal will kill the service right away. The previous code first closed stdin, and then killed the process. That can result in different outcomes on D-Bus. Usually the signal gets received first, and the test service just drops off the bus. Sometimes it notices the closing of stdin and shuts actively down. That can make a difference, especially for the test_monitor() test which runs the monitor while stopping the service. We could just always kill the stub service to get consistent behavior. However, that doesn't seem very useful. Instead, randomize the behavior to easier see how the behavior differs. (cherry picked from commit fc282d5e05f5850d7819bb0bf3b9685db9ae89ee) --- src/tests/client/test-client.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/tests/client/test-client.py b/src/tests/client/test-client.py index 2c8f332706..db4320ba7b 100755 --- a/src/tests/client/test-client.py +++ b/src/tests/client/test-client.py @@ -656,17 +656,37 @@ class NMStubServer: ) self._p = p - def shutdown(self): + def shutdown(self, kill_mode="random"): conn = self._conn p = self._p self._nmobj = None self._nmiface = None self._conn = None self._p = None - p.stdin.close() - p.kill() + + # The test stub service watches stdin and will do a proper + # shutdown when it closes. That means, to send signals about + # going away. + # On the other hand, just killing it will cause the process + # from dropping off the bus. + if kill_mode == "kill": + p.kill() + elif kill_mode == "stdin-close": + p.stdin.close() + else: + assert kill_mode == "random" + ops = [p.stdin.close, p.kill] + random.shuffle(ops) + ops[0]() + r = random.random() + if r < 0.75: + if r < 0.5: + time.sleep(r * 0.2) + ops[1]() + if Util.popen_wait(p, 1) is None: raise Exception("Stub service did not exit in time") + p.stdin.close() if self._conn_get_main_object(conn) is not None: raise Exception( "Stub service is not still here although it should shut down"