Skip to content

NewEngineUnderTest takes a test name, not a testing.TB

Choose a tag to compare

@bw19 bw19 released this 03 Aug 01:14
· 300 commits to main since this release

Test-support change only. engine.NewEngineUnderTest is now keyed by a plain test
name instead of a testing.TB, so a host can stand up an isolated engine under its
own harness — one that has no *testing.T to hand over. A name was all the
constructor ever needed from one.

No schema migrations. No change to dispatch, scheduling, recovery, pool sizing, or
anything else on the production path.

Breaking (test code only)

  • NewEngineUnderTest(t testing.TB) → NewEngineUnderTest(testName string).
    Pass t.Name() from a Go test.
  • Engine.SetTestName is removed. The constructor argument is the isolation key,
    so there is nothing left to override.
  • Startup no longer registers a t.Cleanup shutdown. Teardown is yours:
    defer eng.Shutdown(ctx).
  • The logger default no longer varies by testing.TB type. Every test engine logs
    to stderr at Error (DWARF_TEST_LOG_LEVEL overrides as before); a benchmark or
    fuzz target silences it with SetLogger(slog.New(slog.DiscardHandler)).

Migration

// before
eng := engine.NewEngineUnderTest(t)
eng.SetHost(proxy)
eng.Startup(ctx)

// after
eng := engine.NewEngineUnderTest(t.Name())
defer eng.Shutdown(ctx)
eng.SetHost(proxy)
eng.Startup(ctx)

Engines that must share one isolated database — a multi-replica test — take the
same name. Engines meant to be separate deployments take different names
(t.Name()+"#a", t.Name()+"#b"), which is what SetTestName was for.

Two things to check in your own tests

Where the shutdown defer sits. Registered right after the constructor, it
unwinds last. A test that holds a worker on a channel must release it from a
defer declared below the shutdown one, or the drain waits forever on a worker
that can never return. A t.Cleanup release is worse — it runs after every defer,
including the shutdown. Six fixtures in this repo needed that fix.

An engine you start is now yours to stop. Anything that relied on the old
auto-cleanup leaks its dwarf_peers row and its connections. That is invisible in a
single run and fails the next run in the same process, where the stale rows still
count toward the replica divisor.

Upgrading is still governed by docs/upgrading.md.