| 1 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 2 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 3 |
# |
| 4 |
# This program is free software: you can redistribute it and/or modify |
| 5 |
# it under the terms of the GNU General Public License as published by |
| 6 |
# the Free Software Foundation, either version 3 of the License, or |
| 7 |
# (at your option) any later version. |
| 8 |
# |
| 9 |
# This program is distributed in the hope that it will be useful, |
| 10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
# GNU General Public License for more details. |
| 13 |
# |
| 14 |
# You should have received a copy of the GNU General Public License |
| 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 |
|
| 17 |
"""Tests optional output and task completion logic. |
| 18 |
|
| 19 |
This functionality is defined by the "optional-output-extension" proposal: |
| 20 |
|
| 21 |
https://cylc.github.io/cylc-admin/proposal-optional-output-extension.html#proposal |
| 22 |
""" |
| 23 |
|
| 24 |
from itertools import combinations |
| 25 |
from typing import TYPE_CHECKING |
| 26 |
|
| 27 |
import logging |
| 28 |
import pytest |
| 29 |
import itertools |
| 30 |
|
| 31 |
from cylc.flow.commands import ( |
| 32 |
run_cmd, |
| 33 |
force_trigger_tasks |
| 34 |
) |
| 35 |
from cylc.flow.cycling.integer import IntegerPoint |
| 36 |
from cylc.flow.cycling.iso8601 import ISO8601Point |
| 37 |
from cylc.flow.exceptions import WorkflowConfigError |
| 38 |
from cylc.flow.id import TaskTokens, Tokens |
| 39 |
from cylc.flow.network.resolvers import TaskMsg |
| 40 |
from cylc.flow.task_events_mgr import ( |
| 41 |
TaskEventsManager, |
| 42 |
) |
| 43 |
from cylc.flow.task_outputs import ( |
| 44 |
TASK_OUTPUTS, |
| 45 |
TASK_OUTPUT_EXPIRED, |
| 46 |
TASK_OUTPUT_FAILED, |
| 47 |
TASK_OUTPUT_FINISHED, |
| 48 |
TASK_OUTPUT_SUCCEEDED, |
| 49 |
get_completion_expression, |
| 50 |
) |
| 51 |
from cylc.flow.task_state import ( |
| 52 |
TASK_STATUS_EXPIRED, |
| 53 |
TASK_STATUS_PREPARING, |
| 54 |
TASK_STATUS_RUNNING, |
| 55 |
TASK_STATUS_WAITING, |
| 56 |
) |
| 57 |
|
| 58 |
if TYPE_CHECKING: |
| 59 |
from cylc.flow.task_proxy import TaskProxy |
| 60 |
from cylc.flow.scheduler import Scheduler |
| 61 |
|
| 62 |
|
| 63 |
OPT_BOTH_ERR = "Output {} can't be both required and optional" |
| 64 |
|
| 65 |
|
| 66 |
def reset_outputs(itask: 'TaskProxy'): |
| 67 |
"""Undo the consequences of setting task outputs. |
| 68 |
|
| 69 |
This assumes you haven't completed the task. |
| 70 |
""" |
| 71 |
itask.state.outputs._completed = { |
| 72 |
message: False |
| 73 |
for message in itask.state.outputs._completed |
| 74 |
} |
| 75 |
itask.state_reset( |
| 76 |
TASK_STATUS_WAITING, |
| 77 |
is_queued=False, |
| 78 |
is_held=False, |
| 79 |
is_runahead=False, |
| 80 |
) |
| 81 |
|
| 82 |
|
| 83 |
@pytest.mark.parametrize( |
| 84 |
'graph, completion_outputs', |
| 85 |
[ |
| 86 |
pytest.param( |
| 87 |
'a:x', |
| 88 |
[{TASK_OUTPUT_SUCCEEDED, 'x'}], |
| 89 |
id='1', |
| 90 |
), |
| 91 |
pytest.param( |
| 92 |
'a\na:x\na:expired?', |
| 93 |
[{TASK_OUTPUT_SUCCEEDED, 'x'}, {TASK_OUTPUT_EXPIRED}], |
| 94 |
id='2', |
| 95 |
), |
| 96 |
], |
| 97 |
) |
| 98 |
async def test_task_completion( |
| 99 |
flow, |
| 100 |
scheduler, |
| 101 |
start, |
| 102 |
graph, |
| 103 |
completion_outputs, |
| 104 |
capcall, |
| 105 |
): |
| 106 |
"""Ensure that task completion is watertight. |
| 107 |
|
| 108 |
Run through every possible permutation of outputs MINUS the ones that would |
| 109 |
actually complete a task to ensure that task completion is correctly |
| 110 |
handled. |
| 111 |
|
| 112 |
Note, the building and evaluation of completion expressions is also tested, |
| 113 |
this is more of an end-to-end test to ensure everything is connected |
| 114 |
properly. |
| 115 |
""" |
| 116 |
# prevent tasks from being removed from the pool when complete |
| 117 |
capcall( |
| 118 |
'cylc.flow.task_pool.TaskPool.remove_if_complete' |
| 119 |
) |
| 120 |
id_ = flow({ |
| 121 |
'scheduling': { |
| 122 |
'graph': {'R1': graph}, |
| 123 |
}, |
| 124 |
'runtime': { |
| 125 |
'a': { |
| 126 |
'outputs': { |
| 127 |
'x': 'xxx', |
| 128 |
}, |
| 129 |
}, |
| 130 |
}, |
| 131 |
}) |
| 132 |
schd = scheduler(id_) |
| 133 |
all_outputs = { |
| 134 |
# all built-in outputs |
| 135 |
*TASK_OUTPUTS, |
| 136 |
# all registered custom outputs |
| 137 |
'x' |
| 138 |
# but not the finished psudo output |
| 139 |
} - {TASK_OUTPUT_FINISHED} |
| 140 |
|
| 141 |
async with start(schd): |
| 142 |
a1 = schd.pool.get_task(IntegerPoint('1'), 'a') |
| 143 |
|
| 144 |
# try every set of outputs that *shouldn't* complete the task |
| 145 |
for combination in { |
| 146 |
comb |
| 147 |
# every possible combination of outputs |
| 148 |
for _length in range(1, len(all_outputs)) |
| 149 |
for comb in combinations(all_outputs, _length) |
| 150 |
# that doesn't contain the outputs that would satisfy the task |
| 151 |
if not any( |
| 152 |
set(comb) & output_set == output_set |
| 153 |
for output_set in completion_outputs |
| 154 |
) |
| 155 |
}: |
| 156 |
# set the combination of outputs |
| 157 |
schd.pool.set_prereqs_and_outputs( |
| 158 |
{TaskTokens('1', 'a')}, |
| 159 |
combination, |
| 160 |
[], |
| 161 |
['1'], |
| 162 |
) |
| 163 |
|
| 164 |
# ensure these outputs do *not* complete the task |
| 165 |
assert not a1.state.outputs.is_complete() |
| 166 |
|
| 167 |
# reset any changes |
| 168 |
reset_outputs(a1) |
| 169 |
|
| 170 |
# now try the outputs that *should* satisfy the task |
| 171 |
for combination in completion_outputs: |
| 172 |
# set the combination of outputs |
| 173 |
schd.pool.set_prereqs_and_outputs( |
| 174 |
{TaskTokens('1', 'a')}, |
| 175 |
combination, |
| 176 |
[], |
| 177 |
['1'], |
| 178 |
) |
| 179 |
|
| 180 |
# ensure the task *is* completed |
| 181 |
assert a1.state.outputs.is_complete() |
| 182 |
|
| 183 |
# reset any changes |
| 184 |
reset_outputs(a1) |
| 185 |
|
| 186 |
|
| 187 |
async def test_expire_orthogonality(flow, scheduler, start): |
| 188 |
"""Ensure "expired?" does not infer "succeeded?". |
| 189 |
|
| 190 |
Asserts proposal point 2: |
| 191 |
https://cylc.github.io/cylc-admin/proposal-optional-output-extension.html#proposal |
| 192 |
""" |
| 193 |
id_ = flow({ |
| 194 |
'scheduling': { |
| 195 |
'graph': { |
| 196 |
'R1': 'a:expire? => e' |
| 197 |
}, |
| 198 |
}, |
| 199 |
}) |
| 200 |
schd: 'Scheduler' = scheduler(id_, paused_start=False) |
| 201 |
async with start(schd): |
| 202 |
a_1 = schd.pool.get_task(IntegerPoint('1'), 'a') |
| 203 |
|
| 204 |
# wait for the task to submit |
| 205 |
while not a_1.state(TASK_STATUS_WAITING, TASK_STATUS_PREPARING): |
| 206 |
schd.release_tasks_to_run() |
| 207 |
|
| 208 |
# NOTE: The submit number isn't presently incremented via this code |
| 209 |
# pathway so we have to hack it here. If the task messages in this test |
| 210 |
# get ignored because of some future change, then you can safely remove |
| 211 |
# this line (it's not what this test is testing). |
| 212 |
a_1.submit_num += 1 |
| 213 |
|
| 214 |
# tell the scheduler that the task *submit-failed* |
| 215 |
schd.message_queue.put( |
| 216 |
TaskMsg( |
| 217 |
Tokens('//1/a/01'), |
| 218 |
'2000-01-01T00:00:00+00', |
| 219 |
'INFO', |
| 220 |
TaskEventsManager.EVENT_SUBMIT_FAILED |
| 221 |
), |
| 222 |
) |
| 223 |
schd.process_queued_task_messages() |
| 224 |
# ensure that the scheduler is stalled |
| 225 |
assert not a_1.state.outputs.is_complete() |
| 226 |
assert schd.pool.is_stalled() |
| 227 |
|
| 228 |
# tell the scheduler that the task *failed* |
| 229 |
schd.message_queue.put( |
| 230 |
TaskMsg( |
| 231 |
Tokens('//1/a/01'), |
| 232 |
'2000-01-01T00:00:00+00', |
| 233 |
'INFO', |
| 234 |
TaskEventsManager.EVENT_FAILED, |
| 235 |
), |
| 236 |
) |
| 237 |
schd.process_queued_task_messages() |
| 238 |
# ensure that the scheduler is stalled |
| 239 |
assert not a_1.state.outputs.is_complete() |
| 240 |
assert schd.pool.is_stalled() |
| 241 |
|
| 242 |
# tell the scheduler that the task *expired* |
| 243 |
schd.message_queue.put( |
| 244 |
TaskMsg( |
| 245 |
Tokens('//1/a/01'), |
| 246 |
'2000-01-01T00:00:00+00', |
| 247 |
'INFO', |
| 248 |
TaskEventsManager.EVENT_EXPIRED, |
| 249 |
), |
| 250 |
) |
| 251 |
schd.process_queued_task_messages() |
| 252 |
# ensure that the scheduler is *not* stalled |
| 253 |
assert a_1.state.outputs.is_complete() |
| 254 |
assert not schd.pool.is_stalled() |
| 255 |
|
| 256 |
|
| 257 |
@pytest.fixture(scope='module') |
| 258 |
def implicit_completion_config(mod_flow, mod_validate): |
| 259 |
id_ = mod_flow({ |
| 260 |
'scheduling': { |
| 261 |
'graph': { |
| 262 |
'R1': ''' |
| 263 |
a |
| 264 |
|
| 265 |
b? |
| 266 |
|
| 267 |
c:x |
| 268 |
|
| 269 |
d:x? |
| 270 |
d:y? |
| 271 |
d:z? |
| 272 |
|
| 273 |
e:x |
| 274 |
e:y |
| 275 |
e:z |
| 276 |
|
| 277 |
f? |
| 278 |
f:x |
| 279 |
|
| 280 |
g:expired? |
| 281 |
|
| 282 |
h:succeeded? |
| 283 |
h:expired? |
| 284 |
|
| 285 |
i:expired? |
| 286 |
i:submitted |
| 287 |
|
| 288 |
j:expired? |
| 289 |
j:submitted? |
| 290 |
|
| 291 |
k:submit-failed? |
| 292 |
k:succeeded? |
| 293 |
|
| 294 |
l:expired? |
| 295 |
l:submit-failed? |
| 296 |
l:succeeded? |
| 297 |
''' |
| 298 |
} |
| 299 |
}, |
| 300 |
'runtime': { |
| 301 |
'root': { |
| 302 |
'outputs': {x: f'{x * 3}' for x in 'abcdefghijklxyz'} |
| 303 |
} |
| 304 |
} |
| 305 |
}) |
| 306 |
return mod_validate(id_) |
| 307 |
|
| 308 |
|
| 309 |
@pytest.mark.parametrize( |
| 310 |
'task, condition', |
| 311 |
[ |
| 312 |
pytest.param('a', 'succeeded', id='a'), |
| 313 |
pytest.param('b', 'succeeded or failed', id='b'), |
| 314 |
pytest.param('c', '(succeeded and x)', id='c'), |
| 315 |
pytest.param('d', 'succeeded', id='d'), |
| 316 |
pytest.param('e', '(succeeded and x and y and z)', id='e'), |
| 317 |
pytest.param('f', '(x and succeeded) or failed', id='f'), |
| 318 |
pytest.param('g', 'succeeded or expired', id='h'), |
| 319 |
pytest.param('h', 'succeeded or failed or expired', id='h'), |
| 320 |
pytest.param('i', '(submitted and succeeded) or expired', id='i'), |
| 321 |
pytest.param('j', 'succeeded or submit_failed or expired', id='j'), |
| 322 |
pytest.param('k', 'succeeded or failed or submit_failed', id='k'), |
| 323 |
pytest.param( |
| 324 |
'l', 'succeeded or failed or submit_failed or expired', id='l' |
| 325 |
), |
| 326 |
], |
| 327 |
) |
| 328 |
async def test_implicit_completion_expression( |
| 329 |
implicit_completion_config, |
| 330 |
task, |
| 331 |
condition, |
| 332 |
): |
| 333 |
"""It should generate a completion expression from the graph. |
| 334 |
|
| 335 |
If no completion expression is provided in the runtime section, then it |
| 336 |
should auto generate one inferring whether outputs are required or not from |
| 337 |
the graph. |
| 338 |
""" |
| 339 |
completion_expression = get_completion_expression( |
| 340 |
implicit_completion_config.taskdefs[task] |
| 341 |
) |
| 342 |
assert completion_expression == condition |
| 343 |
|
| 344 |
|
| 345 |
async def test_clock_expire_partially_satisfied_task( |
| 346 |
flow, |
| 347 |
scheduler, |
| 348 |
start, |
| 349 |
): |
| 350 |
"""Clock expire should take effect on a partially satisfied task. |
| 351 |
|
| 352 |
Tests proposal point 8: |
| 353 |
https://cylc.github.io/cylc-admin/proposal-optional-output-extension.html#proposal |
| 354 |
""" |
| 355 |
id_ = flow({ |
| 356 |
'scheduling': { |
| 357 |
'initial cycle point': '2000', |
| 358 |
'runahead limit': 'P0', |
| 359 |
'special tasks': { |
| 360 |
'clock-expire': 'e', |
| 361 |
}, |
| 362 |
'graph': { |
| 363 |
'P1D': ''' |
| 364 |
# this prerequisite we will satisfy |
| 365 |
a => e |
| 366 |
|
| 367 |
# this prerequisite we will leave unsatisfied creating a |
| 368 |
# partially-satisfied task |
| 369 |
b => e |
| 370 |
''' |
| 371 |
}, |
| 372 |
}, |
| 373 |
}) |
| 374 |
schd = scheduler(id_) |
| 375 |
async with start(schd): |
| 376 |
# satisfy one of the prerequisites |
| 377 |
a = schd.pool.get_task(ISO8601Point('20000101T0000Z'), 'a') |
| 378 |
assert a |
| 379 |
schd.pool.spawn_on_output(a, TASK_OUTPUT_SUCCEEDED) |
| 380 |
|
| 381 |
# the task "e" should now be spawned |
| 382 |
e = schd.pool.get_task(ISO8601Point('20000101T0000Z'), 'e') |
| 383 |
assert e |
| 384 |
|
| 385 |
# check for clock-expired tasks |
| 386 |
schd.pool.clock_expire_tasks() |
| 387 |
|
| 388 |
# the task should now be in the expired state |
| 389 |
assert e.state(TASK_STATUS_EXPIRED) |
| 390 |
|
| 391 |
|
| 392 |
async def test_clock_expiry( |
| 393 |
flow, |
| 394 |
scheduler, |
| 395 |
start, |
| 396 |
): |
| 397 |
"""Waiting tasks should be considered for clock-expiry. |
| 398 |
|
| 399 |
Tests two things: |
| 400 |
|
| 401 |
* Manually triggered tasks should not be considered for clock-expiry. |
| 402 |
|
| 403 |
Tests proposal point 10: |
| 404 |
https://cylc.github.io/cylc-admin/proposal-optional-output-extension.html#proposal |
| 405 |
|
| 406 |
* Active tasks should not be considered for clock-expiry. |
| 407 |
|
| 408 |
Closes https://github.com/cylc/cylc-flow/issues/6025 |
| 409 |
""" |
| 410 |
id_ = flow({ |
| 411 |
'scheduling': { |
| 412 |
'initial cycle point': '2000', |
| 413 |
'runahead limit': 'P1', |
| 414 |
'special tasks': { |
| 415 |
'clock-expire': 'x' |
| 416 |
}, |
| 417 |
'graph': { |
| 418 |
'P1Y': 'x' |
| 419 |
}, |
| 420 |
}, |
| 421 |
}) |
| 422 |
schd = scheduler(id_) |
| 423 |
async with start(schd): |
| 424 |
# the first task (waiting) |
| 425 |
one = schd.pool.get_task(ISO8601Point('20000101T0000Z'), 'x') |
| 426 |
assert one |
| 427 |
|
| 428 |
# the second task (preparing) |
| 429 |
two = schd.pool.get_task(ISO8601Point('20010101T0000Z'), 'x') |
| 430 |
assert two |
| 431 |
two.state_reset(TASK_STATUS_PREPARING) |
| 432 |
|
| 433 |
# the third task (force-triggered) |
| 434 |
await run_cmd(force_trigger_tasks(schd, ['20100101T0000Z/x'], ['1'])) |
| 435 |
three = schd.pool.get_task(ISO8601Point('20100101T0000Z'), 'x') |
| 436 |
assert three |
| 437 |
|
| 438 |
# check for expiry |
| 439 |
schd.pool.clock_expire_tasks() |
| 440 |
|
| 441 |
# the first task should be expired (it was waiting) |
| 442 |
assert one.state(TASK_STATUS_EXPIRED) |
| 443 |
assert one.state.outputs.is_message_complete(TASK_OUTPUT_EXPIRED) |
| 444 |
|
| 445 |
# the second task should *not* be expired (it was active) |
| 446 |
assert not two.state(TASK_STATUS_EXPIRED) |
| 447 |
assert not two.state.outputs.is_message_complete(TASK_OUTPUT_EXPIRED) |
| 448 |
|
| 449 |
# the third task should *not* be expired (it was a manual submit) |
| 450 |
assert not three.state(TASK_STATUS_EXPIRED) |
| 451 |
assert not three.state.outputs.is_message_complete(TASK_OUTPUT_EXPIRED) |
| 452 |
|
| 453 |
|
| 454 |
async def test_removed_taskdef( |
| 455 |
flow, |
| 456 |
scheduler, |
| 457 |
start, |
| 458 |
): |
| 459 |
"""It should handle tasks being removed from the config. |
| 460 |
|
| 461 |
If the config of an active task is removed from the config by restart / |
| 462 |
reload, then we must provide a fallback completion expression, otherwise |
| 463 |
the expression will be blank (task has no required or optional outputs). |
| 464 |
|
| 465 |
The fallback is to consider the outputs complete if *any* final output is |
| 466 |
received. Since the task has been removed from the workflow its outputs |
| 467 |
should be inconsequential. |
| 468 |
|
| 469 |
See: https://github.com/cylc/cylc-flow/issues/5057 |
| 470 |
""" |
| 471 |
id_ = flow({ |
| 472 |
'scheduling': { |
| 473 |
'graph': { |
| 474 |
'R1': 'a & z' |
| 475 |
} |
| 476 |
} |
| 477 |
}) |
| 478 |
|
| 479 |
# start the workflow and mark the tasks as running |
| 480 |
schd: 'Scheduler' = scheduler(id_) |
| 481 |
async with start(schd): |
| 482 |
for itask in schd.pool.get_tasks(): |
| 483 |
itask.state_reset(TASK_STATUS_RUNNING) |
| 484 |
assert itask.state.outputs._completion_expression == 'succeeded' |
| 485 |
|
| 486 |
# remove the task "z" from the config |
| 487 |
id_ = flow({ |
| 488 |
'scheduling': { |
| 489 |
'graph': { |
| 490 |
'R1': 'a' |
| 491 |
} |
| 492 |
} |
| 493 |
}, workflow_id=id_) |
| 494 |
|
| 495 |
# restart the workflow |
| 496 |
schd: 'Scheduler' = scheduler(id_) |
| 497 |
async with start(schd): |
| 498 |
# 1/a: |
| 499 |
# * is still in the config |
| 500 |
# * is should still have a sensible completion expression |
| 501 |
# * its outputs should be incomplete if the task fails |
| 502 |
a_1 = schd.pool.get_task(IntegerPoint('1'), 'a') |
| 503 |
assert a_1 |
| 504 |
assert a_1.state.outputs._completion_expression == 'succeeded' |
| 505 |
a_1.state.outputs.set_message_complete(TASK_OUTPUT_FAILED) |
| 506 |
assert not a_1.is_complete() |
| 507 |
|
| 508 |
# 1/z: |
| 509 |
# * is no longer in the config |
| 510 |
# * should have a blank completion expression |
| 511 |
# * its outputs should be completed by any final output |
| 512 |
z_1 = schd.pool.get_task(IntegerPoint('1'), 'z') |
| 513 |
assert z_1 |
| 514 |
assert z_1.state.outputs._completion_expression == '' |
| 515 |
z_1.state.outputs.set_message_complete(TASK_OUTPUT_FAILED) |
| 516 |
assert z_1.is_complete() |
| 517 |
|
| 518 |
|
| 519 |
@pytest.mark.parametrize( |
| 520 |
'graph, err', |
| 521 |
[ |
| 522 |
pytest.param( |
| 523 |
""" |
| 524 |
a |
| 525 |
a? |
| 526 |
""", |
| 527 |
OPT_BOTH_ERR.format("a:succeeded"), |
| 528 |
), |
| 529 |
pytest.param( |
| 530 |
""" |
| 531 |
a => b |
| 532 |
a? |
| 533 |
""", |
| 534 |
OPT_BOTH_ERR.format("a:succeeded"), |
| 535 |
), |
| 536 |
pytest.param( |
| 537 |
""" |
| 538 |
a? => b |
| 539 |
a |
| 540 |
""", |
| 541 |
OPT_BOTH_ERR.format("a:succeeded"), |
| 542 |
), |
| 543 |
pytest.param( |
| 544 |
""" |
| 545 |
a => b? |
| 546 |
b |
| 547 |
""", |
| 548 |
OPT_BOTH_ERR.format("b:succeeded"), |
| 549 |
), |
| 550 |
pytest.param( |
| 551 |
""" |
| 552 |
a => b:succeeded |
| 553 |
b? |
| 554 |
""", |
| 555 |
OPT_BOTH_ERR.format("b:succeeded"), |
| 556 |
), |
| 557 |
pytest.param( |
| 558 |
""" |
| 559 |
a => b:succeeded |
| 560 |
c => b? |
| 561 |
""", |
| 562 |
OPT_BOTH_ERR.format("b:succeeded"), |
| 563 |
), |
| 564 |
pytest.param( |
| 565 |
""" |
| 566 |
c:x => d |
| 567 |
a => c:x? |
| 568 |
""", |
| 569 |
OPT_BOTH_ERR.format("c:x"), |
| 570 |
), |
| 571 |
pytest.param( |
| 572 |
""" |
| 573 |
c:x? => d |
| 574 |
a => c:x |
| 575 |
""", |
| 576 |
OPT_BOTH_ERR.format("c:x"), |
| 577 |
), |
| 578 |
pytest.param( |
| 579 |
""" |
| 580 |
FAM:finish-all? |
| 581 |
""", |
| 582 |
"Family pseudo-output FAM:finish-all can't be optional", |
| 583 |
), |
| 584 |
pytest.param( |
| 585 |
""" |
| 586 |
a => b => c |
| 587 |
b? |
| 588 |
""", |
| 589 |
OPT_BOTH_ERR.format("b:succeeded"), |
| 590 |
), |
| 591 |
pytest.param( |
| 592 |
""" |
| 593 |
a => FAM => c |
| 594 |
""", |
| 595 |
"Family trigger required: FAM => c", |
| 596 |
), |
| 597 |
], |
| 598 |
ids=itertools.count() |
| 599 |
) |
| 600 |
async def test_optional_outputs_consistency(flow, validate, graph, err): |
| 601 |
"""Check that inconsistent output optionality fails validation.""" |
| 602 |
id_ = flow( |
| 603 |
{ |
| 604 |
'scheduling': { |
| 605 |
'graph': { |
| 606 |
'R1': graph |
| 607 |
}, |
| 608 |
}, |
| 609 |
'runtime': { |
| 610 |
'FAM': {}, |
| 611 |
'm1, m2': { |
| 612 |
'inherit': 'FAM', |
| 613 |
}, |
| 614 |
'c': { |
| 615 |
'outputs': { |
| 616 |
'x': 'x', |
| 617 |
}, |
| 618 |
}, |
| 619 |
}, |
| 620 |
}, |
| 621 |
) |
| 622 |
with pytest.raises(WorkflowConfigError) as exc_ctx: |
| 623 |
validate(id_) |
| 624 |
assert err in str(exc_ctx.value) |
| 625 |
|
| 626 |
|
| 627 |
@pytest.mark.parametrize( |
| 628 |
'graph, expected', |
| 629 |
[ |
| 630 |
pytest.param( |
| 631 |
"a => b", |
| 632 |
{ |
| 633 |
("a", "succeeded"): True, # inferred |
| 634 |
("b", "succeeded"): True, # default |
| 635 |
("a", "failed"): None, # (not set) |
| 636 |
("b", "failed"): None, # (not set) |
| 637 |
}, |
| 638 |
), |
| 639 |
pytest.param( |
| 640 |
""" |
| 641 |
a => b |
| 642 |
b? |
| 643 |
""", |
| 644 |
{ |
| 645 |
("a", "succeeded"): True, # inferred |
| 646 |
("b", "succeeded"): False, # inferred |
| 647 |
("b", "failed"): None, # (not set) |
| 648 |
}, |
| 649 |
), |
| 650 |
pytest.param( |
| 651 |
""" |
| 652 |
a:failed => b |
| 653 |
""", |
| 654 |
{ |
| 655 |
("a", "failed"): True, |
| 656 |
("b", "succeeded"): True, |
| 657 |
("a", "succeeded"): None, |
| 658 |
("b", "failed"): None, |
| 659 |
}, |
| 660 |
), |
| 661 |
pytest.param( |
| 662 |
""" |
| 663 |
a => b |
| 664 |
b |
| 665 |
""", |
| 666 |
{ |
| 667 |
("a", "succeeded"): True, |
| 668 |
("b", "succeeded"): True, |
| 669 |
}, |
| 670 |
), |
| 671 |
pytest.param( |
| 672 |
""" |
| 673 |
a => b |
| 674 |
b? |
| 675 |
""", |
| 676 |
{ |
| 677 |
("a", "succeeded"): True, |
| 678 |
("b", "succeeded"): False, |
| 679 |
}, |
| 680 |
), |
| 681 |
pytest.param( |
| 682 |
""" |
| 683 |
a? => b |
| 684 |
""", |
| 685 |
{ |
| 686 |
("a", "succeeded"): False, |
| 687 |
("b", "succeeded"): True, |
| 688 |
}, |
| 689 |
), |
| 690 |
pytest.param( |
| 691 |
""" |
| 692 |
a? => b |
| 693 |
b? |
| 694 |
""", |
| 695 |
{ |
| 696 |
("a", "succeeded"): False, |
| 697 |
("b", "succeeded"): False, |
| 698 |
}, |
| 699 |
), |
| 700 |
pytest.param( |
| 701 |
""" |
| 702 |
a? => b? |
| 703 |
""", |
| 704 |
{ |
| 705 |
("a", "succeeded"): False, |
| 706 |
("b", "succeeded"): False, |
| 707 |
}, |
| 708 |
), |
| 709 |
pytest.param( |
| 710 |
""" |
| 711 |
FAM |
| 712 |
""", |
| 713 |
{ |
| 714 |
("m1", "succeeded"): True, # family default |
| 715 |
("m2", "succeeded"): True, # family default |
| 716 |
}, |
| 717 |
), |
| 718 |
pytest.param( |
| 719 |
""" |
| 720 |
FAM:succeed-all? |
| 721 |
""", |
| 722 |
{ |
| 723 |
("m1", "succeeded"): False, # family default |
| 724 |
("m2", "succeeded"): False, # family default |
| 725 |
}, |
| 726 |
), |
| 727 |
pytest.param( |
| 728 |
""" |
| 729 |
FAM |
| 730 |
m1? |
| 731 |
""", |
| 732 |
{ |
| 733 |
("m1", "succeeded"): False, # inferred |
| 734 |
("m2", "succeeded"): True, # family default |
| 735 |
}, |
| 736 |
), |
| 737 |
pytest.param( |
| 738 |
""" |
| 739 |
a => FAM |
| 740 |
""", |
| 741 |
{ |
| 742 |
("a", "succeeded"): True, # inferred |
| 743 |
("m1", "succeeded"): True, # default |
| 744 |
("m2", "succeeded"): True, # default |
| 745 |
}, |
| 746 |
), |
| 747 |
pytest.param( |
| 748 |
""" |
| 749 |
a => FAM |
| 750 |
m2? |
| 751 |
""", |
| 752 |
{ |
| 753 |
("a", "succeeded"): True, # inferred |
| 754 |
("m1", "succeeded"): True, # default |
| 755 |
("m2", "succeeded"): False, # explicit "?" |
| 756 |
}, |
| 757 |
), |
| 758 |
pytest.param( |
| 759 |
""" |
| 760 |
a => FAM:finish-all |
| 761 |
""", |
| 762 |
{ |
| 763 |
("a", "succeeded"): True, # inferred |
| 764 |
("m1", "succeeded"): False, # family default |
| 765 |
("m2", "succeeded"): False, # family default |
| 766 |
}, |
| 767 |
), |
| 768 |
pytest.param( |
| 769 |
""" |
| 770 |
FAM:succeed-any => a |
| 771 |
""", |
| 772 |
{ |
| 773 |
("a", "succeeded"): True, # inferred |
| 774 |
("m1", "succeeded"): True, # family default |
| 775 |
("m2", "succeeded"): True, # family default |
| 776 |
}, |
| 777 |
), |
| 778 |
pytest.param( |
| 779 |
""" |
| 780 |
FAM:succeed-any? => a |
| 781 |
""", |
| 782 |
{ |
| 783 |
("a", "succeeded"): True, # inferred |
| 784 |
("m1", "succeeded"): False, # family default |
| 785 |
("m2", "succeeded"): False, # family default |
| 786 |
}, |
| 787 |
), |
| 788 |
pytest.param( |
| 789 |
""" |
| 790 |
FAM:succeed-any => a |
| 791 |
m1? |
| 792 |
""", |
| 793 |
{ |
| 794 |
("a", "succeeded"): True, |
| 795 |
("m1", "succeeded"): False, |
| 796 |
("m2", "succeeded"): True, |
| 797 |
}, |
| 798 |
), |
| 799 |
pytest.param( |
| 800 |
""" |
| 801 |
a & b? => c |
| 802 |
""", |
| 803 |
{ |
| 804 |
("a", "succeeded"): True, # inferred |
| 805 |
("b", "succeeded"): False, # explicit "?" |
| 806 |
("c", "succeeded"): True, # default |
| 807 |
}, |
| 808 |
), |
| 809 |
pytest.param( |
| 810 |
""" |
| 811 |
a => c:x |
| 812 |
""", |
| 813 |
{ |
| 814 |
("a", "succeeded"): True, # inferred |
| 815 |
("c", "succeeded"): True, # default |
| 816 |
("c", "x"): True, # explicit ":x" |
| 817 |
}, |
| 818 |
), |
| 819 |
pytest.param( |
| 820 |
""" |
| 821 |
a => c:x? |
| 822 |
""", |
| 823 |
{ |
| 824 |
("a", "succeeded"): True, # inferred |
| 825 |
("c", "succeeded"): True, # default |
| 826 |
("c", "x"): False, # explicit ":x?" |
| 827 |
}, |
| 828 |
), |
| 829 |
pytest.param( |
| 830 |
""" |
| 831 |
a => b => c # infer :succeeded for b inside chain |
| 832 |
""", |
| 833 |
{ |
| 834 |
("a", "succeeded"): True, # inferred |
| 835 |
("b", "succeeded"): True, # inferred |
| 836 |
("c", "succeeded"): True, # default |
| 837 |
}, |
| 838 |
), |
| 839 |
pytest.param( |
| 840 |
# Check we don't infer c:succeeded at end-of-chain |
| 841 |
# when there's an & at the end. |
| 842 |
""" |
| 843 |
a => b & c |
| 844 |
c? |
| 845 |
""", |
| 846 |
{ |
| 847 |
("a", "succeeded"): True, # inferred |
| 848 |
("b", "succeeded"): True, # default |
| 849 |
("c", "succeeded"): False, # inferred |
| 850 |
}, |
| 851 |
), |
| 852 |
], |
| 853 |
ids=itertools.count() |
| 854 |
) |
| 855 |
async def test_optional_outputs_inference( |
| 856 |
flow, validate, graph, expected |
| 857 |
): |
| 858 |
"""Check task output optionality after graph parsing. |
| 859 |
|
| 860 |
This checks taskdef.outputs, which holds inferred and default values. |
| 861 |
|
| 862 |
""" |
| 863 |
id = flow( |
| 864 |
{ |
| 865 |
'scheduling': { |
| 866 |
'graph': { |
| 867 |
'R1': graph |
| 868 |
}, |
| 869 |
}, |
| 870 |
'runtime': { |
| 871 |
'FAM': {}, |
| 872 |
'm1, m2': { |
| 873 |
'inherit': 'FAM', |
| 874 |
}, |
| 875 |
'c': { |
| 876 |
'outputs': { |
| 877 |
'x': 'x', |
| 878 |
}, |
| 879 |
}, |
| 880 |
}, |
| 881 |
} |
| 882 |
) |
| 883 |
|
| 884 |
config = validate(id) |
| 885 |
for (task, output), exp in expected.items(): |
| 886 |
tdef = config.get_taskdef(task) |
| 887 |
(_, required) = tdef.outputs[output] |
| 888 |
assert required == exp |
| 889 |
|
| 890 |
|
| 891 |
async def test_log_outputs(flow, validate, caplog, monkeypatch): |
| 892 |
"""Test logging of optional and required outputs inferred from the graph. |
| 893 |
|
| 894 |
This probes output optionality inferred by the graph parser, so it does |
| 895 |
not include RHS-only tasks that just default to :succeeded required. |
| 896 |
|
| 897 |
""" |
| 898 |
id = flow( |
| 899 |
{ |
| 900 |
'scheduling': { |
| 901 |
'graph': { |
| 902 |
'R1': """ |
| 903 |
# (b:succeeded required by default, not by inference) |
| 904 |
a? => FAM:succeed-all? => b |
| 905 |
m1 |
| 906 |
a? => c:x? |
| 907 |
a? => c:y |
| 908 |
""", |
| 909 |
}, |
| 910 |
}, |
| 911 |
'runtime': { |
| 912 |
'FAM': {}, |
| 913 |
'm1, m2': { |
| 914 |
'inherit': 'FAM', |
| 915 |
}, |
| 916 |
'c': { |
| 917 |
"outputs": { |
| 918 |
"x": "x", |
| 919 |
"y": "y" |
| 920 |
} |
| 921 |
} |
| 922 |
} |
| 923 |
} |
| 924 |
) |
| 925 |
|
| 926 |
monkeypatch.setattr('cylc.flow.flags.verbosity', 2) |
| 927 |
|
| 928 |
caplog.set_level(logging.DEBUG) |
| 929 |
validate(id) |
| 930 |
|
| 931 |
found_opt = False |
| 932 |
found_req = False |
| 933 |
|
| 934 |
for record in caplog.records: |
| 935 |
msg = record.message |
| 936 |
if "Optional outputs inferred from the graph:" in msg: |
| 937 |
found_opt = True |
| 938 |
for output in ["a:succeeded", "m2:succeeded", "c:x"]: |
| 939 |
assert output in msg |
| 940 |
for output in [ |
| 941 |
"b:succeeded", "m1:succeeded", "c:y", "c:succeeded" |
| 942 |
]: |
| 943 |
assert output not in msg |
| 944 |
elif "Required outputs inferred from the graph:" in msg: |
| 945 |
found_req = True |
| 946 |
for output in ["m1:succeeded", "c:y"]: |
| 947 |
assert output in msg |
| 948 |
for output in [ |
| 949 |
"m2:succeeded", "b:succeeded", "a:succeeded", "c:x", |
| 950 |
"c:succeeded" |
| 951 |
]: |
| 952 |
assert output not in msg |
| 953 |
|
| 954 |
assert found_opt |
| 955 |
assert found_req |