Skip to content

Commit f38b96c

Browse files
changed the code the way mysql container is initialized. Trying to fix the issue - #4128
Also going to check if this change will be resolved in the github actions as well. Signed-off-by: Lokesh Rangineni <lokeshforjava@gmail.com>
1 parent 9537946 commit f38b96c

1 file changed

Lines changed: 7 additions & 21 deletions

File tree

sdk/python/tests/unit/test_sql_registry.py

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
from pytest_lazyfixture import lazy_fixture
2222
from testcontainers.core.container import DockerContainer
2323
from testcontainers.core.waiting_utils import wait_for_logs
24+
from testcontainers.mysql import MySqlContainer
2425

2526
from feast import FileSource, RequestSource
2627
from feast.data_format import ParquetFormat
@@ -81,32 +82,17 @@ def pg_registry():
8182

8283
@pytest.fixture(scope="session")
8384
def mysql_registry():
84-
container = (
85-
DockerContainer("mysql:latest")
86-
.with_exposed_ports(3306)
87-
.with_env("MYSQL_RANDOM_ROOT_PASSWORD", "true")
88-
.with_env("MYSQL_USER", POSTGRES_USER)
89-
.with_env("MYSQL_PASSWORD", POSTGRES_PASSWORD)
90-
.with_env("MYSQL_DATABASE", POSTGRES_DB)
91-
)
92-
85+
container = MySqlContainer("mysql:latest")
9386
container.start()
9487

95-
# The log string uses '8.0.*' since the version might be changed as new Docker images are pushed.
96-
log_string_to_wait_for = "/usr/sbin/mysqld: ready for connections. Version: '(\\d+(\\.\\d+){1,2})' socket: '/var/run/mysqld/mysqld.sock' port: 3306" # noqa: W605
97-
waited = wait_for_logs(
98-
container=container,
99-
predicate=log_string_to_wait_for,
100-
timeout=60,
101-
interval=10,
102-
)
103-
logger.info("Waited for %s seconds until mysql container was up", waited)
104-
container_port = container.get_exposed_port(3306)
105-
container_host = container.get_container_host_ip()
88+
# testing for the database to exist and ready to connect and start testing.
89+
import sqlalchemy
90+
engine = sqlalchemy.create_engine(container.get_connection_url(), pool_pre_ping=True)
91+
engine.connect()
10692

10793
registry_config = RegistryConfig(
10894
registry_type="sql",
109-
path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}",
95+
path=container.get_connection_url(),
11096
sqlalchemy_config_kwargs={"echo": False, "pool_pre_ping": True},
11197
)
11298

0 commit comments

Comments
 (0)