mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 02:30:24 +01:00
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.
This commit is contained in:
parent
b32e4c941a
commit
fc282d5e05
1 changed files with 23 additions and 3 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue