Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(weave): Make tests way faster #3908

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test
andrewtruong committed Mar 19, 2025
commit 01cb31bbc11d888b49e8197df18f4644fb29bbc9
33 changes: 30 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -562,9 +562,12 @@ def create_client(
entity = "shawn"
project = "test-project"
db_path = None
# Get worker id for parallel test execution
worker_id = os.environ.get("PYTEST_XDIST_WORKER", "")

if weave_server_flag == "sqlite":
# Get worker id for parallel test execution
if worker_id := os.environ.get("PYTEST_XDIST_WORKER"):
if worker_id:
temp_dir = tempfile.gettempdir()
# Create a unique file-based database for each worker
db_path = f"{temp_dir}/weave_test_{worker_id}_{uuid.uuid4()}.db"
@@ -579,10 +582,34 @@ def create_client(
sqlite_server, DummyIdConverter(), entity
)
elif weave_server_flag == "clickhouse":
# Create unique database names for parallel testing
unique_suffix = f"_{worker_id}_{uuid.uuid4().hex[:8]}" if worker_id else ""
db_management_name = f"db_management{unique_suffix}"
default_db_name = f"default{unique_suffix}"

# Set environment variables to use these database names
os.environ["CLICKHOUSE_DB_MANAGEMENT"] = db_management_name
os.environ["CLICKHOUSE_DEFAULT_DB"] = default_db_name

ch_server = clickhouse_trace_server_batched.ClickHouseTraceServer.from_env()
ch_server.ch_client.command("DROP DATABASE IF EXISTS db_management")
ch_server.ch_client.command("DROP DATABASE IF EXISTS default")
ch_server.ch_client.command(f"DROP DATABASE IF EXISTS {db_management_name}")
ch_server.ch_client.command(f"DROP DATABASE IF EXISTS {default_db_name}")
ch_server._run_migrations()

# Clean up function for Clickhouse databases
def cleanup_ch_dbs():
try:
ch_server.ch_client.command(
f"DROP DATABASE IF EXISTS {db_management_name}"
)
ch_server.ch_client.command(
f"DROP DATABASE IF EXISTS {default_db_name}"
)
except Exception:
pass

request.addfinalizer(cleanup_ch_dbs)

server = TestOnlyUserInjectingExternalTraceServer(
ch_server, DummyIdConverter(), entity
)