summaryrefslogtreecommitdiffstats
path: root/test/integration/targets/throttle
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/targets/throttle')
-rw-r--r--test/integration/targets/throttle/aliases2
-rw-r--r--test/integration/targets/throttle/group_vars/all.yml4
-rw-r--r--test/integration/targets/throttle/inventory6
-rwxr-xr-xtest/integration/targets/throttle/runme.sh7
-rwxr-xr-xtest/integration/targets/throttle/test_throttle.py34
-rw-r--r--test/integration/targets/throttle/test_throttle.yml84
6 files changed, 137 insertions, 0 deletions
diff --git a/test/integration/targets/throttle/aliases b/test/integration/targets/throttle/aliases
new file mode 100644
index 0000000..498fedd
--- /dev/null
+++ b/test/integration/targets/throttle/aliases
@@ -0,0 +1,2 @@
+shippable/posix/group4
+context/controller
diff --git a/test/integration/targets/throttle/group_vars/all.yml b/test/integration/targets/throttle/group_vars/all.yml
new file mode 100644
index 0000000..b04b2aa
--- /dev/null
+++ b/test/integration/targets/throttle/group_vars/all.yml
@@ -0,0 +1,4 @@
+---
+throttledir: '{{ base_throttledir }}/{{ subdir }}'
+base_throttledir: "{{ lookup('env', 'OUTPUT_DIR') }}/throttle.dir"
+subdir: "{{ test_id if lookup('env', 'SELECTED_STRATEGY') in ['free', 'host_pinned'] else '' }}"
diff --git a/test/integration/targets/throttle/inventory b/test/integration/targets/throttle/inventory
new file mode 100644
index 0000000..9f062d9
--- /dev/null
+++ b/test/integration/targets/throttle/inventory
@@ -0,0 +1,6 @@
+[localhosts]
+testhost[00:11]
+
+[localhosts:vars]
+ansible_connection=local
+ansible_python_interpreter="{{ ansible_playbook_python }}"
diff --git a/test/integration/targets/throttle/runme.sh b/test/integration/targets/throttle/runme.sh
new file mode 100755
index 0000000..0db5098
--- /dev/null
+++ b/test/integration/targets/throttle/runme.sh
@@ -0,0 +1,7 @@
+#!/usr/bin/env bash
+
+set -eux
+
+# https://github.com/ansible/ansible/pull/42528
+SELECTED_STRATEGY='linear' ansible-playbook test_throttle.yml -vv -i inventory --forks 12 "$@"
+SELECTED_STRATEGY='free' ansible-playbook test_throttle.yml -vv -i inventory --forks 12 "$@"
diff --git a/test/integration/targets/throttle/test_throttle.py b/test/integration/targets/throttle/test_throttle.py
new file mode 100755
index 0000000..1a5bdd3
--- /dev/null
+++ b/test/integration/targets/throttle/test_throttle.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python
+
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+import os
+import sys
+import time
+
+# read the args from sys.argv
+throttledir, inventory_hostname, max_throttle = sys.argv[1:]
+# format/create additional vars
+max_throttle = int(max_throttle)
+throttledir = os.path.expanduser(throttledir)
+throttlefile = os.path.join(throttledir, inventory_hostname)
+try:
+ # create the file
+ with open(throttlefile, 'a'):
+ os.utime(throttlefile, None)
+ # count the number of files in the dir
+ throttlelist = os.listdir(throttledir)
+ print("tasks: %d/%d" % (len(throttlelist), max_throttle))
+ # if we have too many files, fail
+ if len(throttlelist) > max_throttle:
+ print(throttlelist)
+ raise ValueError("Too many concurrent tasks: %d/%d" % (len(throttlelist), max_throttle))
+ time.sleep(1.5)
+finally:
+ # remove the file, then wait to make sure it's gone
+ os.unlink(throttlefile)
+ while True:
+ if not os.path.exists(throttlefile):
+ break
+ time.sleep(0.1)
diff --git a/test/integration/targets/throttle/test_throttle.yml b/test/integration/targets/throttle/test_throttle.yml
new file mode 100644
index 0000000..8990ea2
--- /dev/null
+++ b/test/integration/targets/throttle/test_throttle.yml
@@ -0,0 +1,84 @@
+---
+- hosts: localhosts
+ gather_facts: false
+ strategy: linear
+ run_once: yes
+ tasks:
+ - name: Clean base throttledir '{{ base_throttledir }}'
+ file:
+ state: absent
+ path: '{{ base_throttledir }}'
+ ignore_errors: yes
+
+ - name: Create throttledir '{{ throttledir }}'
+ file:
+ state: directory
+ path: '{{ throttledir }}'
+ loop: "{{ range(1, test_count|int)|list }}"
+ loop_control:
+ loop_var: test_id
+ vars:
+ test_count: "{{ 9 if lookup('env', 'SELECTED_STRATEGY') in ['free', 'host_pinned'] else 2 }}"
+
+- hosts: localhosts
+ gather_facts: false
+ strategy: "{{ lookup('env', 'SELECTED_STRATEGY') }}"
+ tasks:
+ - block:
+ - name: "Test 1 (max throttle: 3)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 3"
+ vars:
+ test_id: 1
+ throttle: 3
+ - block:
+ - name: "Test 2 (max throttle: 5)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 5"
+ throttle: 5
+ vars:
+ test_id: 2
+ - block:
+ - name: "Test 3 (max throttle: 8)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 8"
+ throttle: 8
+ throttle: 6
+ vars:
+ test_id: 3
+ - block:
+ - block:
+ - name: "Test 4 (max throttle: 8)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 8"
+ throttle: 8
+ vars:
+ test_id: 4
+ throttle: 6
+ throttle: 12
+ throttle: 15
+ - block:
+ - name: "Teat 5 (max throttle: 3)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 3"
+ vars:
+ test_id: 5
+ throttle: 3
+ - block:
+ - name: "Test 6 (max throttle: 5)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 5"
+ throttle: 5
+ vars:
+ test_id: 6
+ - block:
+ - name: "Test 7 (max throttle: 6)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 6"
+ throttle: 6
+ vars:
+ test_id: 7
+ throttle: 3
+ - block:
+ - block:
+ - name: "Test 8 (max throttle: 8)"
+ script: "test_throttle.py {{throttledir}} {{inventory_hostname}} 8"
+ throttle: 8
+ vars:
+ test_id: 8
+ throttle: 6
+ throttle: 4
+ throttle: 2