def s(MockABC, config_file): # A server which is created and shut down with each use. s = Server(config_file) yield s s.stop_and_join()
def test_stop_and_join_disconnects(MockABC, simple_config): # Clients should be disconnected when doing stop and join s = Server(simple_config) c = SimpleClient() c.call("version") s.stop_and_join() time.sleep(0.05) assert c.sock.recv(1024) == b""
def test_join(MockABC, simple_config): # Tests join, stop_and_join and is_alive s = Server(simple_config) assert s.is_alive() is True joining_thread = threading.Thread(target=s.join) joining_thread.start() # The server should still be running... time.sleep(0.05) assert joining_thread.is_alive() assert s.is_alive() is True # When server is stopped, the joining thread should be complete s.stop_and_join() assert s.is_alive() is False joining_thread.join()
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()