Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not start the asynchronous task manager in tests #746

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions storage_service/common/startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
LOGGER = logging.getLogger(__name__)


def startup(space_path: Optional[pathlib.Path] = None) -> None:
def startup(
space_path: Optional[pathlib.Path] = None, start_async: bool = True
) -> None:
if space_path is None:
space_path = pathlib.Path(os.sep)

Expand All @@ -29,7 +31,8 @@
except PopulateLockError:
LOGGER.warning("Another worker is initializing the database.")

start_async_manager()
if start_async:
start_async_manager()

Check warning on line 35 in storage_service/common/startup.py

View check run for this annotation

Codecov / codecov/patch

storage_service/common/startup.py#L35

Added line #L35 was not covered by tests


class PopulateLockError(Exception):
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def startup(working_directory_path: Path) -> None:
"""
from common.startup import startup

startup(working_directory_path) # TODO: get rid of this!
startup(working_directory_path, start_async=False) # TODO: get rid of this!


def get_size(path: Path) -> int:
Expand Down
8 changes: 4 additions & 4 deletions tests/storage_service/test_startup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_create_default_locations(self):
assert not models.Space.objects.all().exists()
assert not models.Location.objects.all().exists()
# Run test
self.startup()
self.startup(start_async=False)
# Assert Space & Locations created
assert models.Space.objects.get(access_protocol="FS")
assert models.Location.objects.get(purpose="TS")
Expand All @@ -40,7 +40,7 @@ def test_handle_multiple_identical_spaces(self):
models.Space.objects.create(path="/", access_protocol="FS")
assert len(models.Space.objects.filter(access_protocol="FS")) == 2
# Run test
self.startup()
self.startup(start_async=False)
# Verify no locations exist - space errored gracefully
assert len(models.Space.objects.filter(access_protocol="FS")) == 2
assert not models.Location.objects.all().exists()
Expand All @@ -63,7 +63,7 @@ def test_handle_multiple_identical_locations(self):
assert len(models.Space.objects.filter(access_protocol="FS")) == 1
assert len(models.Location.objects.filter(purpose="SS")) == 2
# Run test
self.startup()
self.startup(start_async=False)
# Verify no new Location was created
assert len(models.Space.objects.filter(access_protocol="FS")) == 1
assert len(models.Location.objects.filter(purpose="SS")) == 2
Expand All @@ -87,6 +87,6 @@ def test_dont_create_if_same_purpose_already_exist(self):
)
assert len(models.Location.objects.all()) == 6
# Run test
self.startup()
self.startup(start_async=False)
# Verify no new Locations created
assert len(models.Location.objects.all()) == 6