Skip to content

Conversation

@shangyian
Copy link
Contributor

@shangyian shangyian commented Dec 31, 2025

Summary

This PR makes several changes to speed up tests from 1h18min to ~20min.

Single Session-Scoped Postgres Container

Instead of creating a new Docker Postgres container for each test module, we now use a single session-scoped container that persists across all test workers. Individual test modules create their own databases within that container. DB creation is fast compared to Docker container startup.

Template Database Approach

This change involves a template database strategy, where we create a template database (template_all_examples) once at session start. This is pre-populated with all examples used for testing (roads, account revenue, dimension links, etc.)

Each test module clones from this template using PostgreSQL's CREATE DATABASE ... TEMPLATE command, which eliminates the expensive API calls to load examples for each test module.

Function-Scoped Database Cloning

For function-scoped fixtures that need isolation:

  • Created func__database fixture that clones from the template for each test function
  • Created func__clean_postgres_container and clean_session fixtures for tests that need a completely empty database (construction tests, seed tests).

Test Plan

Many tests needed adjustment to work with the pre-populated template database:

  • PR has an associated issue: #
  • make check passes
  • make test shows 100% unit test coverage

Deployment Plan

@netlify
Copy link

netlify bot commented Dec 31, 2025

Deploy Preview for thriving-cassata-78ae72 canceled.

Name Link
🔨 Latest commit e3d4953
🔍 Latest deploy log https://app.netlify.com/projects/thriving-cassata-78ae72/deploys/695707ea1bdc920008f1282f

@shangyian shangyian changed the title Speed up unit tests by switching to a single postgres container that … Speed up tests Jan 1, 2026
@shangyian shangyian changed the title Speed up tests Speed up tests significantly Jan 1, 2026
@shangyian shangyian changed the title Speed up tests significantly Speed up tests significantly (75% decrease) Jan 1, 2026
@shangyian shangyian changed the title Speed up tests significantly (75% decrease) Speed up tests Jan 1, 2026
- Switching to a single postgres container that is shared, with separate databases in that container for isolation
- Creating a template postgres db with all examples loaded rather than reloading them with API calls
@shangyian shangyian marked this pull request as ready for review January 2, 2026 00:13
@shangyian shangyian merged commit 481bb3d into DataJunction:main Jan 2, 2026
17 checks passed
@shangyian shangyian deleted the unit-test-speedup branch January 2, 2026 00:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant