Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oeway committed Dec 6, 2024
1 parent cd3a5b4 commit 4ff56a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
1 change: 1 addition & 0 deletions hypha/core/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ async def schedule_task(
):
"""Schedule a task."""
assert not (corn and time), "Only one of corn or time can be provided"
assert corn or time, "Either corn or time must be provided"
my_task: AsyncKicker = self._broker.register_task(
task, task_name=task_name
).kicker()
Expand Down
7 changes: 5 additions & 2 deletions hypha/core/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -1784,8 +1784,11 @@ async def unload(self, context=None):
await self._s3_controller.cleanup_workspace(winfo)

self._active_ws.dec()
self._active_clients.remove(ws)
self._active_svc.remove(ws)
try:
self._active_clients.remove(ws)
self._active_svc.remove(ws)
except KeyError:
pass

await self._close_workspace(winfo)

Expand Down
34 changes: 17 additions & 17 deletions tests/test_redis.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,23 +112,6 @@ async def dummy_task(data):
assert execution_tracker["executed"] is True
assert execution_tracker["data"] == "test-data"

# Test scheduling a task with a specific time
execution_tracker["executed"] = False # Reset the tracker
scheduled_time = datetime.now() + timedelta(seconds=2)
schedule = await redis_store.schedule_task(
dummy_task, "scheduled-test-data", time=scheduled_time
)

# Assert that the schedule ID is valid
assert schedule.schedule_id is not None

# Allow enough time for the task to execute
await asyncio.sleep(3)

# Verify that the task executed
assert execution_tracker["executed"] is True
assert execution_tracker["data"] == "scheduled-test-data"

# Test scheduling a task using a cron expression
execution_tracker["executed"] = False # Reset the tracker
cron_expr = "*/1 * * * *"
Expand All @@ -149,6 +132,23 @@ async def dummy_task(data):
# Clean up the scheduled task
await redis_store.delete_schedule("cron-test")

# Test scheduling a task with a specific time
execution_tracker["executed"] = False # Reset the tracker
scheduled_time = datetime.now() + timedelta(seconds=2)
schedule = await redis_store.schedule_task(
dummy_task, "scheduled-test-data", time=scheduled_time, schedule_id="scheduled"
)

# Assert that the schedule ID is valid
assert schedule.schedule_id == "scheduled"

# Allow enough time for the task to execute
await asyncio.sleep(3)

# Verify that the task executed
assert execution_tracker["executed"] is True
assert execution_tracker["data"] == "scheduled-test-data"


async def test_websocket_server(fastapi_server, test_user_token_2):
"""Test the websocket server."""
Expand Down

0 comments on commit 4ff56a1

Please sign in to comment.