diff --git a/src/MutationTest.php b/src/MutationTest.php index 4c987e7..de17e27 100644 --- a/src/MutationTest.php +++ b/src/MutationTest.php @@ -7,7 +7,7 @@ use ParaTest\Options; use Pest\Mutate\Event\Facade; 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\MutationTestResult; use Pest\Support\Container; @@ -103,10 +103,11 @@ public function start(array $coveredLines, Configuration $configuration, array $ private function calculateTimeout(): int { - // TODO: calculate a reasonable timeout - return Container::getInstance()->get(ConfigurationRepository::class)->mergedConfiguration()->parallel ? // @phpstan-ignore-line - 10 : - 3; + $initialTestSuiteDuration = Container::getInstance()->get(TelemetryRepository::class) // @phpstan-ignore-line + ->getInitialTestSuiteDuration() + ->seconds(); + + return $initialTestSuiteDuration + max(5, $initialTestSuiteDuration * 0.2); } public function hasFinished(): bool diff --git a/src/Repositories/TelemetryRepository.php b/src/Repositories/TelemetryRepository.php new file mode 100644 index 0000000..c703b69 --- /dev/null +++ b/src/Repositories/TelemetryRepository.php @@ -0,0 +1,22 @@ +initialTestSuiteDuration = $duration; + } + + public function getInitialTestSuiteDuration(): Duration + { + return $this->initialTestSuiteDuration; + } +} diff --git a/src/Subscribers/EnsureInitialTestRunWasSuccessful.php b/src/Subscribers/EnsureInitialTestRunWasSuccessful.php index f20be25..d8cb57b 100644 --- a/src/Subscribers/EnsureInitialTestRunWasSuccessful.php +++ b/src/Subscribers/EnsureInitialTestRunWasSuccessful.php @@ -4,6 +4,8 @@ namespace Pest\Mutate\Subscribers; +use Pest\Mutate\Repositories\TelemetryRepository; +use Pest\Support\Container; use PHPUnit\Event\Application\Finished; use PHPUnit\Event\Application\FinishedSubscriber; @@ -12,5 +14,11 @@ */ final class EnsureInitialTestRunWasSuccessful implements FinishedSubscriber { - public function notify(Finished $event): void {} + public function notify(Finished $event): void + { + // @phpstan-ignore-next-line + Container::getInstance()->get(TelemetryRepository::class)->initialTestSuiteDuration( + $event->telemetryInfo()->durationSinceStart() + ); + } }