def testFDTDWaitingTimeoutWhenCleanup(): """ Test issues long running job (dd copy) on the background (non-blocking) and when killing the job, the timeout is set higher than issuing ALARM signal. It's tested that the ALARM signal was raised, but implemented as is is in fact ignored. More obvious when the killTimeout is set much higher. Implementation of #33 - CleanupProcessesAction - attribute to ignore any wait-to-finish timeouts """ class Handler(object): def __init__(self, flag, testName): self.flag = flag self.testName = testName def signalHandler(self, signum, frame): print("test %s signal handler called (sig: %s)" % (self.testName, signum)) # sets flag to check whether some reaction was successfully # invoked self.flag = True c = """ [general] port = 6700 debug = DEBUG killCommand = ../wrapper_kill.sh %(pid)s portRangeFDTServer = 54321,54400 """ f = getTempFile(c) inputOption = "--config=%s" % f.name conf = ConfigFDTD(inputOption.split()) testName = inspect.stack()[0][3] logger = Logger(name=testName, level=logging.DEBUG) apMon = None fdtd = FDTD(conf, apMon, logger) # need long running job command = "dd if=/dev/zero of=/dev/null count=100000000 bs=102400" # set long timeout (will be interrupted sooner by alarm - while # waiting on kill timeout) e = Executor("some_id", command, caller=fdtd, blocking=False, killTimeout=2, logger=logger) try: e.execute() # command remains is running now # try killing the command # since waitTimeout = True, kill will be waiting cl = CleanupProcessesAction("some_id", timeout=1, waitTimeout=True) handler = Handler(False, testName) signal.signal(signal.SIGALRM, handler.signalHandler) assert handler.flag == False print("test %s is waiting here ..." % testName) signal.alarm(1) # raise alarm in timeout seconds cl.execute(conf=conf, caller=fdtd, apMon=None, logger=logger) signal.alarm(0) # disable alarm # but the alarm was called during this waiting (test flag value) assert handler.flag finally: fdtd.shutdown() fdtd.pyroDaemon.closedown()
def testCleanupProcessesAction(): a = CleanupProcessesAction("some_id", timeout = 45) assert a.id == "some_id" assert a.timeout == 45 fdtd = Mock() r = a.execute(None, fdtd, None) assert r.status == 0
def testCleanupProcessesAction(): logger = Logger() a = CleanupProcessesAction("some_id", timeout=4) assert a.id == "some_id" assert a.timeout == 4 assert a.waitTimeout fdtd = Mock() # wihtout this, it remains in the loop, see # CleanupProcessesAction.execute() fdtd.getExecutor().syncFlag = False r = a.execute(caller=fdtd, logger=logger) assert r.status == 0 a = CleanupProcessesAction("some_id", timeout=5, waitTimeout=False) assert a.waitTimeout == False
def testFDTDNotWaitingTimeoutWhenCleanupForced(): """ Test issues long running job (dd copy) on the background (non-blocking) and when killing the job, the timeout is set high. But no timeout is waited and the command is killed immediately. Raising ALARM in 2s never happens and command shall finish immediately (value of the flag changed in the signal handler never happens). Implementation of #33 - CleanupProcessesAction - attribute to ignore any wait-to-finish timeouts """ class Handler: def __init__(self, flag, testName): self.flag = flag self.testName = testName def signalHandler(self, signum, frame): print("test %s signal handler called (sig: %s)" % (self.testName, signum)) # sets flag to check whether some reaction was successfully # invoked self.flag = True c = """ [general] port = 6700 debug = DEBUG killCommand = ../wrapper_kill.sh %(pid)s portRangeFDTServer = 54321,54400 """ f = getTempFile(c) inputOption = "--config=%s" % f.name conf = ConfigFDTD(inputOption.split()) testName = inspect.stack()[0][3] logger = Logger(name=testName, level=logging.DEBUG) apMon = None fdtd = FDTD(conf, apMon, logger) # need long running job command = "dd if=/dev/zero of=/dev/null count=100000000 bs=102400" # set long timeout, shall be killed immediately anyway e = Executor("some_id", command, caller=fdtd, blocking=False, killTimeout=100, logger=logger) try: e.execute() # command remains is running now # try killing the command # since waitTimeout = False, shall be killed immediately cl = CleanupProcessesAction("some_id", timeout=1, waitTimeout=False) handler = Handler(False, testName) signal.signal(signal.SIGALRM, handler.signalHandler) assert handler.flag == False signal.alarm(1) # raise alarm in timeout seconds # should happen immediately so that ALARM is not raised cl.execute(conf=conf, caller=fdtd, apMon=None, logger=logger) signal.alarm(0) # disable alarm # the alarm shouldn't have been called - value should have # remained the same assert handler.flag == False finally: fdtd.shutdown() fdtd.pyroDaemon.closedown()
def testFDTDWaitingTimeoutWhenCleanup(): """ Test issues long running job (dd copy) on the background (non-blocking) and when killing the job, the timeout is set higher than issuing ALARM signal. It's tested that the ALARM signal was raised, but implemented as is is in fact ignored. More obvious when the killTimeout is set much higher. Implementation of #33 - CleanupProcessesAction - attribute to ignore any wait-to-finish timeouts """ class Handler: def __init__(self, flag, testName): self.flag = flag self.testName = testName def signalHandler(self, signum, frame): print("test %s signal handler called (sig: %s)" % (self.testName, signum)) # sets flag to check whether some reaction was successfully # invoked self.flag = True c = """ [general] port = 6700 debug = DEBUG killCommand = ../wrapper_kill.sh %(pid)s portRangeFDTServer = 54321,54400 """ f = getTempFile(c) inputOption = "--config=%s" % f.name conf = ConfigFDTD(inputOption.split()) testName = inspect.stack()[0][3] logger = Logger(name=testName, level=logging.DEBUG) apMon = None fdtd = FDTD(conf, apMon, logger) # need long running job command = "dd if=/dev/zero of=/dev/null count=100000000 bs=102400" # set long timeout (will be interrupted sooner by alarm - while # waiting on kill timeout) e = Executor("some_id", command, caller=fdtd, blocking=False, killTimeout=2, logger=logger) try: e.execute() # command remains is running now # try killing the command # since waitTimeout = True, kill will be waiting cl = CleanupProcessesAction("some_id", timeout=1, waitTimeout=True) handler = Handler(False, testName) signal.signal(signal.SIGALRM, handler.signalHandler) assert handler.flag == False print "test %s is waiting here ..." % testName signal.alarm(1) # raise alarm in timeout seconds cl.execute(conf=conf, caller=fdtd, apMon=None, logger=logger) signal.alarm(0) # disable alarm # but the alarm was called during this waiting (test flag value) assert handler.flag == True finally: fdtd.shutdown() fdtd.pyroDaemon.closedown()
def testFDTDNotWaitingTimeoutWhenCleanupForced(): """ Test issues long running job (dd copy) on the background (non-blocking) and when killing the job, the timeout is set high. But no timeout is waited and the command is killed immediately. Raising ALARM in 2s never happens and command shall finish immediately (value of the flag changed in the signal handler never happens). Implementation of #33 - CleanupProcessesAction - attribute to ignore any wait-to-finish timeouts """ class Handler(object): def __init__(self, flag, testName): self.flag = flag self.testName = testName def signalHandler(self, signum, frame): print("test %s signal handler called (sig: %s)" % (self.testName, signum)) # sets flag to check whether some reaction was successfully # invoked self.flag = True c = """ [general] port = 6700 debug = DEBUG killCommand = ../wrapper_kill.sh %(pid)s portRangeFDTServer = 54321,54400 """ f = getTempFile(c) inputOption = "--config=%s" % f.name conf = ConfigFDTD(inputOption.split()) testName = inspect.stack()[0][3] logger = Logger(name=testName, level=logging.DEBUG) apMon = None fdtd = FDTD(conf, apMon, logger) # need long running job command = "dd if=/dev/zero of=/dev/null count=100000000 bs=102400" # set long timeout, shall be killed immediately anyway e = Executor("some_id", command, caller=fdtd, blocking=False, killTimeout=100, logger=logger) try: e.execute() # command remains is running now # try killing the command # since waitTimeout = False, shall be killed immediately cl = CleanupProcessesAction("some_id", timeout=1, waitTimeout=False) handler = Handler(False, testName) signal.signal(signal.SIGALRM, handler.signalHandler) assert handler.flag == False signal.alarm(1) # raise alarm in timeout seconds # should happen immediately so that ALARM is not raised cl.execute(conf=conf, caller=fdtd, apMon=None, logger=logger) signal.alarm(0) # disable alarm # the alarm shouldn't have been called - value should have # remained the same assert handler.flag == False finally: fdtd.shutdown() fdtd.pyroDaemon.closedown()