Ejemplo n.º 1
0
def test_hot_start(MockABC, simple_config, state_file, cold_start,
                   corrupt_state, delete_state):
    # Initially start up the server without a state file. Should be cold
    # started.
    assert not os.path.lexists(state_file)
    s = Server(simple_config, cold_start)

    try:
        job_id = s.create_job(None, owner="me")
        time.sleep(0.05)
        assert s.get_job_state(None, job_id)["state"] == JobState.ready
    finally:
        s.stop_and_join()

    # State should be dumped
    assert os.path.lexists(state_file)

    # Corrupt the state if required
    if corrupt_state:
        # Just leave the file empty...
        open(state_file, "w").close()

    # Delete the state if required
    if delete_state:
        # Just leave the file empty...
        os.remove(state_file)

    # Start a new server
    s = Server(simple_config, cold_start)
    try:
        # Should have the same state as before, if doing a hot start
        if cold_start or corrupt_state or delete_state:
            assert s.get_job_state(None, job_id)["state"] == JobState.unknown
        else:
            assert s.get_job_state(None, job_id)["state"] == JobState.ready
    finally:
        s.stop_and_join()