Skip to content
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

Fix determining initial test suite duration in parallel #17

Merged
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions src/Contracts/MutationTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public function isEnabled(): bool;
*/
public function setOriginalArguments(array $arguments): void;

public function setStartTime(float $startTime): void;

public function isCodeCoverageRequested(): bool;

public function run(): int;
Expand Down
5 changes: 2 additions & 3 deletions src/MutationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,9 @@ public function start(array $coveredLines, Configuration $configuration, array $
private function calculateTimeout(): int
{
$initialTestSuiteDuration = Container::getInstance()->get(TelemetryRepository::class) // @phpstan-ignore-line
->getInitialTestSuiteDuration()
->seconds();
->getInitialTestSuiteDuration();

return $initialTestSuiteDuration + max(5, (int) ($initialTestSuiteDuration * 0.2));
return (int) ($initialTestSuiteDuration + max(5, $initialTestSuiteDuration * 0.2));
}

public function hasFinished(): bool
Expand Down
1 change: 1 addition & 0 deletions src/Plugins/Mutate.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function handleArguments(array $arguments): array
->cliConfiguration->fromArguments($arguments);

$mutationTestRunner->setOriginalArguments($arguments);
$mutationTestRunner->setStartTime(microtime(true));

return $arguments;
}
Expand Down
8 changes: 3 additions & 5 deletions src/Repositories/TelemetryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@

namespace Pest\Mutate\Repositories;

use PHPUnit\Event\Telemetry\Duration;

class TelemetryRepository
{
private Duration $initialTestSuiteDuration;
private float $initialTestSuiteDuration;

public function initialTestSuiteDuration(Duration $duration): void
public function initialTestSuiteDuration(float $duration): void
{
$this->initialTestSuiteDuration = $duration;
}

public function getInitialTestSuiteDuration(): Duration
public function getInitialTestSuiteDuration(): float
{
return $this->initialTestSuiteDuration;
}
Expand Down
10 changes: 1 addition & 9 deletions src/Subscribers/EnsureInitialTestRunWasSuccessful.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Pest\Mutate\Subscribers;

use Pest\Mutate\Repositories\TelemetryRepository;
use Pest\Support\Container;
use PHPUnit\Event\Application\Finished;
use PHPUnit\Event\Application\FinishedSubscriber;

Expand All @@ -14,11 +12,5 @@
*/
final class EnsureInitialTestRunWasSuccessful implements FinishedSubscriber
{
public function notify(Finished $event): void
{
// @phpstan-ignore-next-line
Container::getInstance()->get(TelemetryRepository::class)->initialTestSuiteDuration(
$event->telemetryInfo()->durationSinceStart()
);
}
public function notify(Finished $event): void {}
}
12 changes: 11 additions & 1 deletion src/Tester/MutationTestRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Pest\Mutate\MutationTest;
use Pest\Mutate\Plugins\Mutate;
use Pest\Mutate\Repositories\ConfigurationRepository;
use Pest\Mutate\Repositories\TelemetryRepository;
use Pest\Mutate\Support\Configuration\Configuration;
use Pest\Mutate\Support\FileFinder;
use Pest\Mutate\Support\MutationGenerator;
Expand All @@ -38,6 +39,8 @@ class MutationTestRunner implements MutationTestRunnerContract
*/
private array $runningTests;

private float $startTime;

public static function fake(): MutationTestRunnerFake
{
$fake = new MutationTestRunnerFake;
Expand Down Expand Up @@ -90,7 +93,9 @@ public function isCodeCoverageRequested(): bool

public function run(): int
{
$start = microtime(true);
Container::getInstance()->get(TelemetryRepository::class)->initialTestSuiteDuration( // @phpstan-ignore-line
microtime(true) - $this->startTime
);

if (! Coverage::isAvailable() || ! file_exists($reportPath = Coverage::getPath())) {
Container::getInstance()->get(Printer::class)->reportError('No coverage report found, aborting mutation testing.'); // @phpstan-ignore-line
Expand Down Expand Up @@ -294,4 +299,9 @@ private function clearCacheIfPluginVersionChanged(): void

$cache->set('mutation-plugin-version', $pluginVersion); // @phpstan-ignore-line
}

public function setStartTime(float $startTime): void
{
$this->startTime = $startTime;
}
}
5 changes: 5 additions & 0 deletions src/Tester/MutationTestRunnerFake.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public function setOriginalArguments(array $arguments): void
{
// TODO: Implement setOriginalArguments() method.
}

public function setStartTime(float $startTime): void
{
// TODO: Implement setStartTime() method.
}
}
Loading