Skip to content

Commit

Permalink
Splitting time consuming tests to multiple ones
Browse files Browse the repository at this point in the history
Creating and closing processes and threads can be quite time consuming
resulting to test timeouts if the tests performs a lot of actions.
  • Loading branch information
thodkatz committed Dec 9, 2024
1 parent 6d6749f commit cbb2619
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[pytest]
python_files = test_*.py
addopts =
--timeout 10
--timeout 15
-v
-s
--color=yes
Expand Down
17 changes: 11 additions & 6 deletions tests/test_server/test_grpc/test_training_servicer.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,34 +403,39 @@ def fit(self):
pause_thread.join()
resume_thread.join()

def test_graceful_shutdown_for_any_state(self, grpc_stub):
# after init
def test_graceful_shutdown_after_init(self, grpc_stub):
init_response = grpc_stub.Init(training_pb2.TrainingConfig(yaml_content=prepare_unet2d_test_environment()))
training_session_id = training_pb2.TrainingSessionId(id=init_response.id)
grpc_stub.CloseTrainerSession(training_session_id)

# after start
def test_graceful_shutdown_after_start(self, grpc_stub):
init_response = grpc_stub.Init(training_pb2.TrainingConfig(yaml_content=prepare_unet2d_test_environment()))
training_session_id = training_pb2.TrainingSessionId(id=init_response.id)
grpc_stub.Start(training_session_id)
grpc_stub.CloseTrainerSession(training_session_id)

# after pause
def test_graceful_shutdown_after_pause(self, grpc_stub):
init_response = grpc_stub.Init(training_pb2.TrainingConfig(yaml_content=prepare_unet2d_test_environment()))
training_session_id = training_pb2.TrainingSessionId(id=init_response.id)
grpc_stub.Start(training_session_id)
grpc_stub.Pause(training_session_id)
grpc_stub.CloseTrainerSession(training_session_id)

# after resume
def test_graceful_shutdown_after_resume(self, grpc_stub):
init_response = grpc_stub.Init(training_pb2.TrainingConfig(yaml_content=prepare_unet2d_test_environment()))
training_session_id = training_pb2.TrainingSessionId(id=init_response.id)
grpc_stub.Start(training_session_id)
grpc_stub.Pause(training_session_id)
grpc_stub.Resume(training_session_id)
grpc_stub.CloseTrainerSession(training_session_id)

# attempt to close again
def test_close_trainer_session_twice(self, grpc_stub):
# Attempt to close the session twice
init_response = grpc_stub.Init(training_pb2.TrainingConfig(yaml_content=prepare_unet2d_test_environment()))
training_session_id = training_pb2.TrainingSessionId(id=init_response.id)
grpc_stub.CloseTrainerSession(training_session_id)

# The second attempt should raise an error
with pytest.raises(grpc.RpcError) as excinfo:
grpc_stub.CloseTrainerSession(training_session_id)
assert "Unknown session" in excinfo.value.details()
Expand Down
1 change: 0 additions & 1 deletion tiktorch/server/session/backend/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def __init__(self, trainer: Trainer) -> None:
super().__init__()
self._trainer = trainer
self._trainer.should_stop_callbacks.register(self._should_stop)
self._shutdown_event = threading.Event()
self._state = TrainerState.IDLE
self._pause_triggered = False
self._session_thread = threading.Thread(target=self._start_session, name="SessionThread")
Expand Down

0 comments on commit cbb2619

Please sign in to comment.