Skip to content

Commit

Permalink
Update tests to not have too long time.sleeps
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardusrendy committed Apr 20, 2024
1 parent d7cff64 commit 4f915e5
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion examples/fake_lab/tasks/starting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def run(self):
sample_positions,
):
self.lab_view.move_sample(self.sample, sample_positions[None][self.dest][0])
time.sleep(5)
time.sleep(1)
return self.task_id
2 changes: 1 addition & 1 deletion tests/fake_lab/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[general]
working_dir = "."
name = '__fake_alab__'
name = 'Alab'

[mongodb]
host = 'localhost'
Expand Down
2 changes: 1 addition & 1 deletion tests/fake_lab/tasks/starting.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def run(self):
sample_positions,
):
self.lab_view.move_sample(self.sample, sample_positions[None][self.dest][0])
time.sleep(5)
time.sleep(1)
return self.task_id
2 changes: 1 addition & 1 deletion tests/test_device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def setUp(self):
self.process = Process(target=launch_device_manager)
self.process.daemon = False
self.process.start()
time.sleep(1.5)
time.sleep(1)

def tearDown(self):
self.process.terminate()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_lab_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def test_request_resources(self):
"LOCKED",
self.sample_view.get_sample_position_status("furnace_table")[0].name,
)
time.sleep(4)
time.sleep(0.1)
self.assertEqual("IDLE", self.device_view.get_status("furnace_1").name)
self.assertEqual("IDLE", self.device_view.get_status("dummy").name)

Expand Down
5 changes: 2 additions & 3 deletions tests/test_launch.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class TestLaunch(unittest.TestCase):
def setUp(self) -> None:
time.sleep(2)
time.sleep(0.1)
cleanup_lab(
all_collections=True,
_force_i_know_its_dangerous=True,
Expand All @@ -29,7 +29,7 @@ def setUp(self) -> None:
self.worker_process = subprocess.Popen(
["alabos", "launch_worker", "--processes", "4", "--threads", "1"]
)
time.sleep(5) # waiting for starting up
time.sleep(3) # waiting for starting up

def tearDown(self) -> None:
self.main_process.terminate()
Expand Down Expand Up @@ -83,7 +83,6 @@ def test_submit_experiment(self):
self.assertTrue("success", resp_json["status"])
exp_ids.append(exp_id)
time.sleep(3)
time.sleep(40)
# self.assertEqual(9, self.task_view._task_collection.count_documents({}))
# print(list(self.task_view._task_collection.find({})))
print(datetime.datetime.now())
Expand Down
16 changes: 10 additions & 6 deletions tests/test_task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def launch_task_manager():

class TestTaskManager(unittest.TestCase):
def setUp(self) -> None:
time.sleep(2)
time.sleep(0.1)
cleanup_lab(
all_collections=True,
_force_i_know_its_dangerous=True,
Expand All @@ -43,7 +43,7 @@ def setUp(self) -> None:
self.process = Process(target=launch_task_manager)
self.process.daemon = True
self.process.start()
time.sleep(2)
time.sleep(0.1)

def tearDown(self) -> None:
self.process.terminate()
Expand All @@ -54,7 +54,7 @@ def tearDown(self) -> None:
database_name="Alab_sim",
user_confirmation="y",
)
time.sleep(2)
time.sleep(0.1)

def test_task_requester(self):
furnace_type = self.devices["furnace_1"].__class__
Expand All @@ -68,6 +68,7 @@ def test_task_requester(self):
{
"devices": {furnace_type: "furnace_1"},
"sample_positions": {furnace_type: {"inside": ["furnace_1/inside"]}},
"error": None
},
result,
)
Expand All @@ -79,7 +80,7 @@ def test_task_requester(self):
(SamplePositionStatus.LOCKED, self.resource_requester.task_id),
)
self.resource_requester.release_resources(_id)
time.sleep(2)
time.sleep(0.1)
self.assertEqual(
self.device_view.get_status("furnace_1"), DeviceTaskStatus.IDLE
)
Expand All @@ -97,6 +98,7 @@ def test_task_requester(self):
{
"devices": {furnace_type: "furnace_1"},
"sample_positions": {furnace_type: {"inside": ["furnace_1/inside"]}},
"error": None
},
result,
)
Expand All @@ -107,8 +109,7 @@ def test_task_requester(self):
self.sample_view.get_sample_position_status("furnace_1/inside"),
(SamplePositionStatus.LOCKED, self.resource_requester.task_id),
)
self.resource_requester.release_resources(_id)
time.sleep(2)
True == self.resource_requester.release_resources(_id)
self.assertEqual(
self.device_view.get_status("furnace_1"), DeviceTaskStatus.IDLE
)
Expand All @@ -126,6 +127,7 @@ def test_task_requester(self):
{
"devices": {furnace_type: "furnace_1"},
"sample_positions": {furnace_type: {"inside": ["furnace_1/inside"]}},
"error": None
},
result,
)
Expand All @@ -150,6 +152,7 @@ def test_task_requester(self):
]
}
},
"error": None
},
result,
)
Expand Down Expand Up @@ -179,6 +182,7 @@ def test_task_requester(self):
]
},
},
"error": None
},
result,
)
Expand Down

0 comments on commit 4f915e5

Please sign in to comment.