Skip to content
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
6 changes: 1 addition & 5 deletions src/PhpPact/Standalone/MockService/MockServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ public function start(): int
$processId = $this->processRunner->run();

$result = $this->verifyHealthCheck();
if ($result) {
$retrySec = $this->config->getHealthCheckRetrySec();
\sleep($retrySec);
}

return $processId;
}
Expand Down Expand Up @@ -122,7 +118,7 @@ private function verifyHealthCheck(): bool
try {
return $service->healthCheck();
} catch (ConnectionException $e) {
\sleep($retrySec);
\usleep(intval(round($retrySec * 1000000)));
}
} while ($tries <= $maxTries);

Expand Down
14 changes: 7 additions & 7 deletions src/PhpPact/Standalone/MockService/MockServerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ class MockServerConfig implements MockServerConfigInterface, PactConfigInterface
/**
* The max allowed attempts the mock server has to be available in. Otherwise it is considered as sick.
*/
private int $healthCheckTimeout;
private int $healthCheckTimeout = 100;

/**
* The seconds between health checks of mock server
*/
private int $healthCheckRetrySec;
private float $healthCheckRetrySec = 0.1;

private ?string $logLevel = null;

Expand Down Expand Up @@ -118,7 +118,7 @@ public function isSecure(): bool
/**
* {@inheritdoc}
*/
public function setSecure(bool $secure): MockServerConfigInterface
public function setSecure(bool $secure): self
{
$this->secure = $secure;

Expand Down Expand Up @@ -274,7 +274,7 @@ public function getLogLevel(): ?string
return $this->logLevel;
}

public function setLogLevel(string $logLevel): PactConfigInterface
public function setLogLevel(string $logLevel): self
{
$logLevel = \strtoupper($logLevel);
if (!\in_array($logLevel, ['DEBUG', 'INFO', 'WARN', 'ERROR'])) {
Expand Down Expand Up @@ -303,7 +303,7 @@ public function setCors(mixed $flag): self
return $this;
}

public function setHealthCheckTimeout(int $timeout): MockServerConfigInterface
public function setHealthCheckTimeout(int $timeout): self
{
$this->healthCheckTimeout = $timeout;

Expand All @@ -315,14 +315,14 @@ public function getHealthCheckTimeout(): int
return $this->healthCheckTimeout;
}

public function setHealthCheckRetrySec(int $seconds): MockServerConfigInterface
public function setHealthCheckRetrySec(float $seconds): self
{
$this->healthCheckRetrySec = $seconds;

return $this;
}

public function getHealthCheckRetrySec(): int
public function getHealthCheckRetrySec(): float
{
return $this->healthCheckRetrySec;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function setHealthCheckTimeout(int $timeout): self;

public function getHealthCheckTimeout(): int;

public function setHealthCheckRetrySec(int $seconds): self;
public function setHealthCheckRetrySec(float $seconds): self;

public function getHealthCheckRetrySec(): int;
public function getHealthCheckRetrySec(): float;
}
4 changes: 2 additions & 2 deletions src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ public function __construct()

$timeout = $this->parseEnv('PACT_MOCK_SERVER_HEALTH_CHECK_TIMEOUT', false);
if (!$timeout) {
$timeout = 10;
$timeout = 100;
}
$this->setHealthCheckTimeout($timeout);

$seconds = $this->parseEnv('PACT_MOCK_SERVER_HEALTH_CHECK_RETRY_SEC', false);
if (!$seconds) {
$seconds = 1;
$seconds = 0.1;
}
$this->setHealthCheckRetrySec($seconds);

Expand Down
2 changes: 0 additions & 2 deletions src/PhpPact/Standalone/PactMessage/PactMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public function update(string $pactJson, string $consumer, string $provider, str
$process = new ProcessRunner(Scripts::getPactMessage(), $arguments);
$process->runBlocking();

\sleep(1);

return true;
}
}
14 changes: 13 additions & 1 deletion tests/PhpPact/Standalone/MockServer/MockServerConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,41 @@ public function testSetters()
$consumer = 'test-consumer';
$pactDir = 'test-pact-dir/';
$pactFileWriteMode = 'merge';
$logLevel = 'INFO';
$log = 'test-log-dir/';
$cors = true;
$pactSpecificationVersion = '2.0';
$healthCheckTimeout = 20;
$healthCheckRetrySec = 2.0;
$secure = false;

$subject = (new MockServerConfig())
->setSecure(false)
->setHost($host)
->setPort($port)
->setProvider($provider)
->setConsumer($consumer)
->setPactDir($pactDir)
->setPactFileWriteMode($pactFileWriteMode)
->setLogLevel($logLevel)
->setLog($log)
->setPactSpecificationVersion($pactSpecificationVersion)
->setCors($cors);
->setCors($cors)
->setHealthCheckTimeout(20)
->setHealthCheckRetrySec(2);

static::assertSame($secure, $subject->isSecure());
static::assertSame($host, $subject->getHost());
static::assertSame($port, $subject->getPort());
static::assertSame($provider, $subject->getProvider());
static::assertSame($consumer, $subject->getConsumer());
static::assertSame($pactDir, $subject->getPactDir());
static::assertSame($pactFileWriteMode, $subject->getPactFileWriteMode());
static::assertSame($log, $subject->getLog());
static::assertSame($logLevel, $subject->getLogLevel());
static::assertSame($pactSpecificationVersion, $subject->getPactSpecificationVersion());
static::assertSame($cors, $subject->hasCors());
static::assertSame($healthCheckTimeout, $subject->getHealthCheckTimeout());
static::assertSame($healthCheckRetrySec, $subject->getHealthCheckRetrySec());
}
}