diff options
author | Vitor Mattos <vitor@php.rio> | 2023-02-28 18:57:11 -0300 |
---|---|---|
committer | Vitor Mattos <vitor@php.rio> | 2023-02-28 19:59:07 -0300 |
commit | 22cdc4e88c3049dc8126b06c6d87ef774eb325b9 (patch) | |
tree | df64a1d250f2fcb88a5ca81b422535ae6d31f53d /tests | |
parent | ff03f17725d04070de85dbaa75db2e9d373f58f5 (diff) |
Wait by mock server
Signed-off-by: Vitor Mattos <vitor@php.rio>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/features/bootstrap/RecordingTrait.php | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/integration/features/bootstrap/RecordingTrait.php b/tests/integration/features/bootstrap/RecordingTrait.php index d9d6d5b1f..4dbd813c9 100644 --- a/tests/integration/features/bootstrap/RecordingTrait.php +++ b/tests/integration/features/bootstrap/RecordingTrait.php @@ -110,6 +110,8 @@ trait RecordingTrait { 'php -S ' . $this->getSignalingServerAddress() . ' ' . $path . ' >/dev/null & echo $!' ); + $this->waitForMockServer(); + register_shutdown_function(function () { if ($this->recordingServerPid !== '') { exec('kill ' . $this->recordingServerPid); @@ -118,6 +120,24 @@ trait RecordingTrait { }); } + private function waitForMockServer(): void { + [$host, $port] = explode(':', $this->getSignalingServerAddress()); + $mockServerIsUp = false; + for ($i = 0; $i <= 20; $i++) { + usleep(100000); + + $open = @fsockopen($host, $port); + if (is_resource($open)) { + fclose($open); + $mockServerIsUp = true; + break; + } + } + if (!$mockServerIsUp) { + throw new \Exception('Failure to start mock server.'); + } + } + /** * @AfterScenario * |