Esempio n. 1
0
def test_set_lost():
    worker = Main(1, 'test name', ['default'])
    worker.update_worker()  # first time creates the row
    worker.worker.status = Worker.LOST
    worker.worker.save()

    worker.executor = mock.Mock()
    worker.update_worker()

    assert worker.state == State.terminate
    assert worker.executor.mark_terminated.called
Esempio n. 2
0
def test_signals():
    try:
        worker = Main(1, 'test name', ['default'])
        worker.handle_signals()
        worker.executor = mock.Mock()

        handler = signal.getsignal(signal.SIGINT)
        handler()
        assert worker.state == State.shutdown

        handler = signal.getsignal(signal.SIGTERM)
        handler()
        assert worker.state == State.terminate
        assert worker.executor.mark_terminated.called

    finally:
        # restore the default handlers
        signal.signal(signal.SIGINT, signal.SIG_DFL)
        signal.signal(signal.SIGTERM, signal.SIG_DFL)