Skip to content

Commit d079ff5

Browse files
authored
Added new configuration option: wait_until_ready in microseconds (#50)
1 parent 34df2ac commit d079ff5

File tree

4 files changed

+35
-22
lines changed

4 files changed

+35
-22
lines changed

README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ extensions:
4141
logs_path: /var/log/my_app/tests/logs # defaults to codeception's tests output dir
4242
debug: true # defaults to false
4343
wait_until_ready: true # defaults to false
44-
wait_until_ready_timeout: 15 # defaults to 30
44+
wait_until_ready_timeout: 15 # (seconds) defaults to 30
45+
wait_until_ready_interval: 100 # (microseconds) defaults to 50000
4546
expectations_path: /my/expectations/path # defaults to tests/_expectations
4647
server_factory: \My\FactoryClass # defaults to 'default'
4748
extra_instances: [] # deaults to an empty array

codeception.https.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ extensions:
2020
server_factory: Mcustiel\Phiremock\Codeception\Module\Tests\Helpers\FactoryWithGuzzle7
2121
logs_path: tests/_output/phiremock.extra.log
2222
debug: true
23-
start_delay: 1
23+
start_delay: 0
24+
wait_until_ready: true
25+
wait_until_ready_timeout: 5
26+
wait_until_ready_interval: 10000
2427
extra_instances:
2528
-
2629
listen: 0.0.0.0:18443

src/Extension/Phiremock.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ private function setDefaultLogsPath(): void
113113

114114
private function waitUntilReady(): void
115115
{
116-
if (!$this->extensionConfig->isWaitUntilReady()) {
116+
if (!$this->extensionConfig->waitUntilReady()) {
117117
return;
118118
}
119119

@@ -126,22 +126,21 @@ private function waitUntilReady(): void
126126
);
127127

128128
$start = \microtime(true);
129-
129+
$interval = $this->extensionConfig->getWaitUntilReadyIntervalMicros();
130+
$timeout = $this->extensionConfig->getWaitUntilReadyTimeout();
130131
while (true) {
131132
if ($readinessChecker->isReady()) {
132133
break;
133134
}
134-
135-
\sleep(1);
135+
\usleep($interval);
136136
$elapsed = (int) (\microtime(true) - $start);
137137

138-
if ($elapsed > $this->extensionConfig->getWaitUntilReadyTimeout()) {
138+
if ($elapsed > $timeout) {
139139
throw new \RuntimeException(
140140
\sprintf('Phiremock failed to start within %d seconds', $this->extensionConfig->getWaitUntilReadyTimeout())
141141
);
142142
}
143143
}
144-
145144
$this->writeln('Phiremock is ready!');
146145
}
147146
}

src/PhiremockExtension/Config.php

+24-14
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,23 @@ class Config
3838
public const DEFAULT_SUITES = [];
3939
public const DEFAULT_WAIT_UNTIL_READY = false;
4040
public const DEFAULT_WAIT_UNTIL_READY_TIMEOUT = 30;
41+
public const DEFAULT_WAIT_UNTIL_READY_INTERVAL_MICROS = 50000;
4142

4243
public const DEFAULT_CONFIG = [
43-
'listen' => self::DEFAULT_INTERFACE . ':' . self::DEFAULT_PORT,
44-
'debug' => self::DEFAULT_DEBUG_MODE,
45-
'start_delay' => self::DEFAULT_DELAY,
46-
'bin_path' => self::DEFAULT_PHIREMOCK_PATH,
47-
'expectations_path' => self::DEFAULT_EXPECTATIONS_PATH,
48-
'server_factory' => self::DEFAULT_SERVER_FACTORY,
49-
'certificate' => self::DEFAULT_CERTIFICATE,
50-
'certificate_key' => self::DEFAULT_CERTIFICATE_KEY,
51-
'cert_passphrase' => self::DEFAULT_CERTIFICATE_PASSPHRASE,
52-
'extra_instances' => self::DEFAULT_EXTRA_INSTANCES,
53-
'suites' => self::DEFAULT_SUITES,
54-
'wait_until_ready' => self::DEFAULT_WAIT_UNTIL_READY,
55-
'wait_until_ready_timeout' => self::DEFAULT_WAIT_UNTIL_READY_TIMEOUT
44+
'listen' => self::DEFAULT_INTERFACE . ':' . self::DEFAULT_PORT,
45+
'debug' => self::DEFAULT_DEBUG_MODE,
46+
'start_delay' => self::DEFAULT_DELAY,
47+
'bin_path' => self::DEFAULT_PHIREMOCK_PATH,
48+
'expectations_path' => self::DEFAULT_EXPECTATIONS_PATH,
49+
'server_factory' => self::DEFAULT_SERVER_FACTORY,
50+
'certificate' => self::DEFAULT_CERTIFICATE,
51+
'certificate_key' => self::DEFAULT_CERTIFICATE_KEY,
52+
'cert_passphrase' => self::DEFAULT_CERTIFICATE_PASSPHRASE,
53+
'extra_instances' => self::DEFAULT_EXTRA_INSTANCES,
54+
'suites' => self::DEFAULT_SUITES,
55+
'wait_until_ready' => self::DEFAULT_WAIT_UNTIL_READY,
56+
'wait_until_ready_timeout' => self::DEFAULT_WAIT_UNTIL_READY_TIMEOUT,
57+
'wait_until_ready_interval' => self::DEFAULT_WAIT_UNTIL_READY_INTERVAL_MICROS,
5658
];
5759

5860
/** @var string */
@@ -87,6 +89,8 @@ class Config
8789
private $waitUntilReady;
8890
/** @var int */
8991
private $waitUntilReadyTimeout;
92+
/** @var int */
93+
private $waitUntilReadyCheckIntervalMicros;
9094

9195
/** @throws ConfigurationException */
9296
public function __construct(array $config, callable $output)
@@ -106,6 +110,7 @@ public function __construct(array $config, callable $output)
106110
$this->suites = $config['suites'];
107111
$this->waitUntilReady = (bool) $config['wait_until_ready'];
108112
$this->waitUntilReadyTimeout = (int) $config['wait_until_ready_timeout'];
113+
$this->waitUntilReadyCheckIntervalMicros = (int) $config['wait_until_ready_interval'];
109114
}
110115

111116
public function getSuites(): array
@@ -184,7 +189,7 @@ public function isSecure(): bool
184189
&& $this->getCertificateKeyPath() !== null;
185190
}
186191

187-
public function isWaitUntilReady(): bool
192+
public function waitUntilReady(): bool
188193
{
189194
return $this->waitUntilReady;
190195
}
@@ -194,6 +199,11 @@ public function getWaitUntilReadyTimeout(): int
194199
return $this->waitUntilReadyTimeout;
195200
}
196201

202+
public function getWaitUntilReadyIntervalMicros(): int
203+
{
204+
return $this->waitUntilReadyCheckIntervalMicros;
205+
}
206+
197207
/** @throws ConfigurationException */
198208
public static function getDefaultLogsPath(): string
199209
{

0 commit comments

Comments
 (0)