- Move most of the stuff for backwards compatibility support into one class

- Added random port logic
- Updated wait wtrategies
- API alignments to make it similar to other official implementations
- ...
This commit is contained in:
Sergei Shitikov
2024-09-06 19:08:37 +02:00
parent a956794279
commit f05ea0020d
43 changed files with 1191 additions and 601 deletions
+40
View File
@@ -0,0 +1,40 @@
<?php
declare(strict_types=1);
namespace Testcontainers\Wait;
use Docker\API\Model\ContainersIdJsonGetResponse200;
use Testcontainers\Container\StartedTestContainer;
use Testcontainers\Exception\ContainerNotReadyException;
/**
* Simply makes container inspect and checks if container is running.
* Uses $timout and $pollInterval in milliseconds to set the parameters for waiting.
*/
class WaitForContainer extends BaseWaitStrategy
{
public function wait(StartedTestContainer $container): void
{
$id = $container->getId();
$startTime = microtime(true) * 1000;
while (true) {
$elapsedTime = (microtime(true) * 1000) - $startTime;
if ($elapsedTime > $this->timeout) {
throw new ContainerNotReadyException($id);
}
/** @var ContainersIdJsonGetResponse200 | null $containerInspect */
$containerInspect = $container->getClient()->containerInspect($id);
$containerStatus = $containerInspect?->getState()?->getStatus();
if ($containerStatus === 'running') {
return;
}
usleep($this->pollInterval * 1000);
}
}
}