Skip to content

Commit 53a0170

Browse files
committed
ci: Update postgres tests to use test containers
Signed-off-by: Achal Shah <[email protected]>
1 parent 99ef7d2 commit 53a0170

File tree

4 files changed

+41
-24
lines changed

4 files changed

+41
-24
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ The services with containerized replacements currently implemented are:
178178
- Redis
179179
- Trino
180180
- HBase
181+
- Postgres
181182

182183
You can run `make test-python-integration-container` to run tests against the containerized versions of dependencies.
183184

sdk/python/feast/infra/offline_stores/contrib/postgres_repo_configuration.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
PostgreSQLDataSourceCreator,
66
)
77

8-
98
FULL_REPO_CONFIGS = [
109
IntegrationTestRepoConfig(
1110
provider="local",

sdk/python/tests/conftest.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,19 @@ def get_singleton(cls):
217217
if not cls.is_running:
218218
cls.container = (
219219
DockerContainer("postgres:latest")
220-
.with_exposed_ports(5432)
221-
.with_env("POSTGRES_USER", cls.postgres_user)
222-
.with_env("POSTGRES_PASSWORD", cls.postgres_password)
223-
.with_env("POSTGRES_DB", cls.postgres_db)
220+
.with_exposed_ports(5432)
221+
.with_env("POSTGRES_USER", cls.postgres_user)
222+
.with_env("POSTGRES_PASSWORD", cls.postgres_password)
223+
.with_env("POSTGRES_DB", cls.postgres_db)
224224
)
225225

226226
cls.container.start()
227227
log_string_to_wait_for = "database system is ready to accept connections"
228228
waited = wait_for_logs(
229-
container=cls.container, predicate=log_string_to_wait_for, timeout=30, interval=10
229+
container=cls.container,
230+
predicate=log_string_to_wait_for,
231+
timeout=30,
232+
interval=10,
230233
)
231234
logger.info("Waited for %s seconds until postgres container was up", waited)
232235
cls.is_running = True
@@ -247,7 +250,6 @@ def teardown():
247250
return PostgresContainerSingleton
248251

249252

250-
251253
@pytest.fixture(
252254
params=FULL_REPO_CONFIGS, scope="session", ids=[str(c) for c in FULL_REPO_CONFIGS]
253255
)

sdk/python/tests/integration/feature_repos/universal/data_sources/postgres.py

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
from tests.integration.feature_repos.universal.data_source_creator import (
1616
DataSourceCreator,
1717
)
18-
from tests.integration.feature_repos.universal.online_store_creator import OnlineStoreCreator
18+
from tests.integration.feature_repos.universal.online_store_creator import (
19+
OnlineStoreCreator,
20+
)
1921

2022
logger = logging.getLogger(__name__)
2123

@@ -38,24 +40,27 @@ def initialize(cls, project_name: str, *args, **kwargs):
3840
cls.project_name = project_name
3941

4042
if "offline_container" not in kwargs or not kwargs.get(
41-
"offline_container", None
43+
"offline_container", None
4244
):
4345
# If we don't get an offline container provided, we try to create it on the fly.
4446
# the problem here is that each test creates its own container, which basically
4547
# browns out developer laptops.
4648
cls.container = (
4749
DockerContainer("postgres:latest")
48-
.with_exposed_ports(5432)
49-
.with_env("POSTGRES_USER", cls.postgres_user)
50-
.with_env("POSTGRES_PASSWORD", cls.postgres_password)
51-
.with_env("POSTGRES_DB", cls.postgres_db)
50+
.with_exposed_ports(5432)
51+
.with_env("POSTGRES_USER", cls.postgres_user)
52+
.with_env("POSTGRES_PASSWORD", cls.postgres_password)
53+
.with_env("POSTGRES_DB", cls.postgres_db)
5254
)
5355

5456
cls.container.start()
5557
cls.provided_container = False
5658
log_string_to_wait_for = "database system is ready to accept connections"
5759
waited = wait_for_logs(
58-
container=cls.container, predicate=log_string_to_wait_for, timeout=30, interval=10
60+
container=cls.container,
61+
predicate=log_string_to_wait_for,
62+
timeout=30,
63+
interval=10,
5964
)
6065
logger.info("Waited for %s seconds until postgres container was up", waited)
6166
cls.running = True
@@ -75,18 +80,19 @@ def initialize(cls, project_name: str, *args, **kwargs):
7580

7681
@classmethod
7782
def create_data_source(
78-
cls,
79-
df: pd.DataFrame,
80-
destination_name: str,
81-
suffix: Optional[str] = None,
82-
timestamp_field="ts",
83-
created_timestamp_column="created_ts",
84-
field_mapping: Dict[str, str] = None,
83+
cls,
84+
df: pd.DataFrame,
85+
destination_name: str,
86+
suffix: Optional[str] = None,
87+
timestamp_field="ts",
88+
created_timestamp_column="created_ts",
89+
field_mapping: Dict[str, str] = None,
8590
) -> DataSource:
8691

8792
destination_name = cls.get_prefixed_table_name(destination_name)
8893

89-
df_to_postgres_table(cls.offline_store_config, df, destination_name)
94+
if cls.offline_store_config:
95+
df_to_postgres_table(cls.offline_store_config, df, destination_name)
9096

9197
return PostgreSQLSource(
9298
name=destination_name,
@@ -97,7 +103,8 @@ def create_data_source(
97103
)
98104

99105
@classmethod
100-
def create_offline_store_config(cls) -> FeastConfigBaseModel:
106+
def create_offline_store_config(cls) -> PostgreSQLOfflineStoreConfig:
107+
assert cls.offline_store_config
101108
return cls.offline_store_config
102109

103110
@classmethod
@@ -106,6 +113,7 @@ def get_prefixed_table_name(cls, suffix: str) -> str:
106113

107114
@classmethod
108115
def create_online_store(cls) -> Dict[str, str]:
116+
assert cls.container
109117
return {
110118
"type": "postgres",
111119
"host": "localhost",
@@ -152,7 +160,14 @@ def create_data_source(
152160
field_mapping: Dict[str, str] = None,
153161
) -> DataSource:
154162

155-
return PostgresSourceCreatorSingleton.create_data_source(df, destination_name, suffix, timestamp_field, created_timestamp_column, field_mapping)
163+
return PostgresSourceCreatorSingleton.create_data_source(
164+
df,
165+
destination_name,
166+
suffix,
167+
timestamp_field,
168+
created_timestamp_column,
169+
field_mapping,
170+
)
156171

157172
def create_offline_store_config(self) -> FeastConfigBaseModel:
158173
return PostgresSourceCreatorSingleton.create_offline_store_config()

0 commit comments

Comments
 (0)