Skip to content

Commit

Permalink
Merge pull request #56 from lsst-sqre/tickets/DM-38279
Browse files Browse the repository at this point in the history
DM-38279: Wait for first image service run during startup
  • Loading branch information
rra authored Mar 30, 2023
2 parents f45f7ae + f6a9557 commit 45a6ea6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
9 changes: 8 additions & 1 deletion src/jupyterlabcontroller/services/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,14 +394,21 @@ async def refresh(self) -> None:
self._to_prepull = to_prepull

async def start(self) -> None:
"""Start a periodic refresh as a background task."""
"""Start a periodic refresh as a background task.
Does not return until the background refresh has completed its first
run. We don't want to start answering user requests until we have
populated our lists of available images; otherwise, we might return
bogus information for the spawner form.
"""
if self._scheduler:
msg = "Image service already running, cannot start again"
self._logger.warning(msg)
return
self._logger.info("Starting image service")
self._scheduler = Scheduler()
await self._scheduler.spawn(self._refresh_loop())
await self._refreshed.wait()

async def stop(self) -> None:
"""Stop the background refresh task."""
Expand Down
4 changes: 0 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@ async def factory(
"""Create a component factory for tests."""
mock_kubernetes.set_nodes_for_test(obj_factory.nodecontents)
async with Factory.standalone(config) as factory:
# Currently, always start background processes since tests expect it.
# This is temporary until tests can be refactored to decide whether
# they want background processes running.
await factory.start_background_services()
yield factory


Expand Down
8 changes: 2 additions & 6 deletions tests/services/lab_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
"""Tests for the lab service."""

import asyncio

import pytest

from jupyterlabcontroller.factory import Factory
Expand All @@ -16,6 +14,7 @@ async def test_lab_manager(
token, user = obj_factory.get_user()
lab = obj_factory.labspecs[0]
lab_manager = factory.create_lab_manager()
await factory.start_background_services()

assert not lab_manager.check_for_user(user.username)
await lab_manager.create_lab(user, token, lab)
Expand All @@ -33,6 +32,7 @@ async def test_get_active_users(
token, user = obj_factory.get_user()
lab = obj_factory.labspecs[0]
lab_manager = factory.create_lab_manager()
await factory.start_background_services()

assert await factory.user_map.running() == []

Expand All @@ -43,8 +43,4 @@ async def test_get_active_users(
assert await factory.user_map.running() == [user.username]

await lab_manager.delete_lab(user.username)

# We have to let the background task run and complete the namespace
# deletion.
await asyncio.sleep(0.2)
assert await factory.user_map.running() == []

0 comments on commit 45a6ea6

Please sign in to comment.