From 28e67362261170409ec7233c898ae39d9b974ff5 Mon Sep 17 00:00:00 2001 From: s-hertel <19572925+s-hertel@users.noreply.github.com> Date: Wed, 9 Aug 2023 10:10:59 -0400 Subject: [PATCH] Add a test case for loop item display Use test_utils timeout script for compatibility on different platforms Reduce test duration and redistribute timeout to try to avoid race condition Co-authored-by: Matt Davis <6775756+nitzmahone@users.noreply.github.com> --- test/integration/targets/loops/aliases | 1 + test/integration/targets/loops/playbook.yml | 4 ++++ test/integration/targets/loops/runme.sh | 23 +++++++++++++++++++ .../targets/loops/test_loop_item_display.yml | 9 ++++++++ 4 files changed, 37 insertions(+) create mode 100644 test/integration/targets/loops/playbook.yml create mode 100755 test/integration/targets/loops/runme.sh create mode 100644 test/integration/targets/loops/test_loop_item_display.yml diff --git a/test/integration/targets/loops/aliases b/test/integration/targets/loops/aliases index 498fedd558e..4c302cbdfae 100644 --- a/test/integration/targets/loops/aliases +++ b/test/integration/targets/loops/aliases @@ -1,2 +1,3 @@ shippable/posix/group4 context/controller +needs/target/test_utils diff --git a/test/integration/targets/loops/playbook.yml b/test/integration/targets/loops/playbook.yml new file mode 100644 index 00000000000..e48ae4b8fef --- /dev/null +++ b/test/integration/targets/loops/playbook.yml @@ -0,0 +1,4 @@ +- hosts: all + gather_facts: no + roles: + - ../loops diff --git a/test/integration/targets/loops/runme.sh b/test/integration/targets/loops/runme.sh new file mode 100755 index 00000000000..13f0bcfad09 --- /dev/null +++ b/test/integration/targets/loops/runme.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +set -eu + +ansible-playbook playbook.yml -i ../../inventory "$@" + +rm -f out.txt && touch out.txt + +python ../test_utils/scripts/timeout.py -- 10 'ansible-playbook test_loop_item_display.yml "$@" >> out.txt' & + +echo "waiting for first loop result..." +# wait up to 2s for first loop result to appear +python ../test_utils/scripts/timeout.py -- 2 tail -f out.txt | grep item=0 -m 1 || (echo "failed to get first loop result in time" && false) + +echo "checking for absence of second loop result..." +# fail if the second loop result appeared too early +grep item=2 out.txt && (echo "found the second loop result early, failing" && false) + +echo "waiting for second loop result..." +# wait up to 3s for second loop result to appear +python ../test_utils/scripts/timeout.py -- 3 tail -f out.txt | grep item=2 -m 1 || (echo "failed to get second loop result in time" && false) + +echo "success" diff --git a/test/integration/targets/loops/test_loop_item_display.yml b/test/integration/targets/loops/test_loop_item_display.yml new file mode 100644 index 00000000000..d5f50c9b702 --- /dev/null +++ b/test/integration/targets/loops/test_loop_item_display.yml @@ -0,0 +1,9 @@ +--- +- hosts: localhost + gather_facts: no + tasks: + - name: Sleep per loop item + shell: sleep {{ item }} + loop: + - 0 + - 2