Skip to content

Commit

Permalink
Merge pull request #42 from CederGroupHub/test_fix
Browse files Browse the repository at this point in the history
tests(fix): fixing the duplicate errors
  • Loading branch information
idocx authored Sep 20, 2023
2 parents 5f3fe83 + b2063fc commit 10bb840
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ on:
jobs:
py3test:
runs-on: ubuntu-latest
timeout-minutes: 6
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10" ]
Expand Down
8 changes: 7 additions & 1 deletion alab_management/task_manager/resource_requester.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ def __init__(
self._thread.daemon = False
self._thread.start()

self._stop = False

def __close__(self):
self._stop = True
self._thread.join()

def request_resources(
self,
resource_request: _ResourceRequestDict,
Expand Down Expand Up @@ -266,7 +272,7 @@ def release_all_resources(self) -> bool:
)

def _check_request_status_loop(self):
while True:
while not self._stop:
try:
for request_id in self._waiting.copy().keys():
status = self.get_request(request_id=request_id, projection=["status"])["status"] # type: ignore
Expand Down
1 change: 1 addition & 0 deletions alab_management/task_manager/task_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def handle_request_cycles(self):
sample_positions=positions_to_reroute,
),
)
thread.daemon = False
thread.start()

def _handle_requested_resources(self, request_entry: Dict[str, Any]):
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
testpaths = ./tests
env =
D:ALAB_CONFIG = ./tests/fake_lab/config.toml
timeout = 40
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dash_mantine_components>=0.12.1
numpy>=1.21.2
matplotlib>=3.4.3
dramatiq-abort @ git+https://github.com/idocx/dramatiq-abort
slack_sdk>=3.19.5
15 changes: 8 additions & 7 deletions tests/fake_lab/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
from alab_management import add_device
from alab_management import add_task
from .devices.furnace import furnace_1, furnace_2, furnace_3, furnace_4
from .devices.robot_arm import robot_arm
from .devices.furnace import Furnace
from .devices.robot_arm import RobotArm
from .tasks.ending import Ending
from .tasks.heating import Heating
from .tasks.moving import Moving
from .tasks.starting import Starting

add_device(furnace_1)
add_device(furnace_2)
add_device(furnace_3)
add_device(furnace_4)
add_device(robot_arm)
add_device(Furnace(name="furnace_1"))
add_device(Furnace(name="furnace_2"))
add_device(Furnace(name="furnace_3"))
add_device(Furnace(name="furnace_4"))
add_device(RobotArm(name="dummy"))

add_task(Starting)
add_task(Moving)
add_task(Heating)
Expand Down
6 changes: 0 additions & 6 deletions tests/fake_lab/devices/furnace.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,3 @@ def connect(self):

def disconnect(self):
pass


furnace_1 = Furnace(name="furnace_1")
furnace_2 = Furnace(name="furnace_2")
furnace_3 = Furnace(name="furnace_3")
furnace_4 = Furnace(name="furnace_4")
3 changes: 0 additions & 3 deletions tests/fake_lab/devices/robot_arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,3 @@ def connect(self):

def disconnect(self):
pass


robot_arm = RobotArm(name="dummy")
2 changes: 1 addition & 1 deletion tests/test_device_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def setUp(self):
setup_lab()
self.devices_client = DevicesClient(task_id=ObjectId(), timeout=5)
self.process = Process(target=launch_device_manager)
self.process.daemon = True
self.process.daemon = False
self.process.start()
time.sleep(1.5)

Expand Down
9 changes: 5 additions & 4 deletions tests/test_task_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import sys
import time
import unittest
from multiprocessing import Process
Expand Down Expand Up @@ -61,15 +62,15 @@ def test_task_requester(self):
result,
)
self.assertEqual(
self.device_view.get_status("furnace_1"), DeviceStatus.OCCUPIED
self.device_view.get_status("furnace_1"), DeviceTaskStatus.OCCUPIED
)
self.assertEqual(
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(1)
self.assertEqual(self.device_view.get_status("furnace_1"), DeviceStatus.IDLE)
self.assertEqual(self.device_view.get_status("furnace_1"), DeviceTaskStatus.IDLE)
self.assertEqual(
self.sample_view.get_sample_position_status("furnace_1/inside"),
(SamplePositionStatus.EMPTY, None),
Expand All @@ -88,15 +89,15 @@ def test_task_requester(self):
result,
)
self.assertEqual(
self.device_view.get_status("furnace_1"), DeviceStatus.OCCUPIED
self.device_view.get_status("furnace_1"), DeviceTaskStatus.OCCUPIED
)
self.assertEqual(
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(1)
self.assertEqual(self.device_view.get_status("furnace_1"), DeviceStatus.IDLE)
self.assertEqual(self.device_view.get_status("furnace_1"), DeviceTaskStatus.IDLE)
self.assertEqual(
self.sample_view.get_sample_position_status("furnace_1/inside"),
(SamplePositionStatus.EMPTY, None),
Expand Down

0 comments on commit 10bb840

Please sign in to comment.