"""
    :codeauthor: Nicole Thomas <nicole@saltstack.com>
"""

# DGM
import logging

import pytest
import salt.utils.platform

log = logging.getLogger(__name__)

pytestmark = [
    pytest.mark.windows_whitelisted,
    #    pytest.mark.slow_test,
]


@pytest.fixture(scope="module")
def run_timeout():
    if salt.utils.platform.is_windows():
        return 180
    else:
        return 30


def test_batch_run(salt_cli, run_timeout, salt_sub_minion):
    """
    Tests executing a simple batch command to help catch regressions
    """
    ret = "Executing run on [{}]".format(repr(salt_sub_minion.id))
    cmd = salt_cli.run(
        "test.echo",
        "batch testing",
        "-b 50%",
        minion_tgt="*minion*",
        _timeout=run_timeout,
    )
    assert ret in cmd.stdout


def test_batch_run_number(salt_cli, salt_minion, salt_sub_minion, run_timeout):
    """
    Tests executing a simple batch command using a number division instead of
    a percentage with full batch CLI call.
    """
    ret = "Executing run on [{}, {}]".format(
        repr(salt_minion.id), repr(salt_sub_minion.id)
    )
    cmd = salt_cli.run(
        "--batch-size=2",
        "test.ping",
        minion_tgt="*minion*",
        _timeout=run_timeout,