realtime icon indicating copy to clipboard operation
realtime copied to clipboard

Support pointing ExUnit tenant-DB tests at Multigres and other external servers

Open cuongdo opened this issue 3 months ago • 1 comments

Chore

Describe the chore

Add an opt-in mode to test/support/containers.ex/test/test_helper.exs that lets ExUnit tenant-DB tests connect to an already-running, external Postgres-wire-compatible server, instead of always checking out a per-test supabase/postgres Docker container from the poolboy pool.

New env vars, gated so default behavior is unchanged:

  • TENANT_DB=external — opt in (unset = today's byte-for-byte container-pool behavior).
  • EXTERNAL_TENANT_DB_PORT — no default, fail fast if TENANT_DB=external is set without it. Host stays hardcoded 127.0.0.1 (matches the pre-existing hardcoded host in test/support/generators.ex's tenant_fixture/1 — not something this change touches).

In external mode: skip starting/pulling the container pool entirely, skip CREATE DATABASE/the zero-column existence probe in storage_up!/1, and force max_cases: 1 (all tests share the one external DB, so concurrent DROP SCHEMA realtime CASCADE would collide).

I already have working code for this, but I'm also fine with someone else taking this on, since my Elixir knowledge is limited.

Additional context

Today's per-test container pool assumes the tenant DB is something the suite itself can spin up and throw away — a disposable, single-container Postgres created fresh per test. This chore is for the opposite case: a tenant DB that's separately managed, already running, and shared across the whole run.

Motivating case: compatibility-testing Realtime against Multigres. Swapping POSTGRES_IMAGE to a Multigres image doesn't work, because:

  • It isn't a single lightweight container. The whole cluster is built and started together, spinning that up fresh per-test the way a bare Postgres container is pooled would be far too slow.
  • No ad-hoc CREATE DATABASE. Multigres's gateway exposes one long-lived database, provisioned once outside the test run, not created/dropped per test.
  • It's a separately-managed, already-running system. Cluster lifecycle (build, start, health-check) is its own multi-minute process outside mix test's control — tests need to connect to and share an instance that's already up, serially.

This approach was validated against a live Multigres cluster up through the full test suite: 1756 tests, 16 failures.

Also includes a small unrelated cleanup: making capture_log configurable via CAPTURE_LOG (previously hardcoded true), useful for surfacing crash logs when a test hangs, independent of external-mode.

Opening this per CONTRIBUTING.md's requirement to link an issue/discussion before a PR. Happy to adjust the opt-in mechanism (e.g. a boolean flag instead of a TENANT_DB value) if maintainers prefer something else.

cuongdo avatar Aug 03 '26 14:08 cuongdo

:tada: This issue has been resolved in version 2.124.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket:

realtime-release-bot avatar Aug 07 '26 09:08 realtime-release-bot