|
13 | 13 | from faker import Faker |
14 | 14 | from models_library.clusters import DEFAULT_CLUSTER_ID, Cluster |
15 | 15 | from models_library.projects import ProjectID |
| 16 | +from models_library.projects_state import RunningState |
16 | 17 | from models_library.users import UserID |
17 | 18 | from simcore_service_director_v2.core.errors import ( |
18 | 19 | ClusterNotFoundError, |
@@ -197,21 +198,149 @@ async def test_update( |
197 | 198 | assert updated.scheduled is not None |
198 | 199 |
|
199 | 200 |
|
200 | | -async def test_delete(aiopg_engine): |
201 | | - ... |
| 201 | +async def test_set_run_result( |
| 202 | + aiopg_engine, |
| 203 | + run_metadata: RunMetadataDict, |
| 204 | + faker: Faker, |
| 205 | + publish_project: Callable[[], Awaitable[PublishedProject]], |
| 206 | +): |
| 207 | + published_project = await publish_project() |
| 208 | + created = await CompRunsRepository(aiopg_engine).create( |
| 209 | + user_id=published_project.user["id"], |
| 210 | + project_id=published_project.project.uuid, |
| 211 | + cluster_id=DEFAULT_CLUSTER_ID, |
| 212 | + iteration=None, |
| 213 | + metadata=run_metadata, |
| 214 | + use_on_demand_clusters=faker.pybool(), |
| 215 | + ) |
| 216 | + got = await CompRunsRepository(aiopg_engine).get( |
| 217 | + user_id=published_project.user["id"], |
| 218 | + project_id=published_project.project.uuid, |
| 219 | + ) |
| 220 | + assert created == got |
| 221 | + assert created.result is not RunningState.PENDING |
| 222 | + assert created.ended is None |
| 223 | + |
| 224 | + updated = await CompRunsRepository(aiopg_engine).set_run_result( |
| 225 | + user_id=created.user_id, |
| 226 | + project_id=created.project_uuid, |
| 227 | + iteration=created.iteration, |
| 228 | + result_state=RunningState.PENDING, |
| 229 | + final_state=False, |
| 230 | + ) |
| 231 | + assert updated |
| 232 | + assert updated != created |
| 233 | + assert updated.result is RunningState.PENDING |
| 234 | + assert updated.ended is None |
| 235 | + |
| 236 | + final_updated = await CompRunsRepository(aiopg_engine).set_run_result( |
| 237 | + user_id=created.user_id, |
| 238 | + project_id=created.project_uuid, |
| 239 | + iteration=created.iteration, |
| 240 | + result_state=RunningState.ABORTED, |
| 241 | + final_state=True, |
| 242 | + ) |
| 243 | + assert final_updated |
| 244 | + assert final_updated != updated |
| 245 | + assert final_updated.result is RunningState.ABORTED |
| 246 | + assert final_updated.ended is not None |
202 | 247 |
|
203 | 248 |
|
204 | | -async def test_set_run_result(aiopg_engine): |
205 | | - ... |
| 249 | +async def test_mark_for_cancellation( |
| 250 | + aiopg_engine, |
| 251 | + run_metadata: RunMetadataDict, |
| 252 | + faker: Faker, |
| 253 | + publish_project: Callable[[], Awaitable[PublishedProject]], |
| 254 | +): |
| 255 | + published_project = await publish_project() |
| 256 | + created = await CompRunsRepository(aiopg_engine).create( |
| 257 | + user_id=published_project.user["id"], |
| 258 | + project_id=published_project.project.uuid, |
| 259 | + cluster_id=DEFAULT_CLUSTER_ID, |
| 260 | + iteration=None, |
| 261 | + metadata=run_metadata, |
| 262 | + use_on_demand_clusters=faker.pybool(), |
| 263 | + ) |
| 264 | + got = await CompRunsRepository(aiopg_engine).get( |
| 265 | + user_id=published_project.user["id"], |
| 266 | + project_id=published_project.project.uuid, |
| 267 | + ) |
| 268 | + assert created == got |
| 269 | + assert created.cancelled is None |
206 | 270 |
|
| 271 | + updated = await CompRunsRepository(aiopg_engine).mark_for_cancellation( |
| 272 | + user_id=created.user_id, |
| 273 | + project_id=created.project_uuid, |
| 274 | + iteration=created.iteration, |
| 275 | + ) |
| 276 | + assert updated |
| 277 | + assert updated != created |
| 278 | + assert updated.cancelled is not None |
207 | 279 |
|
208 | | -async def test_mark_for_cancellation(aiopg_engine): |
209 | | - ... |
210 | 280 |
|
| 281 | +async def test_mark_for_scheduling( |
| 282 | + aiopg_engine, |
| 283 | + run_metadata: RunMetadataDict, |
| 284 | + faker: Faker, |
| 285 | + publish_project: Callable[[], Awaitable[PublishedProject]], |
| 286 | +): |
| 287 | + published_project = await publish_project() |
| 288 | + created = await CompRunsRepository(aiopg_engine).create( |
| 289 | + user_id=published_project.user["id"], |
| 290 | + project_id=published_project.project.uuid, |
| 291 | + cluster_id=DEFAULT_CLUSTER_ID, |
| 292 | + iteration=None, |
| 293 | + metadata=run_metadata, |
| 294 | + use_on_demand_clusters=faker.pybool(), |
| 295 | + ) |
| 296 | + got = await CompRunsRepository(aiopg_engine).get( |
| 297 | + user_id=published_project.user["id"], |
| 298 | + project_id=published_project.project.uuid, |
| 299 | + ) |
| 300 | + assert created == got |
| 301 | + assert created.scheduled is None |
| 302 | + assert created.processed is None |
| 303 | + |
| 304 | + updated = await CompRunsRepository(aiopg_engine).mark_for_scheduling( |
| 305 | + user_id=created.user_id, |
| 306 | + project_id=created.project_uuid, |
| 307 | + iteration=created.iteration, |
| 308 | + ) |
| 309 | + assert updated |
| 310 | + assert updated != created |
| 311 | + assert updated.scheduled is not None |
| 312 | + assert updated.processed is None |
211 | 313 |
|
212 | | -async def test_mark_for_scheduling(aiopg_engine): |
213 | | - ... |
214 | 314 |
|
| 315 | +async def test_mark_scheduling_done( |
| 316 | + aiopg_engine, |
| 317 | + run_metadata: RunMetadataDict, |
| 318 | + faker: Faker, |
| 319 | + publish_project: Callable[[], Awaitable[PublishedProject]], |
| 320 | +): |
| 321 | + published_project = await publish_project() |
| 322 | + created = await CompRunsRepository(aiopg_engine).create( |
| 323 | + user_id=published_project.user["id"], |
| 324 | + project_id=published_project.project.uuid, |
| 325 | + cluster_id=DEFAULT_CLUSTER_ID, |
| 326 | + iteration=None, |
| 327 | + metadata=run_metadata, |
| 328 | + use_on_demand_clusters=faker.pybool(), |
| 329 | + ) |
| 330 | + got = await CompRunsRepository(aiopg_engine).get( |
| 331 | + user_id=published_project.user["id"], |
| 332 | + project_id=published_project.project.uuid, |
| 333 | + ) |
| 334 | + assert created == got |
| 335 | + assert created.scheduled is None |
| 336 | + assert created.processed is None |
215 | 337 |
|
216 | | -async def test_mark_scheduling_done(aiopg_engine): |
217 | | - ... |
| 338 | + updated = await CompRunsRepository(aiopg_engine).mark_scheduling_done( |
| 339 | + user_id=created.user_id, |
| 340 | + project_id=created.project_uuid, |
| 341 | + iteration=created.iteration, |
| 342 | + ) |
| 343 | + assert updated |
| 344 | + assert updated != created |
| 345 | + assert updated.scheduled is None |
| 346 | + assert updated.processed is not None |
0 commit comments