Commit 19ad29d2 authored by Guido Trotter's avatar Guido Trotter
Browse files

Fix race condition in mainloop unittest



Currently, in testDeferredCancel if the self._CancelEvent are entered
more than 0.3 seconds after the _SendSig have been entered, the test
could fail. This is unlikely but may happen. To avoid it we use
enterabs, to use absolute times.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarMichael Hanselmann <hansmi@google.com>
parent c6987b16
......@@ -25,6 +25,7 @@ import unittest
import signal
import os
import socket
import time
from ganeti import daemon
......@@ -82,13 +83,17 @@ class TestMainloop(testutils.GanetiTestCase):
def testDeferredCancel(self):
self.mainloop.RegisterSignal(self)
self.mainloop.scheduler.enter(0.1, 1, self._SendSig, [signal.SIGCHLD])
handle1 = self.mainloop.scheduler.enter(0.3, 2, self._SendSig,
now = time.time()
self.mainloop.scheduler.enterabs(now + 0.1, 1, self._SendSig,
[signal.SIGCHLD])
handle1 = self.mainloop.scheduler.enterabs(now + 0.3, 2, self._SendSig,
[signal.SIGCHLD])
handle2 = self.mainloop.scheduler.enter(0.4, 2, self._SendSig,
handle2 = self.mainloop.scheduler.enterabs(now + 0.4, 2, self._SendSig,
[signal.SIGCHLD])
self.mainloop.scheduler.enter(0, 1, self._CancelEvent, [handle1])
self.mainloop.scheduler.enter(0, 1, self._CancelEvent, [handle2])
self.mainloop.scheduler.enterabs(now + 0.2, 1, self._CancelEvent,
[handle1])
self.mainloop.scheduler.enterabs(now + 0.2, 1, self._CancelEvent,
[handle2])
self.mainloop.scheduler.enter(0.5, 1, self._SendSig, [signal.SIGTERM])
self.mainloop.Run()
self.assertEquals(self.sendsig_events, [signal.SIGCHLD, signal.SIGTERM])
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment