
# This loop illustrate the way to exit the loop upon operator answer
- loop:
    doc: This loop illustrate the way to exit on a condition.
    name: Infine loop with conditional exit
    stop_on_failure: False
    key: $(test)_PASS
    steps:
        - sleep: {name: small wait, timeout: 0.2}
        - py_func:
            name: Echo function
            key: $(test)_PASS
            file: $(test_path)$(psep)conditional$(psep)conditional.py
            func_name: echo
            param:
                - $(loop_param)

    exit_condition:
        value: <| $(pfn_Echo function) > 3 |>

- let:
    name: let
    key: $(test)_PASS
    values:
        - conditional_exec: <| random.randint(1, 2) |>

- console:
    name: Console creation
    condition: <| $(conditional_exec) == 1 |>
    console_name: consname
    doc: Opening the console
    key: $(test)_PASS
    steps:
        - open:
            protocol: terminal
            terminal_path: $(test_directory)
        - writeln: echo "terminal loaded"

- console:
    name: Console read_until with timeout
    condition: <| $(conditional_exec) == 1 |>
    console_name: consname
    key: $(test)_PASS
    steps:
{% if os == "Windows" %}
        - read_until: {expected: echo "terminal loaded", timeout: 1}
{% endif %}
        - read_until: {expected: terminal loaded, timeout: 5}

# Echo two tokens on one line so both are buffered together; the immediate
# (timeout 0) reads below match buffered data with no race on the async prompt.
- console:
    name: Console write
    condition: <| $(conditional_exec) == 1 |>
    console_name: consname
    key: $(test)_PASS
    steps:
        - writeln: echo ALPHA BETA

- sleep:
    name: sleep item
    condition: <| $(conditional_exec) == 1 |>
    timeout: 1

- console:
    name: Console read_until immediate
    condition: <| $(conditional_exec) == 1 |>
    console_name: consname
    key: $(test)_PASS
    steps:
{% if os == "Windows" %}
        - read_until: {expected: echo ALPHA BETA, timeout: 0}
{% endif %}
        - read_until: {expected: ALPHA, timeout: 0}

- console:
    name: Console read_until immediate (2)
    condition: <| $(conditional_exec) == 1 |>
    console_name: consname
    key: $(test)_PASS
    steps:
        - read_until: {expected: BETA, timeout: 0}

- console:
    name: Console closure
    condition: <| $(conditional_exec) == 1 |>
    console_name: consname
    key: $(test)_PASS
    steps:
        - close: consname

- sleep:
    name: sleep item
    condition: <| $(conditional_exec) == 2 |>
    timeout: 1
