From 93c9895027fe415346585c2368ba1be1cb995329 Mon Sep 17 00:00:00 2001 From: Sergei Shitikov Date: Sun, 1 Sep 2024 19:12:46 +0200 Subject: [PATCH] Adjust tests for OpenSearch --- phpunit.xml.dist | 1 + src/Container/MySQLContainer.php | 3 +-- src/Container/OpenSearchContainer.php | 7 ++++++- tests/Integration/MySQLContainerTest.php | 2 +- tests/Integration/OpenSearchContainerTest.php | 2 +- 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 9993376..fd48e82 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -14,6 +14,7 @@ tests + tests/Integration/WaitStrategyTest.php diff --git a/src/Container/MySQLContainer.php b/src/Container/MySQLContainer.php index cdf6577..e4bb4d9 100644 --- a/src/Container/MySQLContainer.php +++ b/src/Container/MySQLContainer.php @@ -12,9 +12,8 @@ class MySQLContainer extends GenericContainer { parent::__construct('mysql:' . $version); $this->withExposedPorts(3306); - - $this->withWait(new WaitForLog('ready for connections')); $this->withEnvironment('MYSQL_ROOT_PASSWORD', $mysqlRootPassword); + $this->withWait(new WaitForLog('ready for connections')); } /** diff --git a/src/Container/OpenSearchContainer.php b/src/Container/OpenSearchContainer.php index 186df17..a6d2b84 100644 --- a/src/Container/OpenSearchContainer.php +++ b/src/Container/OpenSearchContainer.php @@ -5,6 +5,7 @@ declare(strict_types=1); namespace Testcontainers\Container; use Testcontainers\Wait\WaitForHttp; +use Testcontainers\Wait\WaitForLog; class OpenSearchContainer extends GenericContainer { @@ -14,7 +15,11 @@ class OpenSearchContainer extends GenericContainer $this->withExposedPorts(9200); $this->withEnvironment('discovery.type', 'single-node'); $this->withEnvironment('OPENSEARCH_INITIAL_ADMIN_PASSWORD', 'c3o_ZPHo!'); - $this->withWait(WaitForHttp::make(9200)); + $this->withWait(new WaitForLog( + '/\]\s+started\?\[/', + true, + 30000 + )); } /** diff --git a/tests/Integration/MySQLContainerTest.php b/tests/Integration/MySQLContainerTest.php index d625a90..51c98e3 100644 --- a/tests/Integration/MySQLContainerTest.php +++ b/tests/Integration/MySQLContainerTest.php @@ -19,7 +19,7 @@ class MySQLContainerTest extends ContainerTestCase public function testMySQLContainer(): void { $pdo = new \PDO( - sprintf('mysql:host=%s;port=3306', self::$container->getAddress()), + sprintf('mysql:host=%s;port=3306', '127.0.0.1'), 'bar', 'baz', ); diff --git a/tests/Integration/OpenSearchContainerTest.php b/tests/Integration/OpenSearchContainerTest.php index 92fd1cb..8e8db0d 100644 --- a/tests/Integration/OpenSearchContainerTest.php +++ b/tests/Integration/OpenSearchContainerTest.php @@ -21,7 +21,7 @@ class OpenSearchContainerTest extends ContainerTestCase public function testOpenSearch(): void { $ch = curl_init(); - curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', self::$container->getAddress(), 9200)); + curl_setopt($ch, CURLOPT_URL, sprintf('http://%s:%d', '127.0.0.1', 9200)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = (string) curl_exec($ch);