Skip to content

Commit 18074a8

Browse files
cookieark7cookieark
andauthored
fix(tests): prevent schema collisions between integration test params (#6072)
Signed-off-by: cookieark <aishwary.kantode@gmail.com> Co-authored-by: cookieark <aishwary.kantode@gmail.com>
1 parent e30fe61 commit 18074a8

1 file changed

Lines changed: 10 additions & 2 deletions

File tree

tests/core/engine_adapter/integration/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from __future__ import annotations
22

3+
import hashlib
34
import os
45
import pathlib
6+
import secrets
57
import sys
68
import typing as t
79
import time
@@ -20,7 +22,7 @@
2022
from sqlmesh.core.engine_adapter import SparkEngineAdapter, TrinoEngineAdapter, AthenaEngineAdapter
2123
from sqlmesh.core.engine_adapter.shared import DataObject
2224
from sqlmesh.core.model.definition import SqlModel, load_sql_based_model
23-
from sqlmesh.utils import random_id
25+
from sqlmesh.utils import ALPHANUMERIC, random_id
2426
from sqlmesh.utils.date import to_ds
2527
from sqlmesh.utils.pydantic import PydanticModel
2628
from tests.utils.pandas import compare_dataframes
@@ -205,7 +207,13 @@ def __init__(
205207
self.mark = mark
206208
self.gateway = gateway
207209
self._columns_to_types = columns_to_types
208-
self.test_id = random_id(short=True)
210+
# The id is appended to schema names, so it has to keep concurrent test params apart
211+
# while staying short: temp table names built from these schemas are already close to
212+
# Postgres's 63 character identifier limit. A tag derived from the param guarantees two
213+
# params never share a schema, and the random part separates concurrent runs and retries.
214+
param_tag = hashlib.sha1(mark.encode()).hexdigest()[:3]
215+
random_part = "".join(secrets.choice(ALPHANUMERIC) for _ in range(5))
216+
self.test_id = f"{param_tag}{random_part}"
209217
self._context: t.Optional[Context] = None
210218
self.is_remote = is_remote
211219
self._schemas: t.List[

0 commit comments

Comments
 (0)