Skip to content

Fix flaky tests #124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 15, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions tests/Integration/ParallelizationIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,17 @@ public function test_it_can_run_the_command_without_sub_processes(): void
Processing 5 items in segments of 2, batches of 2, 1 round, 1 batch in 1 process

0/5 [>---------------------------] 0% 10 secs/10 secs 10.0 MiB
1/5 [=====>----------------------] 20% 10 secs/10 secs 10.0 MiB
2/5 [===========>----------------] 40% 10 secs/10 secs 10.0 MiB
3/5 [================>-----------] 60% 10 secs/10 secs 10.0 MiB
4/5 [======================>-----] 80% 10 secs/10 secs 10.0 MiB
5/5 [============================] 100% 10 secs/10 secs 10.0 MiB

Processed 5 items.

EOF;

$actual = $this->getOutput($commandTester);
$actual = self::normalizeIntermediateProgressBars(
$this->getOutput($commandTester),
);

self::assertSame($expected, $actual);
self::assertSame($expected, $actual, $actual);
}

public function test_it_uses_a_sub_process_if_only_one_process_is_used(): void
Expand Down Expand Up @@ -112,15 +110,15 @@ public function test_it_can_run_the_command_with_multiple_processes(): void
Processing 5 movies in segments of 2, batches of 2, 3 rounds, 3 batches in 2 processes

0/5 [>---------------------------] 0% 10 secs/10 secs 10.0 MiB
2/5 [===========>----------------] 40% 10 secs/10 secs 10.0 MiB
4/5 [======================>-----] 80% 10 secs/10 secs 10.0 MiB
5/5 [============================] 100% 10 secs/10 secs 10.0 MiB

Processed 5 movies.

EOF;

$actual = $this->getOutput($commandTester);
$actual = self::normalizeIntermediateProgressBars(
$this->getOutput($commandTester),
);

self::assertSame($expected, $actual, $actual);
}
Expand All @@ -144,8 +142,6 @@ public function test_it_can_run_the_command_with_multiple_processes_in_debug_mod
Processing 5 movies in segments of 2, batches of 2, 3 rounds, 3 batches in 2 processes

0/5 [>---------------------------] 0% 10 secs/10 secs 10.0 MiB
2/5 [===========>----------------] 40% 10 secs/10 secs 10.0 MiB
4/5 [======================>-----] 80% 10 secs/10 secs 10.0 MiB
5/5 [============================] 100% 10 secs/10 secs 10.0 MiB

Processed 5 movies.
Expand All @@ -158,10 +154,12 @@ public function test_it_can_run_the_command_with_multiple_processes_in_debug_mod
$expectedCommandStartedLine = "[debug] Command started: '/path/to/php' '/path/to/work-dir/bin/console' 'import:movies' '--child'\n";
$expectedCommandFinishedLine = "[debug] Command finished\n";

$outputWithoutExtraDebugInfo = str_replace(
[$expectedCommandStartedLine, $expectedCommandFinishedLine],
['', ''],
$actual,
$outputWithoutExtraDebugInfo = self::normalizeIntermediateProgressBars(
str_replace(
[$expectedCommandStartedLine, $expectedCommandFinishedLine],
['', ''],
$actual,
),
);

self::assertSame($expectedWithNoDebugMode, $outputWithoutExtraDebugInfo, $outputWithoutExtraDebugInfo);
Expand Down Expand Up @@ -216,4 +214,13 @@ private static function normalizeConsolePath(string $output): string
$output,
);
}

private static function normalizeIntermediateProgressBars(string $output): string
{
return preg_replace(
'# *?[1-4]/5 \[[=>-]+\] \d+% 10 secs/10 secs 10.0 MiB\n#',
'',
$output,
);
}
}