1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

Speed up Windows tests

Enable multiple workers for Windows, just like we do on Linux already.
This commit is contained in:
Bruce Weirdan 2021-12-30 14:11:36 +02:00
parent 03b7e94748
commit 1ae2bff5ff
No known key found for this signature in database
GPG Key ID: CFC3AAB181751B0D
2 changed files with 94 additions and 2 deletions

View File

@ -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

View File

@ -0,0 +1,61 @@
<?php
if (count($argv) < 2) {
fwrite(STDERR, 'Usage: ' . $argv[0] . ' <number_of_chunks>' . PHP_EOL);
exit(1);
}
$number_of_chunks = (int) $argv[1];
if ($number_of_chunks === 0) {
fwrite(STDERR, 'Usage: ' . $argv[0] . ' <number_of_chunks>' . 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');