|
45 | 45 | from pytest_mock.plugin import MockerFixture |
46 | 46 | from pytest_simcore.helpers.typing_env import EnvVarsDict |
47 | 47 | from servicelib.rabbitmq import RabbitMQClient |
| 48 | +from servicelib.redis import CouldNotAcquireLockError |
48 | 49 | from settings_library.rabbit import RabbitSettings |
49 | 50 | from settings_library.redis import RedisSettings |
50 | 51 | from simcore_postgres_database.models.comp_runs import comp_runs |
@@ -162,29 +163,34 @@ async def _assert_comp_tasks_db( |
162 | 163 | async def schedule_all_pipelines(scheduler: BaseCompScheduler) -> None: |
163 | 164 | # NOTE: we take a copy of the pipelines, as this could change quickly if there are |
164 | 165 | # 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 |
165 | 168 | local_pipelines = deepcopy(scheduler.scheduled_pipelines) |
166 | | - await asyncio.gather( |
| 169 | + results = await asyncio.gather( |
167 | 170 | *( |
168 | 171 | scheduler._schedule_pipeline( # noqa: SLF001 |
169 | 172 | user_id=user_id, |
170 | 173 | project_id=project_id, |
171 | 174 | iteration=iteration, |
172 | 175 | pipeline_params=params, |
173 | 176 | ) |
| 177 | + for _ in range(3) |
174 | 178 | for ( |
175 | 179 | user_id, |
176 | 180 | project_id, |
177 | 181 | iteration, |
178 | 182 | ), 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 |
180 | 189 | ) |
| 190 | + total_results_count = len(results) |
181 | 191 |
|
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 |
188 | 194 |
|
189 | 195 |
|
190 | 196 | @pytest.fixture |
|
0 commit comments