Skip to content

Commit

Permalink
Fix teamcity output concurrency (#851)
Browse files Browse the repository at this point in the history
For each worker, teamcity output is read only when the worker
is free and is getting flushed. So we are sure the worker is
not concurrently writing additional content.

Fix #850
  • Loading branch information
MatteoBiagini committed May 3, 2024
1 parent b2c11a0 commit c361d78
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
7 changes: 3 additions & 4 deletions src/WrapperRunner/ResultPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,13 @@ public function start(): void
$output->write("\n");
}

/** @param list<SplFileInfo> $teamcityFiles */
public function printFeedback(
SplFileInfo $progressFile,
SplFileInfo $outputFile,
array $teamcityFiles
SplFileInfo|null $teamcityFile
): void {
if ($this->options->needsTeamcity) {
$teamcityProgress = $this->tailMultiple($teamcityFiles);
if ($this->options->needsTeamcity && $teamcityFile !== null) {
$teamcityProgress = $this->tailMultiple([$teamcityFile]);

if ($this->teamcityLogFileHandle !== null) {
fwrite($this->teamcityLogFileHandle, $teamcityProgress);
Expand Down
2 changes: 1 addition & 1 deletion src/WrapperRunner/WrapperRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private function flushWorker(WrapperWorker $worker): void
$this->printer->printFeedback(
$worker->progressFile,
$worker->unexpectedOutputFile,
$this->teamcityFiles,
$worker->teamcityFile ?? null,
);
$worker->reset();
}
Expand Down
18 changes: 9 additions & 9 deletions test/Unit/WrapperRunner/ResultPrinterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,15 +137,15 @@ public function testPrintFeedbackForMixed(): void
$outputFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'output1';
file_put_contents($feedbackFile, 'EWWFFFRRSSSS.......');
touch($outputFile);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), []);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), null);
$contents = $this->output->fetch();
self::assertSame('EWWFFFRRSSSS.......', $contents);

$feedbackFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'feedback2';
$outputFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'output2';
file_put_contents($feedbackFile, 'E');
touch($outputFile);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), []);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), null);
$contents = $this->output->fetch();
self::assertSame("E 20 / 20 (100%)\n", $contents);
}
Expand All @@ -159,7 +159,7 @@ public function testColorsForFailing(): void
$outputFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'output1';
file_put_contents($feedbackFile, 'E');
touch($outputFile);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), []);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), null);
$contents = $this->output->fetch();
self::assertStringContainsString('E', $contents);
self::assertStringContainsString('31;1', $contents);
Expand All @@ -181,7 +181,7 @@ public function testTeamcityFeedbackOnFile(): void
file_put_contents($feedbackFile, 'E');
touch($outputFile);

$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), [new SplFileInfo($teamcitySource)]);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), new SplFileInfo($teamcitySource));

self::assertSame('E', $this->output->fetch());
self::assertFileExists($teamcityLog);
Expand All @@ -207,7 +207,7 @@ public function testTeamcityFeedbackOnStdout(): void
file_put_contents($feedbackFile, 'E');
touch($outputFile);

$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), [new SplFileInfo($teamcitySource)]);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), new SplFileInfo($teamcitySource));
$this->printer->printResults($this->getEmptyTestResult(), [new SplFileInfo($teamcitySource)], []);

self::assertSame($teamcitySourceContent, $this->output->fetch());
Expand All @@ -228,7 +228,7 @@ public function testTestdoxOutputWithProgress(): void
file_put_contents($feedbackFile, 'EEE');
touch($outputFile);

$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), []);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), null);
$this->printer->printResults($this->getEmptyTestResult(), [], [new SplFileInfo($testdoxSource)]);

self::assertStringMatchesFormat(
Expand All @@ -252,7 +252,7 @@ public function testTestdoxOutputWithoutProgress(): void
file_put_contents($feedbackFile, 'EEE');
touch($outputFile);

$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), []);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), null);
$this->printer->printResults($this->getEmptyTestResult(), [], [new SplFileInfo($testdoxSource)]);

self::assertStringMatchesFormat(
Expand All @@ -279,7 +279,7 @@ public function testPrintFeedbackFromMultilineSource(): void
$outputFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'output1';
file_put_contents($feedbackFile, str_repeat('.', 300));
touch($outputFile);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), []);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), null);
$contents = $this->output->fetch();
self::assertSame($expected, $contents);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ public function testPrintFeedbackFromMultilineSource2(): void
$outputFile = $this->tmpDir . DIRECTORY_SEPARATOR . 'output1';
file_put_contents($feedbackFile, str_repeat('.', 2484));
touch($outputFile);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), []);
$this->printer->printFeedback(new SplFileInfo($feedbackFile), new SplFileInfo($outputFile), null);
$contents = $this->output->fetch();
self::assertSame($expected, $contents);
}
Expand Down

0 comments on commit c361d78

Please sign in to comment.