def test_integration_failed(self): with self.yield_sleepy(ThermosTaskRunner, sleep=0, exit_code=1) as task_runner: task_runner.start() task_runner.forked.wait() self.run_to_completion(task_runner) assert task_runner.status is not None assert TaskState.Name(task_runner.status.status) == 'TASK_FAILED' # no-op task_runner.stop() assert task_runner.status is not None assert TaskState.Name(task_runner.status.status) == 'TASK_FAILED'
def test_chained_health_interface(): hi = ChainedStatusChecker([]) assert hi.status is None hi = ChainedStatusChecker([Healthy()]) assert hi.status is None si1 = EventHealth() si2 = EventHealth() chained_si = ChainedStatusChecker([si1, si2]) for si in (si1, si2): assert not si.started.is_set() chained_si.start() for si in (si1, si2): assert si.started.is_set() assert chained_si.status is None reason = StatusResult('derp', TaskState.Value('TASK_FAILED')) si2.set_status(reason) assert chained_si.status == reason assert chained_si.status.reason == 'derp' assert TaskState.Name(chained_si.status.status) == 'TASK_FAILED' for si in (si1, si2): assert not si.stopped.is_set() chained_si.stop() for si in (si1, si2): assert si.stopped.is_set()
def test_integration_stop(self): with self.yield_sleepy(ThermosTaskRunner, sleep=1000, exit_code=0) as task_runner: task_runner.start() task_runner.forked.wait() assert task_runner.status is None task_runner.stop() assert task_runner.status is not None assert TaskState.Name(task_runner.status.status) == 'TASK_KILLED'
def test_integration_quitquitquit(self): ignorant_script = ';'.join([ 'import time, signal', 'signal.signal(signal.SIGTERM, signal.SIG_IGN)', 'time.sleep(1000)' ]) class ShortPreemptionThermosTaskRunner(ThermosTaskRunner): THERMOS_PREEMPTION_WAIT = Amount(1, Time.SECONDS) with self.yield_runner( ShortPreemptionThermosTaskRunner, command="%s -c '%s'" % (sys.executable, ignorant_script)) as task_runner: task_runner.start() task_runner.forked.wait() task_runner.stop(timeout=Amount(5, Time.SECONDS)) assert task_runner.status is not None assert TaskState.Name(task_runner.status.status) == 'TASK_KILLED'
def __repr__(self): return '%s(%r, status=%r)' % (self.__class__.__name__, self._reason, TaskState.Name(self._status))