Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

perf(tests): turn on parallelism in backend/tests (#21354)

Danny Xue2d6c6cb6ae9
diff --git a/backend/tests/account_email_validation_test.go b/backend/tests/account_email_validation_test.go
index 6dc773dd2f..7bc3efce91 100644
--- a/backend/tests/account_email_validation_test.go
+++ b/backend/tests/account_email_validation_test.go
@@ -22,7 +22,9 @@ func getCurrentWorkspace(ctx context.Context, t *testing.T, ctl *controller) str
}
func TestServiceAccountEmailValidation(t *testing.T) {
+ t.Parallel()
t.Run("create rejects invalid generated email", func(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -43,6 +45,7 @@ func TestServiceAccountEmailValidation(t *testing.T) {
})
t.Run("get rejects malformed resource email", func(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -59,7 +62,9 @@ func TestServiceAccountEmailValidation(t *testing.T) {
}
func TestWorkloadIdentityEmailValidation(t *testing.T) {
+ t.Parallel()
t.Run("create rejects invalid generated email", func(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -80,6 +85,7 @@ func TestWorkloadIdentityEmailValidation(t *testing.T) {
})
t.Run("get rejects malformed resource email", func(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/approval_test.go b/backend/tests/approval_test.go
index 8f74ebcce5..12d77625c0 100644
--- a/backend/tests/approval_test.go
+++ b/backend/tests/approval_test.go
@@ -303,7 +303,9 @@ func TestApprovalFindingRerunsPlanCheckForStaleApprovalInputVersion(t *testing.T
a.Equal(v1pb.PlanCheckRun_DONE, checkResp.Msg.Status)
}
+//nolint:tparallel // Subtests share one server lifecycle.
func TestApprovalActionRejectsStaleApprovalInputVersion(t *testing.T) {
+ t.Parallel()
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/data_source_test.go b/backend/tests/data_source_test.go
index 4bf9c143b6..7029a91200 100644
--- a/backend/tests/data_source_test.go
+++ b/backend/tests/data_source_test.go
@@ -12,6 +12,7 @@ import (
)
func TestDataSource(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -160,6 +161,7 @@ func TestDataSource(t *testing.T) {
}
func TestDataSourceValidateOnly(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/environment_test.go b/backend/tests/environment_test.go
index 96d5cd2618..46a124175b 100644
--- a/backend/tests/environment_test.go
+++ b/backend/tests/environment_test.go
@@ -13,6 +13,7 @@ import (
)
func TestDatabaseEnvironment(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/login_attempt_collision_test.go b/backend/tests/login_attempt_collision_test.go
index 9a5c4af382..1fd7d3561d 100644
--- a/backend/tests/login_attempt_collision_test.go
+++ b/backend/tests/login_attempt_collision_test.go
@@ -22,6 +22,7 @@ import (
// buckets: rows sharing an identity (other kind) or sharing a kind (other
// identity) must be untouched by claims, clears, and purges on a neighbor.
func TestCollision_LoginAttempt(t *testing.T) {
+ t.Parallel()
ctx := context.Background()
container := testcontainer.GetTestPgContainer(ctx, t)
t.Cleanup(func() { container.Close(ctx) })
diff --git a/backend/tests/login_audit_test.go b/backend/tests/login_audit_test.go
index 164ca40583..a91db36f6b 100644
--- a/backend/tests/login_audit_test.go
+++ b/backend/tests/login_audit_test.go
@@ -22,6 +22,7 @@ import (
)
func TestLoginFailureLockout(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -201,7 +202,10 @@ func TestLoginFailureLockout(t *testing.T) {
// AuditLogService/SearchAuditLogs. Downstream consumers (SIEMs, compliance
// tooling, `docker logs | grep log_type:audit`) depend on this shape being
// stable across releases — changes here are user-visible breaking changes.
+//
+//nolint:tparallel // Subtests share one server lifecycle.
func TestAuditLogFormat(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/main_test.go b/backend/tests/main_test.go
index 048480a133..a17356f9c7 100644
--- a/backend/tests/main_test.go
+++ b/backend/tests/main_test.go
@@ -3,6 +3,9 @@ package tests
import (
"context"
"testing"
+
+ storepb "github.com/bytebase/bytebase/backend/generated-go/store"
+ webhookplugin "github.com/bytebase/bytebase/backend/plugin/webhook"
)
func TestMain(m *testing.M) {
@@ -30,5 +33,14 @@ func startMain(ctx context.Context, m *testing.M) (int, error) {
externalPgHost = pgContainer.host
externalPgPort = pgContainer.port
+ // Seeded once here, before any test starts, and never mutated afterwards:
+ // ValidateWebhookURL reads this map without synchronization, and the tests
+ // that add webhooks run in parallel. A test that set and deleted its own
+ // entry would be a concurrent map write against those readers, which is
+ // fatal to the process rather than merely racy.
+ for _, webhookType := range []storepb.WebhookType{storepb.WebhookType_SLACK, storepb.WebhookType_DINGTALK} {
+ webhookplugin.TestOnlyAllowedDomains[webhookType] = []string{"127.0.0.1", "localhost", "[::1]"}
+ }
+
return m.Run(), nil
}
diff --git a/backend/tests/metrics_test.go b/backend/tests/metrics_test.go
index 2551031dd2..7deeea8a27 100644
--- a/backend/tests/metrics_test.go
+++ b/backend/tests/metrics_test.go
@@ -16,6 +16,7 @@ import (
)
func TestCollisionMetricsLicenseSeats(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/pg_sdl_rollout_test.go b/backend/tests/pg_sdl_rollout_test.go
index 51843704cd..97198c6117 100644
--- a/backend/tests/pg_sdl_rollout_test.go
+++ b/backend/tests/pg_sdl_rollout_test.go
@@ -23,7 +23,10 @@ type sdlRolloutResult struct {
// TestPgSDLRollout tests PostgreSQL SDL rollout workflow end-to-end.
// This test focuses on verifying the overall SDL rollout workflow works correctly.
// Detailed logic tests for specific SDL operations should be in backend/plugin/schema/pg tests.
+//
+//nolint:tparallel // Subtests share one server lifecycle.
func TestPgSDLRollout(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
diff --git a/backend/tests/project_instance_compat_extras_test.go b/backend/tests/project_instance_compat_extras_test.go
index 272b6681f0..ea58b4b98c 100644
--- a/backend/tests/project_instance_compat_extras_test.go
+++ b/backend/tests/project_instance_compat_extras_test.go
@@ -22,6 +22,7 @@ import (
// project-scoped database name for a database on a project instance and
// rejects cross-project and workspace-form names for the same database.
func TestProjectInstanceExport(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -102,6 +103,7 @@ func TestProjectInstanceExport(t *testing.T) {
// canonical project-scoped database name for databases on a project instance
// and reject cross-project references.
func TestProjectInstanceSavedQuery(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -169,6 +171,7 @@ func TestProjectInstanceSavedQuery(t *testing.T) {
// project-instance database work inside the owning project and are rejected
// across projects.
func TestProjectInstanceAccessGrant(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -246,6 +249,7 @@ func TestProjectInstanceAccessGrant(t *testing.T) {
// invalid members with zero side effects, and retained workspace batch
// behavior.
func TestBatchSyncInstancesCompatibility(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/project_test.go b/backend/tests/project_test.go
index 97154eca51..3e1bbdf838 100644
--- a/backend/tests/project_test.go
+++ b/backend/tests/project_test.go
@@ -11,7 +11,9 @@ import (
v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
)
+//nolint:tparallel // Subtests share one server lifecycle.
func TestArchiveProject(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/review_config_audit_test.go b/backend/tests/review_config_audit_test.go
index 34ee29e29a..ee69319517 100644
--- a/backend/tests/review_config_audit_test.go
+++ b/backend/tests/review_config_audit_test.go
@@ -13,6 +13,7 @@ import (
)
func TestReviewConfigAuditLog(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/schema_update_test.go b/backend/tests/schema_update_test.go
index 9d745d9d2f..22c3302bb6 100644
--- a/backend/tests/schema_update_test.go
+++ b/backend/tests/schema_update_test.go
@@ -113,7 +113,9 @@ func TestSchemaAndDataUpdate(t *testing.T) {
a.Equal(v1pb.Changelog_DONE, getResp.Msg.Status)
}
+//nolint:tparallel // Subtests share one server lifecycle.
func TestGetLatestSchema(t *testing.T) {
+ t.Parallel()
tests := []struct {
name string
dbType storepb.Engine
diff --git a/backend/tests/sql_dml_table_scope_test.go b/backend/tests/sql_dml_table_scope_test.go
index ade6c4c293..a728c0ad03 100644
--- a/backend/tests/sql_dml_table_scope_test.go
+++ b/backend/tests/sql_dml_table_scope_test.go
@@ -193,7 +193,10 @@ func TestSQLEditorTableScopedDML(t *testing.T) {
//
// Postgres is required for the same reason the base test documents: it is a
// "newACL" engine, so DML/DDL statements reach the ACL at all.
+//
+//nolint:tparallel // Subtests share one server lifecycle.
func TestSQLEditorTableScopedDMLEdgeCases(t *testing.T) {
+ t.Parallel()
// Not t.Parallel(): the subtests share one server/instance/database and each
// rewrites the project IAM policy, so they must run serially (not in parallel
// with each other). The whole test still runs alongside other test binaries.
diff --git a/backend/tests/sql_service_audit_test.go b/backend/tests/sql_service_audit_test.go
index 5b654ddca4..33ca536392 100644
--- a/backend/tests/sql_service_audit_test.go
+++ b/backend/tests/sql_service_audit_test.go
@@ -11,6 +11,7 @@ import (
)
func TestAdminExecuteAuditLog(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/subscription_test.go b/backend/tests/subscription_test.go
index ba57402a1a..b549b94e2f 100644
--- a/backend/tests/subscription_test.go
+++ b/backend/tests/subscription_test.go
@@ -10,6 +10,7 @@ import (
)
func TestSubscription(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/task_run_cancel_scope_test.go b/backend/tests/task_run_cancel_scope_test.go
index e63540dbed..fcf70cd2d9 100644
--- a/backend/tests/task_run_cancel_scope_test.go
+++ b/backend/tests/task_run_cancel_scope_test.go
@@ -23,6 +23,7 @@ import (
// rights in one environment reach a task run in another environment of the same
// project — test-environment rights killing a production migration.
func TestBatchCancelTaskRuns_RejectsTaskRunFromAnotherStage(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
diff --git a/backend/tests/task_run_idempotent_test.go b/backend/tests/task_run_idempotent_test.go
index 945f95ae27..7ab1077507 100644
--- a/backend/tests/task_run_idempotent_test.go
+++ b/backend/tests/task_run_idempotent_test.go
@@ -18,6 +18,7 @@ import (
// TestBatchRunTasks_Idempotent verifies that BatchRunTasks is idempotent and safe for concurrent calls.
// This test covers both sequential double-clicks and concurrent requests scenarios.
func TestBatchRunTasks_Idempotent(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -162,6 +163,7 @@ func TestBatchRunTasks_Idempotent(t *testing.T) {
}
func TestBatchRunTasks_ConcurrentSkipCannotBothWin(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
@@ -317,6 +319,7 @@ func TestBatchRunTasks_ConcurrentSkipCannotBothWin(t *testing.T) {
}
func TestBatchRunTasks_RejectsSkippedTasks(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/transaction_mode_test.go b/backend/tests/transaction_mode_test.go
index 54c4226baa..92b943e08c 100644
--- a/backend/tests/transaction_mode_test.go
+++ b/backend/tests/transaction_mode_test.go
@@ -15,7 +15,10 @@ import (
)
// TestTransactionMode tests the configurable transaction mode feature across different database engines.
+//
+//nolint:tparallel // Each subtest drives one engine container through both transaction modes in order.
func TestTransactionMode(t *testing.T) {
+ t.Parallel()
ctx := context.Background()
tests := []struct {
diff --git a/backend/tests/user_test.go b/backend/tests/user_test.go
index 8cc31387dd..8a274836ef 100644
--- a/backend/tests/user_test.go
+++ b/backend/tests/user_test.go
@@ -18,6 +18,7 @@ import (
)
func TestDeleteUser(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -128,6 +129,7 @@ func TestDeleteUser(t *testing.T) {
// occupying a seat even though its IAM binding lingers, while a pending member
// (in IAM, no principal) still counts.
func TestBatchGetUsers(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -164,6 +166,7 @@ func TestBatchGetUsers(t *testing.T) {
}
func TestSeatCountExcludesDeletedPrincipal(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -215,6 +218,7 @@ func TestSeatCountExcludesDeletedPrincipal(t *testing.T) {
// workspace can still add a seat-neutral member (service account / workload
// identity) to its IAM, while adding another end user remains blocked.
func TestSeatLimitAllowsServiceAccountWhenOverLimit(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -308,6 +312,7 @@ func TestSeatLimitAllowsServiceAccountWhenOverLimit(t *testing.T) {
// workspace is at the limit — closing the delete-bound-user, refill, undelete
// loophole. Undelete is still allowed when a seat is free.
func TestSeatLimitGuardsUndeleteOfBoundUser(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -386,6 +391,7 @@ func TestSeatLimitGuardsUndeleteOfBoundUser(t *testing.T) {
}
func TestUpdateUserEmail(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
@@ -651,6 +657,7 @@ func TestUpdateUserEmail(t *testing.T) {
}
func TestGetCurrentUser_ServiceAccount(t *testing.T) {
+ t.Parallel()
a := require.New(t)
ctx := context.Background()
ctl := &controller{}
diff --git a/backend/tests/webhook_test.go b/backend/tests/webhook_test.go
index bb7d793a89..1e04eb5bb2 100644
--- a/backend/tests/webhook_test.go
+++ b/backend/tests/webhook_test.go
@@ -18,9 +18,7 @@ import (
"github.com/stretchr/testify/require"
"google.golang.org/protobuf/types/known/fieldmaskpb"
- storepb "github.com/bytebase/bytebase/backend/generated-go/store"
v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
- webhookplugin "github.com/bytebase/bytebase/backend/plugin/webhook"
)
// webhookCollector collects webhook requests for testing.
@@ -134,13 +132,13 @@ func parseSlackWebhook(body []byte) (title, description string, err error) {
}
// TestWebhookIntegration tests webhook functionality.
+//
+//nolint:tparallel // Subtests share one server and one webhook collector.
func TestWebhookIntegration(t *testing.T) {
- // Allow localhost for testing
- webhookplugin.TestOnlyAllowedDomains[storepb.WebhookType_SLACK] = []string{"127.0.0.1", "localhost", "[::1]"}
- defer func() {
- // Clean up after test
- delete(webhookplugin.TestOnlyAllowedDomains, storepb.WebhookType_SLACK)
- }()
+ t.Parallel()
+ // Localhost is allowed for SLACK and DINGTALK by TestMain, once, for the
+ // whole package. Do not set it here: ValidateWebhookURL reads that map
+ // unsynchronized from every parallel test that adds a webhook.
ctx := context.Background()
ctl := &controller{}
@@ -772,10 +770,6 @@ func TestWebhookIntegration(t *testing.T) {
_, _ = w.Write([]byte(`{"errcode":0}`))
}))
defer dingtalkServer.Close()
- webhookplugin.TestOnlyAllowedDomains[storepb.WebhookType_DINGTALK] = []string{"127.0.0.1", "localhost", "[::1]"}
- t.Cleanup(func() {
- delete(webhookplugin.TestOnlyAllowedDomains, storepb.WebhookType_DINGTALK)
- })
_, err = ctl.projectServiceClient.AddWebhook(ctx, connect.NewRequest(&v1pb.AddWebhookRequest{
Project: project.Name,
Webhook: &v1pb.Webhook{
diff --git a/docs/design/backend-test-execution-time.md b/docs/design/backend-test-execution-time.md
index cf5c66888c..84750d4839 100644
--- a/docs/design/backend-test-execution-time.md
+++ b/docs/design/backend-test-execution-time.md
@@ -13,9 +13,12 @@ is the point.
## Measurements
-One local pass of `go test -p=8 -json ./backend/...` on 20 vCPU / 31 GB, with
-warm build and image caches, finishes in **14 m 19 s**. Individual package wall
-times sum to **3180 s**, so packages overlap about 3.7×.
+Everything below is one local pass of `go test -p=8 -json ./backend/...` on
+20 vCPU / 31 GB with warm build and image caches. **The run this design started
+from finished in 14 m 19 s**, with individual package wall times summing to
+**3180 s**, so packages overlapped about 3.7×. Those are the numbers the efforts
+were sized against; see "Where it stands now" for what the same command costs
+today.
Per-operation costs are means of 5 sequential runs:
@@ -61,41 +64,79 @@ The two other expensive packages have to be read differently:
story here. Its container starts in 14 s. The other 273 s is DDL work against
a real Oracle.
+### Where it stands now
+
+Same command, same box, with efforts 1, 2, 6 and 7 partly landed: **272 s**
+(4 m 32 s), package walls summing to 736 s and overlapping 2.7×. Every package
+passes.
+
+| Package | Then | Now | What moved it |
+| --- | ---: | ---: | --- |
+| `backend/tests` | 635 s | 174 s | effort 1, then effort 2's `t.Parallel()` |
+| `backend/api/v1` | 540 s | 43 s | #21349, a shared Postgres — not this design |
+| `backend/store` | 459 s | 12 s | effort 2, both steps |
+| `backend/plugin/schema/oracle` | 315 s | 78 s | #21344 goldens, #21351 shared container |
+| `backend/component/review` | 282 s | 17 s | #21349 |
+| `backend/migrator` | 90 s | <2 s | effort 6, by deletion |
+
+Two rows are worth reading twice. `api/v1` fell 12× without anyone writing a
+fake, which removes the wall-clock argument for effort 6 — the case for seams
+there is now about what the tests say, not what they cost. And
+`plugin/schema/*` as a whole went from 475 s to 164 s, `plugin/db/*` from 339 s
+to 145 s, which shrinks effort 7 from the largest item here to a middling one.
+
### The floor
-`backend/plugin/...` costs 866 s across 69 packages, and splits by who owns the
-code: `plugin/schema/*` is 475 s in 6 packages, `plugin/db/*` is 339 s in 18.
-The other 45 packages — pure parser and advisor tests, no containers — come to
-51 s. Parsing is not what costs; engines are.
+`backend/plugin/...` cost 866 s across 69 packages at the start, and split by
+who owns the code: `plugin/schema/*` was 475 s in 6 packages, `plugin/db/*`
+339 s in 18. The other 45 packages — pure parser and advisor tests, no
+containers — came to 51 s. Parsing is not what costs; engines are. Today the
+same 70 packages come to 358 s.
What any of this buys follows one rule:
```
-wall ≈ max( slowest single package , sum of package walls ÷ 3.7 )
+wall ≈ max( slowest single package , sum of package walls ÷ overlap )
```
-It reproduces the measured run: `max(635, 3180 ÷ 3.7)` is 859 s, against an
-actual 859 s. Treat the 3.7 as an observed property of this schedule, not a
-constant — it will drift as package times change.
+It reproduced the starting run — `max(635, 3180 ÷ 3.7)` is 859 s against an
+actual 859 s — and it reproduces the current one: `max(174, 736 ÷ 2.7)` is
+273 s against an actual 272 s. Treat the overlap factor as an observed property
+of a given schedule, not a constant.
-`backend/tests` at 635 s is the slowest package. Fixing the four serial packages
-makes the run floor-bound on it almost immediately, so everything after that has
-to come out of `backend/tests` itself. Working through the efforts below should
-land the local pass around 7.5 minutes.
+**The gate has moved, and that is the most important thing on this page.** The
+run used to be bound by its slowest package, so only `backend/tests` was worth
+attacking. It is now bound by the sum term: 736 s of work over an overlap of
+2.7, with the slowest package at 174 s and nowhere near binding. Every second
+removed anywhere now buys about 0.37 s of wall, and no single package is the
+gate. That makes the remaining efforts additive rather than a queue behind one
+package — and it makes work outside `backend/tests` worth doing again.
## Design
-Six efforts, ordered by payoff per unit of work. Two have moved since this was
-written, and the numbering is kept through both so existing references resolve:
-effort 3 — a checkout pool for the 104 `provisionPgInstance` callers — is
-dropped, and effort 6 was rescoped and now runs ahead of effort 2 for `api/v1`.
-
-Efforts 1, 4 and 5 all target `backend/tests`. Their figures are fixture cost
-inside a package that runs 3.7× parallel, and effort 1's saving sits inside
-effort 4's, so they do not simply add. Together they should take it from 635 s
-of wall clock to roughly 450 s: dropping effort 3 leaves its 450 s of container
-time in place, which is about 120 s of wall at that compression, on top of the
-330 s the four efforts were originally worth.
+Six efforts. The numbering is the order they were written in, kept so existing
+references resolve, and it is no longer the order of payoff — effort 3, a
+checkout pool for the 104 `provisionPgInstance` callers, is dropped outright, and
+four of the rest have been re-sized since. **Read the sizing line at the top of
+each section, not its position.**
+
+What changed is that effort 2's second step overtook everything else. Adding
+`t.Parallel()` to 34 tests took `backend/tests` from 615 s to a median 173 s on
+its own — more than efforts 1, 4 and 5 together were ever projected to buy — and
+by making the run sum-bound rather than bound by one package it changed what the
+others are worth. Efforts 4, 6 and 7 deflated: their costs now overlap, or were
+already collected by work that landed outside this design. Effort 5 did not,
+because deleting a test removes work instead of moving it.
+
+The standing order, by what is left rather than by number:
+
+| | Effort | Worth |
+| --- | --- | --- |
+| 1 | 5, drop the duplicated MySQL bodies | ~320 s of work, ~2 min of suite wall |
+| 2 | `TestWebhookIntegration` | 148 s in one test, now `backend/tests`'s floor |
+| 3 | 7, engine conformance to omni | 164 s, behind a large ownership blocker |
+| 4 | 6, seams instead of containers | seconds; do it for the tests, not the clock |
+| 5 | 4, isolate per project | a memory ceiling, not a speed play |
### [✓] 1. Close idle connections before shutting the server down
@@ -205,8 +246,71 @@ Peak concurrent connections to the shared container is 38 against Postgres's
default 100, at `-parallel=20`. A runner with many more cores should have that
re-measured before it is trusted.
+**Step 2 again, in `backend/tests`, and this is where the package was hiding its
+time.** 175 of its 209 tests already called `t.Parallel()`. The other 34 never
+did, and they summed to **483.7 s — 79% of the package's 614.7 s wall**, running
+strictly one at a time, because Go defers parallel tests to the end and runs
+everything else back to back. The 175 that did were compressing 1717.7 s into
+about 131 s, a 13× overlap. The machinery was already there; a fifth of the
+tests were not using it.
+
+Adding `t.Parallel()` to those 34 — one line each, no other change — takes the
+package from **614.7 s to a median 173 s**, over ten runs spanning 155–236 s
+with no failures. The spread is real: twenty concurrent servers is a noisy
+schedule, and the worst run is still 2.6× better than the best serial one.
+
+Almost nothing structural was in the way. 32 of the 34 boot a server, and each
+already gets its own server, workspace and database, so there is nothing to
+share. **One exception, and it is the interesting one:**
+`webhook.TestOnlyAllowedDomains` is a plain map in `plugin/webhook` that
+`TestWebhookIntegration` wrote and deleted, while `ValidateWebhookURL` reads it
+unsynchronized on behalf of every other test that adds a webhook — and two of
+those were already parallel. Concurrent map access is fatal to the process, not
+merely racy. `TestMain` now seeds it once for SLACK and DINGTALK and nothing
+mutates it afterwards.
+
+The lesson generalizes past this one map: **grepping the package for shared state
+is not enough, because the shared state can live in the package under test.** A
+`^var ` sweep of `backend/tests` finds `nextPort` and friends and reports all
+clear. What it cannot see is a test reaching into another package's global. When
+turning parallelism on, follow the writes out of the test package as well. Every
+piece of package-level state is already guarded — `nextPort` and
+`nextDatabaseNumber` behind `mu`, `externalPgHost`/`Port` written once in
+`TestMain` and read-only thereafter — and the package has no `t.Setenv` or
+`t.Chdir` anywhere, either of which would panic under `t.Parallel()`. Of the 34,
+exactly one contains a `time.Sleep` and it is inside a comment:
+`waitForWebhookCount` replaced it with a poll-until-deadline. The two explicit
+deadlines are 5-minute context timeouts against tests that run in about ten
+seconds.
+
+Ten of the 34 have subtests, and `tparallel`'s all-or-nothing rule forces a
+choice on each. Two of them — the account email validation pair — boot a server
+*inside every subtest*, so their subtests are independent and now run parallel
+too. The other eight boot one server in the parent and drive it through the
+subtests in order, which is `backend/tests`'s existing
+`//nolint:tparallel // Subtests share one server lifecycle.` case; each now
+carries that directive with its own reason. Note what this does not cost:
+the parent stays parallel with the rest of the package either way, and that is
+where the entire saving came from. Making `TestTransactionMode`'s four engine
+subtests parallel would buy nothing, because the package floor is
+`TestWebhookIntegration`, not the sum of everything else.
+
+**`TestWebhookIntegration` is now the package floor.** At 148 s it is most of the
+173 s, and the rest of the package finishes around it. It is the one place left
+in `backend/tests` where a single test is worth attacking on its own.
+
### 4. Isolate per project, not per workspace
+**Re-sized: about 7 s of wall, not 362 s.** The 362 s below is real work — 207
+boots at 703 ms up and, after effort 1, ~1 ms down — but effort 2's step 2 made
+it overlap. Spread across twenty workers it is worth single-digit seconds of
+wall clock, and the run is no longer bound by this package anyway.
+
+What survives is a resource argument, not a speed one: twenty concurrent servers
+is what sets the memory ceiling on how far `-parallel` can go, and one server for
+the whole package would lift it. Do this when a runner cannot take the
+concurrency, not to buy time. The original sizing follows.
+
**362 s of fixture time inside `backend/tests`.**
Every test there gets its own server, and therefore its own workspace: a
@@ -244,6 +348,11 @@ the repo, 24 subtests behind one boot with several fixed sleeps.
the rest is the duplicated test bodies. `TestSQLReviewForMySQL` costs 52.7 s
where `TestSQLReviewForPostgreSQL` costs 17.9 s for the same assertion.
+Unlike effort 4, this one did not deflate. Deleting a test removes work rather
+than moving it, and the run is now bound by the sum term, so the 320 s converts
+at the whole-run rate of about 0.37 s of wall per second removed — roughly two
+minutes off the suite. That makes this the largest remaining item on the page.
+
Two packages may hold a real database, and no others. `backend/store` is where a
metadata query is asserted against one, and `backend/tests` is the only package
that boots a server. Everywhere else — `api/v1` above all — the handler's
@@ -280,11 +389,19 @@ Three keep their engine. Each needs a comment saying why:
### 6. Seams instead of containers
-**822 s of wall clock, 611 s of it container starts**, after `migrator` was
-settled by deletion below. Effort 5 confines a real metadata Postgres to
-`store` and `tests`; `api/v1` and `component/review` are not on that list and
-start 141 containers between them. `backend/api/mcp` is the proof this is
-livable: 168 tests in 39.5 s, 16 of its 18 files containerless.
+**Re-sized: the seconds are already gone, the argument is not.** This section
+was written against 822 s of wall clock, 611 s of it container starts. #21349
+then gave `api/v1`, `component/review`, `auth`, `oauth2`, `lsp` and `mcp` a
+shared Postgres through `testcontainer.MetadataMain`, and those two packages
+went to 43 s and 17 s without a single fake being written. All six now sit within
+a couple of seconds of the 6.9 s floor that a package holding one container
+cannot go below, and `api/v1` is 43 s of which about 36 s is its own tests.
+
+So do this for what the tests say, not what they cost. A container in `api/v1`
+still buys a `*store.Store` that the assertions never look at, and effort 5 still
+says the metadata database belongs in `store` and `tests`. The classification
+below stands; only the payoff line has changed. `backend/api/mcp` remains the
+proof it is livable: 168 tests in 19 s, 16 of its 18 files containerless.
Effort 2 declined a fake store on two grounds, and both fail here. `api/v1` is
not testing its API — `mcp_info_test.go` calls `service.GetMCPInfo` as a Go
@@ -389,15 +506,20 @@ the 27 `TestCollision*` and `TestClaim*` tests where they are —
### 7. Engine conformance to omni
-**475 s of package wall time, and the largest change here.** The
-`plugin/schema/*` packages assert engine fidelity: generate DDL, apply it to a
-real engine, dump it back, compare. That belongs to omni.
+**Re-sized: 164 s of package wall time, no longer the largest change here.**
+#21344 replaced Oracle's migration round-trip with recorded goldens and #21351
+gave each engine package one shared container, taking `plugin/schema/*` from
+475 s to 164 s and Oracle from 315 s to 78 s. The ownership argument is
+unaffected — these tests still assert engine fidelity, which is omni's — but the
+port now buys 164 s, not 475 s, against the same large blocker described below.
The blocker is that the round-trip is expressed in Bytebase's metadata proto
(`storepb`, `plugin/schema`, `store/model`), so omni must own the metadata model
-first. The ownership split above is the plan: all 475 s of `plugin/schema/*`
-moves, of which Oracle alone is 315 s; all 339 s of `plugin/db/*` stays, because
-that is our driver.
+first. The ownership split above is the plan: all of `plugin/schema/*` moves,
+all of `plugin/db/*` stays, because that is our driver. The figures in the rest
+of this section — 475 s, 315 s for Oracle, 339 s for `plugin/db/*` — are the
+pre-#21351 ones the analysis was done against; the split they describe is
+unchanged, the totals are now 164 s and 145 s.
For most engines the metadata model is not the near blocker — omni has no engine
to move to. It ships a parser and AST for Oracle and for MSSQL and nothing more,