[meta]
    title = "test suite for broadcast functionality"

    description = """
The initial prep task in this suite broadcasts an environment variable
"BCAST" to various cycles and namespaces, then each task writes its cycle
time, name, and its value of BCAST to a special log file. Finally, the
shutdown event handler compares the broadcast log file with a previously
generated reference version.
              """

[cylc]
    cycle point format = %Y%m%dT%H

[scheduling]
    initial cycle point = 20100808T00
    final cycle point   = 20100809T00
    [[graph]]
        R1 = prep => foo
        T00 = """
            foo => bar & baz & qux & wibble => ENS
            ENS:finish-all => wobble
        """
[runtime]
    [[root]]
        pre-script = "echo $CYLC_TASK_CYCLE_POINT $CYLC_TASK_NAME BCAST is $BCAST | tee -a $BCASTLOG"
        script = "true" # no sleep
        [[[environment]]]
            BCAST = ${BCAST:-(not set)}
            BCASTLOG = ${CYLC_SUITE_DEF_PATH}/broadcast.log
    [[prep]]
        pre-script = "rm -f $BCASTLOG"
        script = """
set +x
{
    # broadcast to all cycles and namespaces:
        cylc broadcast -s "[environment]BCAST = ROOT" $CYLC_SUITE_NAME
    # broadcast to foo.20100808T00:
        cylc broadcast -p 20100808T00 -n foo -s "[environment]BCAST = FOO" $CYLC_SUITE_NAME
    # broadcast to bar at all cycles:
        cylc broadcast -n bar -s "[environment]BCAST = BAR" $CYLC_SUITE_NAME
    # broadcast to baz at 20100809T00:
        cylc broadcast -n baz -p 20100809T00 -s "[environment]BCAST = BAZ" $CYLC_SUITE_NAME
    # broadcast to qux at 20100809T00, then cancel it:
        cylc broadcast -n qux -p 20100809T00 -s "[environment]BCAST = QUX" $CYLC_SUITE_NAME
        cylc broadcast -n qux -p 20100809T00 --cancel "[environment]BCAST" $CYLC_SUITE_NAME
    # broadcast to wibble at all cycles, then clear it:
        cylc broadcast -n wibble -s "[environment]BCAST = WIBBLE" $CYLC_SUITE_NAME
        cylc broadcast -n wibble --clear $CYLC_SUITE_NAME
    # broadcast to all members of ENS, all cycles:
        cylc broadcast -n ENS -s "[environment]BCAST = ENS" $CYLC_SUITE_NAME
    # broadcast to all members of ENS1, all cycles:
        cylc broadcast -n ENS1 -s "[environment]BCAST = ENS1" $CYLC_SUITE_NAME
    # broadcast to a single member m2 of ENS1, in 20100809T00:
        cylc broadcast -n m2 -p 20100809T00 -s "[environment]BCAST = M2" $CYLC_SUITE_NAME
    # cancel broadcast to m4 of ENS1, in 20100809T00 (will not work):
        ! cylc broadcast -n m4 -p 20100809T00 --cancel "[environment]BCAST" $CYLC_SUITE_NAME
    # cancel broadcast to m5 of ENS1 at all cycles (will not work):
        ! cylc broadcast -n m5 --cancel "[environment]BCAST" $CYLC_SUITE_NAME
    # clear broadcast to m6 of ENS1 at all cycles (will not work):
        ! cylc broadcast -n m6 --clear $CYLC_SUITE_NAME
    # clear, then reset, broadcast to m7 of ENS1 at all cycles:
        ! cylc broadcast -n m7 --clear $CYLC_SUITE_NAME
        cylc broadcast -n m7 -s "[environment]BCAST = M7" $CYLC_SUITE_NAME
    # reset broadcast to m8 of ENS1 at 20100809T00
        cylc broadcast -n m8 -s "[environment]BCAST = M8" $CYLC_SUITE_NAME
    # reset broadcast to m9 of ENS1 at all cycles
        cylc broadcast -n m9 -s "[environment]BCAST = M9" $CYLC_SUITE_NAME
    # clear broadcast for ENS3 (will not work):
        ! cylc broadcast -n ENS3 --clear $CYLC_SUITE_NAME
    # list the result to prep task stdout:
        cylc bcast --display $CYLC_SUITE_NAME
} 1>prep.out 2>prep.err
set -x
sed -i '/DEBUG -/d' 'prep.out'
sed -i '/\(DEBUG\|WARNING\|ERROR\) -/d' 'prep.err'

# workaround for platforms affected by https://github.com/cylc/cylc-flow/issues/3585
sed -i '/BASH_XTRACEFD/d' 'prep.err'

diff -u "${CYLC_SUITE_DEF_PATH}/expected-prep.out" 'prep.out'
diff -u "${CYLC_SUITE_DEF_PATH}/expected-prep.err" 'prep.err'
"""
    [[ENS]]
    [[ENS1]]
        inherit = ENS
    [[m1,m2,m3,m4,m5,m6,m7,m8,m9]]
        inherit = ENS1
    [[ENS2]]
        inherit = ENS
    [[n1]]
        inherit = ENS2
    [[ENS3]]
        inherit = ENS
    [[o1]]
        inherit = ENS3
