# For this suite to run successfully (exit 0) every operation by perpetrated by
# task perpetrator must complete successfully, so that perpetrator succeeds and
# the suite shuts down cleanly.

[cylc]
    [[events]]
        timeout = PT10S
        abort on timeout = True
[scheduling]
    [[dependencies]]
        graph = victim & perpetrator
[runtime]
    [[victim]]
        script = sleep 600
    [[perpetrator]]
        # Mess with victim.
        script = """
WAIT_A_BIT="--max-polls=5 --interval=2"
sleep 2
# Check victim is running (or fail).
cylc suite-state -t victim -p 1 --status=running $WAIT_A_BIT $CYLC_SUITE_NAME
# Force state to succeeded.
cylc reset --state=succeeded $CYLC_SUITE_NAME victim.1
# Check state is succeeded (or fail).
cylc suite-state -t victim -p 1 --status=succeeded $WAIT_A_BIT $CYLC_SUITE_NAME
# A poll should find that victim is really still running.
cylc poll -s $CYLC_SUITE_NAME victim.1
# Check the poll result (or fail).
cylc suite-state -t victim -p 1 --status=running $WAIT_A_BIT $CYLC_SUITE_NAME
# Kill victim now.
cylc kill $CYLC_SUITE_NAME victim.1
# Check victim is stone cold dead (or fail). 
cylc suite-state -t victim -p 1 --status=failed $WAIT_A_BIT $CYLC_SUITE_NAME
# Force state of dead victim to submitted.
cylc reset --state=submitted $CYLC_SUITE_NAME victim.1
# A poll should find that victim is really still dead.
cylc poll $CYLC_SUITE_NAME victim.1
# Check the poll result (or fail).
cylc suite-state -t victim -p 1 --status=failed $WAIT_A_BIT $CYLC_SUITE_NAME
sleep 2
# Force to succeeded, to hide the evidence and allow clean suite shutdown.
cylc reset --state=succeeded $CYLC_SUITE_NAME victim.1
        """
