Browse 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 14 years ago
parent
commit
4b4813d587
1 changed files with 17 additions and 13 deletions
  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)
             queue_pid = os.fork()
             if queue_pid == 0:
+                signal.alarm(10)
                 msgq.register_socket(queue)
                 msgq.run()
             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)
-                    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)
 
     def test_small_sends(self):