Skip to content

Commit 250795d

Browse files
committed
Fix thread pool bug in unit test
Seemed to occur when running the full test stack with pytest -s -v. Did not notice it when running the test file individually.
1 parent d97d90b commit 250795d

1 file changed

Lines changed: 13 additions & 7 deletions

File tree

tests/unit/divbase_api/test_vcf_dimensions_concurrency_task_submission.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import asyncio
6+
from concurrent.futures import ThreadPoolExecutor
67
from dataclasses import dataclass
78
from types import SimpleNamespace
89
from unittest.mock import AsyncMock, MagicMock, patch
@@ -32,13 +33,18 @@ def _run_update_endpoint(db: MagicMock) -> DimensionsUpdateSubmitResult:
3233
"""Helper function that runs the update endpoint with the given mocked db and fixed project/user info. Returns the endpoint result."""
3334
project = ProjectTest(id=7, name="test-project", bucket_name="test-bucket")
3435
user = UserTest(id=99)
35-
return asyncio.run(
36-
vcf_dimensions.update_vcf_dimensions_endpoint(
37-
project_name=project.name,
38-
project_and_user_and_role=(project, user, ProjectRoles.EDIT),
39-
db=db,
40-
)
41-
)
36+
with (
37+
ThreadPoolExecutor(max_workers=1) as pool
38+
): # Use separate thread per test call to avoid event loop collisions/errors when running the full test stack with pytest -s -v
39+
return pool.submit(
40+
lambda: asyncio.run(
41+
vcf_dimensions.update_vcf_dimensions_endpoint(
42+
project_name=project.name,
43+
project_and_user_and_role=(project, user, ProjectRoles.EDIT),
44+
db=db,
45+
)
46+
)
47+
).result(timeout=5.0)
4248

4349

4450
def test_update_vcf_dimensions_endpoint_reuses_existing_active_job():

0 commit comments

Comments
 (0)