Skip to content

Commit bbdd2e7

Browse files
committed
seems to work well
1 parent 050fb67 commit bbdd2e7

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

services/director-v2/tests/unit/with_dbs/test_modules_comp_scheduler_dask_scheduler.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from pytest_mock.plugin import MockerFixture
4646
from pytest_simcore.helpers.typing_env import EnvVarsDict
4747
from servicelib.rabbitmq import RabbitMQClient
48+
from servicelib.redis import CouldNotAcquireLockError
4849
from settings_library.rabbit import RabbitSettings
4950
from settings_library.redis import RedisSettings
5051
from simcore_postgres_database.models.comp_runs import comp_runs
@@ -162,29 +163,34 @@ async def _assert_comp_tasks_db(
162163
async def schedule_all_pipelines(scheduler: BaseCompScheduler) -> None:
163164
# NOTE: we take a copy of the pipelines, as this could change quickly if there are
164165
# misconfigured pipelines that would be removed from the scheduler
166+
# NOTE: we simulate multiple dv-2 replicas by running several times
167+
# the same pipeline scheduling
165168
local_pipelines = deepcopy(scheduler.scheduled_pipelines)
166-
await asyncio.gather(
169+
results = await asyncio.gather(
167170
*(
168171
scheduler._schedule_pipeline( # noqa: SLF001
169172
user_id=user_id,
170173
project_id=project_id,
171174
iteration=iteration,
172175
pipeline_params=params,
173176
)
177+
for _ in range(3)
174178
for (
175179
user_id,
176180
project_id,
177181
iteration,
178182
), params in local_pipelines.items()
179-
)
183+
),
184+
return_exceptions=True,
185+
)
186+
# we should have exceptions 2/3 of the time
187+
could_not_acquire_lock_count = sum(
188+
isinstance(r, CouldNotAcquireLockError) for r in results
180189
)
190+
total_results_count = len(results)
181191

182-
# # NOTE: this simulates having 3 schedulers running in parallel
183-
# await asyncio.gather(
184-
# scheduler.schedule_all_pipelines(),
185-
# scheduler.schedule_all_pipelines(),
186-
# scheduler.schedule_all_pipelines(),
187-
# )
192+
# Check if 2/3 of the results are CouldNotAcquireLockError
193+
assert could_not_acquire_lock_count == (2 / 3) * total_results_count
188194

189195

190196
@pytest.fixture

0 commit comments

Comments
 (0)