From 1ae2bff5ffc3ff8afd5821ae6ebdd2295e85c769 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Thu, 30 Dec 2021 14:11:36 +0200 Subject: [PATCH 1/2] Speed up Windows tests Enable multiple workers for Windows, just like we do on Linux already. --- .github/workflows/windows-ci.yml | 35 ++++++++++++++++-- bin/generate_testsuites.php | 61 ++++++++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 bin/generate_testsuites.php diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index f59e4b38471..ac7f60e33bc 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -3,13 +3,41 @@ name: Run unit tests on Windows on: [push, pull_request] jobs: + chunk-matrix: + name: Generate Chunk Matrix + + runs-on: ubuntu-latest + env: + CHUNK_COUNT: 8 + + outputs: + count: ${{ steps.chunk-matrix.outputs.count }} + chunks: ${{ steps.chunk-matrix.outputs.chunks }} + + steps: + - id: chunk-matrix + name: Generates the Chunk Matrix + run: | + echo "::set-output name=count::$(php -r 'echo json_encode([ ${{ env.CHUNK_COUNT }} ]);')" + echo "::set-output name=chunks::$(php -r 'echo json_encode(range(1, ${{ env.CHUNK_COUNT }} ));')" + tests: - name: "Unit Tests" + name: "Unit Tests - ${{ matrix.chunk }}" runs-on: windows-latest + needs: + - chunk-matrix strategy: fail-fast: false + matrix: + count: ${{ fromJson(needs.chunk-matrix.outputs.count) }} + chunk: ${{ fromJson(needs.chunk-matrix.outputs.chunks) }} + + env: + CHUNK_COUNT: "${{ matrix.count }}" + CHUNK_NUMBER: "${{ matrix.chunk }}" + PARALLEL_PROCESSES: 5 steps: - name: Set git to use LF @@ -47,5 +75,8 @@ jobs: env: COMPOSER_ROOT_VERSION: dev-master + - name: Generate test suits + run: php bin/generate_testsuites.php $env:CHUNK_COUNT + - name: Run unit tests - run: vendor/bin/paratest --log-junit build/phpunit/phpunit.xml + run: vendor/bin/paratest --processes=$env:PARALLEL_PROCESSES --testsuite=chunk_$env:CHUNK_NUMBER --log-junit build/phpunit/phpunit.xml diff --git a/bin/generate_testsuites.php b/bin/generate_testsuites.php new file mode 100644 index 00000000000..0f16d58d3be --- /dev/null +++ b/bin/generate_testsuites.php @@ -0,0 +1,61 @@ +' . PHP_EOL); + exit(1); +} + +$number_of_chunks = (int) $argv[1]; +if ($number_of_chunks === 0) { + fwrite(STDERR, 'Usage: ' . $argv[0] . ' ' . PHP_EOL); + exit(1); +} + +// find tests -name '*Test.php' +$files = iterator_to_array( + new RegexIterator( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator( + 'tests', + FilesystemIterator::CURRENT_AS_PATHNAME|FilesystemIterator::SKIP_DOTS + ), + RecursiveIteratorIterator::LEAVES_ONLY + ), + '/.*Test.php$/' + ) +); + +mt_srand(4); // chosen by fair dice roll. + // guaranteed to be random. + // -- xkcd:221 + +$order = array_map( + function (): int { + return mt_rand(); + }, + $files +); +array_multisort($order, $files); + +$chunks = array_chunk($files, ceil(count($files) / $number_of_chunks)); + +$phpunit_config = new DOMDocument('1.0', 'UTF-8'); +$phpunit_config->preserveWhiteSpace = false; +$phpunit_config->load('phpunit.xml.dist'); +$suites_container = $phpunit_config->getElementsByTagName('testsuites')->item(0); + +while ($suites_container->firstChild) { + $suites_container->removeChild($suites_container->firstChild); +} + +foreach ($chunks as $chunk_id => $chunk) { + $suite = $phpunit_config->createElement('testsuite'); + $suite->setAttribute('name', 'chunk_' . ($chunk_id + 1)); + foreach ($chunk as $file) { + $suite->appendChild($phpunit_config->createElement('file', $file)); + } + $suites_container->appendChild($suite); +} + +$phpunit_config->formatOutput = true; +$phpunit_config->save('phpunit.xml'); From 18fbaeeda5a6528fffa4e50e67750e689ac7f835 Mon Sep 17 00:00:00 2001 From: Bruce Weirdan Date: Thu, 30 Dec 2021 14:38:58 +0200 Subject: [PATCH 2/2] Attempt to avoid timeouts --- .github/workflows/windows-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/windows-ci.yml b/.github/workflows/windows-ci.yml index ac7f60e33bc..dc5fd77c560 100644 --- a/.github/workflows/windows-ci.yml +++ b/.github/workflows/windows-ci.yml @@ -37,7 +37,7 @@ jobs: env: CHUNK_COUNT: "${{ matrix.count }}" CHUNK_NUMBER: "${{ matrix.chunk }}" - PARALLEL_PROCESSES: 5 + PARALLEL_PROCESSES: 4 steps: - name: Set git to use LF