traffic: reinitialise RNG in each child
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Wed, 21 Nov 2018 23:19:46 +0000 (12:19 +1300)
committerDouglas Bagnall <dbagnall@samba.org>
Tue, 8 Jan 2019 22:55:33 +0000 (23:55 +0100)
Otherwise they all replay using the same random sequence.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/emulate/traffic.py

index 62df873dd37a15bdb17c925b173f0832df593aca..6dfc9c6b71f7ccf4e8243864b64a52fb34c0c482 100644 (file)
@@ -1442,7 +1442,12 @@ def flushing_signal_handler(signal, frame):
 
 def replay_seq_in_fork(cs, start, context, account, client_id, server_id=1):
     """Fork a new process and replay the conversation sequence."""
-    endpoints = (server_id, client_id)
+    # We will need to reseed the random number generator or all the
+    # clients will end up using the same sequence of random
+    # numbers. random.randint() is mixed in so the initial seed will
+    # have an effect here.
+    seed = client_id * 1000 + random.randint(0, 999)
+
     # flush our buffers so messages won't be written by both sides
     sys.stdout.flush()
     sys.stderr.flush()
@@ -1453,8 +1458,9 @@ def replay_seq_in_fork(cs, start, context, account, client_id, server_id=1):
     # we must never return, or we'll end up running parts of the
     # parent's clean-up code. So we work in a try...finally, and
     # try to print any exceptions.
-
     try:
+        random.seed(seed)
+        endpoints = (server_id, client_id)
         status = 0
         t = cs[0][0]
         c = Conversation(t, endpoints, seq=cs, conversation_id=client_id)