From 242a5a061127fe4c319e3bf73a2e76368318341a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0nan=C3=A7=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 31 Aug 2023 11:10:53 +0300 Subject: [PATCH] Limit E2E test parallelism The current Github runner is low on resources, so running many E2E tests can make tests more flaky then necessary. For now, it seems, we need to leave with this. --- .github/workflows/e2e.yml | 49 ++++++++++++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 36ff67aba..67c18ff59 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -60,26 +60,57 @@ jobs: export K6_BROWSER_EXECUTABLE_PATH=/usr/bin/google-chrome fi export K6_BROWSER_HEADLESS=true + + # run only two E2E tests in parallel + # the current runner is low on resources + max_concurrent_jobs=2 + current_jobs=0 + declare -a pids declare -a output_files + launch_job() { + local f="$1" + + local output_file="output_$(basename "$f" .js).txt" + output_files+=("$output_file") + + # Run the test in the background + ./k6extension run "$f" > "$output_file" 2>&1 & + local pid=$! + + pids+=($pid) + current_jobs=$((current_jobs + 1)) + } + for f in examples/*.js; do if [ "$f" == "examples/hosts.js" ] && [ "$RUNNER_OS" == "Windows" ]; then echo "skipping $f on Windows" continue fi - output_file="output_$(basename "$f" .js).txt" - output_files+=("$output_file") - ./k6extension run -q "$f" > "$output_file" 2>&1 & - pids+=($!) + + launch_job "$f" + + # If we've reached the maximum number of concurrent jobs, wait for one to finish + if [ "$current_jobs" -ge "$max_concurrent_jobs" ]; then + wait "${pids[0]}" + unset "pids[0]" + pids=("${pids[@]}") + current_jobs=$((current_jobs - 1)) + fi done - # Wait for each background job to finish and display its output - for i in "${!pids[@]}"; do - wait "${pids[$i]}" - echo "Output for job ${pids[$i]} (from file ${output_files[$i]}):" - cat "${output_files[$i]}" + # Wait for all remaining jobs to finish + for pid in "${pids[@]}"; do + wait "$pid" done + + # Output the results + for output_file in "${output_files[@]}"; do + echo "Output from file $output_file:" + cat "$output_file" + done + - name: Check screenshot if: matrix.go != 'tip' || matrix.platform != 'windows-latest' # TODO: Do something more sophisticated?