Skip to content

Instantly share code, notes, and snippets.

@bendavies
Last active March 29, 2021 09:33
Show Gist options
  • Save bendavies/4774d7d765c58d453b4fabfd6dfac9a8 to your computer and use it in GitHub Desktop.
Save bendavies/4774d7d765c58d453b4fabfd6dfac9a8 to your computer and use it in GitHub Desktop.
Chunked Tests
jobs:
strategy:
fail-fast: false
matrix:
chunk_count: [5]
chunk_number: [1, 2, 3, 4, 5]
env:
CHUNK_COUNT: ${{matrix.chunk_count}}
CHUNK_NUMBER: ${{matrix.chunk_number}}
PARALLEL_PROCESSES: 5
DATABASE_URL: postgres://abacus:abacus@postgres:5432/abacus
services:
postgres:
image: postgres:9.6
env:
POSTGRES_DB: abacus
POSTGRES_USER: abacus
POSTGRES_PASSWORD: abacus
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
- name: "Checkout"
uses: actions/checkout@v2
#....some more steps to setup dependencies, databases etc..
- name: "Run Tests"
run: bin/tests
#!/bin/bash
set -eu
function get_seeded_random() {
openssl enc -aes-256-ctr -pass pass:"abacus" -nosalt </dev/zero 2>/dev/null
}
function run {
local -r chunk_count="$1"
local -r chunk_number="$2"
local -r parallel_processes="$3"
local -r phpunit_cmd='
echo "::group::{}";
TEST_TOKEN={%} vendor/bin/phpunit --log-junit build/logs/phpunit/{_}.xml --colors=always {};
exit_code=$?;
echo ::endgroup::;
if [[ "$exit_code" -ne 0 ]]; then
echo "::error::{}";
fi;
exit "$exit_code"'
mkdir -p build/logs/phpunit
find tests -name '*Test.php' | shuf --random-source=<(get_seeded_random) > tests_all
split --number="l/$chunk_number/$chunk_count" tests_all > tests_split
parallel --group -j"$parallel_processes" --rpl {_}\ s/\\//_/g --joblog build/logs/parallel.log "$phpunit_cmd" < tests_split
}
if [ -z "${CHUNK_COUNT:-}" ]; then echo "Did not find env var CHUNK_COUNT."; exit 1; fi
if [ -z "${CHUNK_NUMBER:-}" ]; then echo "Did not find env var CHUNK_NUMBER."; exit 1; fi
if [ -z "${PARALLEL_PROCESSES:-}" ]; then echo "Did not find env var PARALLEL_PROCESSES."; exit 1; fi
run "$CHUNK_COUNT" "$CHUNK_NUMBER" "$PARALLEL_PROCESSES"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment