Skip to content

Commit

Permalink
⏰ Added a timeout to server sub assert
Browse files Browse the repository at this point in the history
  • Loading branch information
Etesam913 committed Jul 30, 2022
1 parent 02dc2db commit c25fddc
Showing 1 changed file with 15 additions and 25 deletions.
40 changes: 15 additions & 25 deletions test/core/test_live_runs.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@ def get_mock_run(self, blueprint, task_runner) -> LiveTaskRun:
self.worker_pool.register_run(live_run)
return live_run

def assert_server_subbed_in_time(self, server, timeout: int = 5) -> None:
start_time = time.time()
while (len(server.subs) == 0) and time.time() - start_time < timeout:
time.sleep(0.3)
self.assertEqual(
len(self.architect.server.subs),
1,
"MockServer doesn't see registered channel",
)

def get_mock_assignment_data_array(self) -> List[InitializationData]:
mock_data = MockTaskRunner.get_mock_assignment_data()
return [mock_data, mock_data]
Expand Down Expand Up @@ -240,11 +250,7 @@ def test_register_concurrent_run(self):
self.assertIsNotNone(channel)
self.assertTrue(channel.is_alive())
task_runner = live_run.task_runner
self.assertEqual(
len(self.architect.server.subs),
1,
"MockServer doesn't see registered channel",
)
self.assert_server_subbed_in_time(self.architect.server)
self.assertIsNotNone(
self.architect.server.last_alive_packet,
"No alive packet received by server",
Expand Down Expand Up @@ -350,11 +356,7 @@ def test_register_run(self):
self.assertIsNotNone(channel)
self.assertTrue(channel.is_alive())
task_runner = live_run.task_runner
self.assertEqual(
len(self.architect.server.subs),
1,
"MockServer doesn't see registered channel",
)
self.assert_server_subbed_in_time(self.architect.server)
self.assertIsNotNone(
self.architect.server.last_alive_packet,
"No alive packet received by server",
Expand Down Expand Up @@ -468,11 +470,7 @@ def test_register_concurrent_run_with_onboarding(self):
self.assertIsNotNone(channel)
self.assertTrue(channel.is_alive())
task_runner = live_run.task_runner
self.assertEqual(
len(self.architect.server.subs),
1,
"MockServer doesn't see registered channel",
)
self.assert_server_subbed_in_time(self.architect.server)
self.assertIsNotNone(
self.architect.server.last_alive_packet,
"No alive packet received by server",
Expand Down Expand Up @@ -706,11 +704,7 @@ def test_register_run_with_onboarding(self):
self.assertIsNotNone(channel)
self.assertTrue(channel.is_alive())
task_runner = live_run.task_runner
self.assertEqual(
len(self.architect.server.subs),
1,
"MockServer doesn't see registered channel",
)
self.assert_server_subbed_in_time(self.architect.server)
self.assertIsNotNone(
self.architect.server.last_alive_packet,
"No alive packet received by server",
Expand Down Expand Up @@ -963,11 +957,7 @@ def screen_unit(unit):
self.assertIsNotNone(channel)
self.assertTrue(channel.is_alive())
task_runner = live_run.task_runner
self.assertEqual(
len(self.architect.server.subs),
1,
"MockServer doesn't see registered channel",
)
self.assert_server_subbed_in_time(self.architect.server)
self.assertIsNotNone(
self.architect.server.last_alive_packet,
"No alive packet received by server",
Expand Down

0 comments on commit c25fddc

Please sign in to comment.