Parcourir la source

[trac420] Make sure the subprocess doesn't outlive

It could happen in rare occasions that the subprocess survived death of
the tests, mostly when exceptions happened in the parent process and it
didn't kill it. So there's a finally now and the subprocess has a
limited life length just in case it still slipped somehow without kill.
Michal 'vorner' Vaner il y a 14 ans
Parent
commit
4b4813d587
1 fichiers modifiés avec 17 ajouts et 13 suppressions
  1. 17 13
      src/bin/msgq/tests/msgq_test.py

+ 17 - 13
src/bin/msgq/tests/msgq_test.py

@@ -189,23 +189,27 @@ class SendNonblock(unittest.TestCase):
             length = len(data)
             length = len(data)
             queue_pid = os.fork()
             queue_pid = os.fork()
             if queue_pid == 0:
             if queue_pid == 0:
+                signal.alarm(10)
                 msgq.register_socket(queue)
                 msgq.register_socket(queue)
                 msgq.run()
                 msgq.run()
             else:
             else:
-                def killall(signum, frame):
+                try:
+                    def killall(signum, frame):
+                        os.kill(queue_pid, signal.SIGTERM)
+                        sys.exit(1)
+                    signal.signal(signal.SIGALRM, killall)
+                    msg = msgq.preparemsg({"type" : "ping"}, data)
+                    now = time.clock()
+                    while time.clock() - now < 0.2:
+                        out.sendall(msg)
+                        # Check the answer
+                        (routing, received) = msgq.read_packet(out.fileno(),
+                            out)
+                        self.assertEqual({"type" : "pong"},
+                            isc.cc.message.from_wire(routing))
+                        self.assertEqual(data, received)
+                finally:
                     os.kill(queue_pid, signal.SIGTERM)
                     os.kill(queue_pid, signal.SIGTERM)
-                    sys.exit(1)
-                signal.signal(signal.SIGALRM, killall)
-                msg = msgq.preparemsg({"type" : "ping"}, data)
-                now = time.clock()
-                while time.clock() - now < 0.2:
-                    out.sendall(msg)
-                    # Check the answer
-                    (routing, received) = msgq.read_packet(out.fileno(), out)
-                    self.assertEqual({"type" : "pong"},
-                        isc.cc.message.from_wire(routing))
-                    self.assertEqual(data, received)
-                os.kill(queue_pid, signal.SIGTERM)
         self.terminate_check(run)
         self.terminate_check(run)
 
 
     def test_small_sends(self):
     def test_small_sends(self):