Skip to content

Commit 266f0be

Browse files
authored
Merge pull request #64 from berejant/fix/port-resolve-wait-port
Fix issue with repeatable host port resolve in WaitForHttp
2 parents 874827c + 8e4845e commit 266f0be

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/Wait/WaitForHttp.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,10 @@ class WaitForHttp extends BaseWaitStrategy
3030
*/
3131
protected int $readTimeout = 1000;
3232

33+
protected ?int $hostPort = null;
34+
3335
public function __construct(
34-
protected ?int $port = null,
36+
protected ?int $containerPort = null,
3537
int $timeout = 10000,
3638
int $pollInterval = 500
3739
) {
@@ -101,10 +103,10 @@ public function wait(StartedTestContainer $container): void
101103
}
102104

103105
try {
104-
$this->resolvePort($container);
106+
$this->resolveHostPort($container);
105107
$containerAddress = $container->getHost();
106108

107-
$url = sprintf('%s://%s:%d%s', $this->protocol, $containerAddress, $this->port, $this->path);
109+
$url = sprintf('%s://%s:%d%s', $this->protocol, $containerAddress, $this->hostPort, $this->path);
108110
$responseCode = $this->makeHttpRequest($url);
109111

110112
if ($responseCode === $this->expectedStatusCode) {
@@ -142,10 +144,14 @@ private function makeHttpRequest(string $url): int
142144
return curl_getinfo($ch, CURLINFO_HTTP_CODE);
143145
}
144146

145-
private function resolvePort(StartedTestContainer $container): void
147+
private function resolveHostPort(StartedTestContainer $container): void
146148
{
147-
$this->port = $this->port === null
149+
if ($this->hostPort !== null) {
150+
return; // Port already resolved
151+
}
152+
153+
$this->hostPort = $this->containerPort === null
148154
? $container->getFirstMappedPort()
149-
: $container->getMappedPort($this->port);
155+
: $container->getMappedPort($this->containerPort);
150156
}
151157
}

0 commit comments

Comments
 (0)