|
21 | 21 | from pytest_lazyfixture import lazy_fixture |
22 | 22 | from testcontainers.core.container import DockerContainer |
23 | 23 | from testcontainers.core.waiting_utils import wait_for_logs |
| 24 | +from testcontainers.mysql import MySqlContainer |
24 | 25 |
|
25 | 26 | from feast import FileSource, RequestSource |
26 | 27 | from feast.data_format import ParquetFormat |
@@ -81,32 +82,17 @@ def pg_registry(): |
81 | 82 |
|
82 | 83 | @pytest.fixture(scope="session") |
83 | 84 | 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") |
93 | 86 | container.start() |
94 | 87 |
|
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() |
106 | 92 |
|
107 | 93 | registry_config = RegistryConfig( |
108 | 94 | registry_type="sql", |
109 | | - path=f"mysql+pymysql://{POSTGRES_USER}:{POSTGRES_PASSWORD}@{container_host}:{container_port}/{POSTGRES_DB}", |
| 95 | + path=container.get_connection_url(), |
110 | 96 | sqlalchemy_config_kwargs={"echo": False, "pool_pre_ping": True}, |
111 | 97 | ) |
112 | 98 |
|
|
0 commit comments