Repository navigation
Conversation
…gration test TestIntegration_CreateAdminIfNone_ConcurrentBootstrapOnce_Stress fires 50 barrier-synchronized CreateAdminIfNone callers per round for 10 rounds and requires exactly one winner, no errors and exactly one Administrators-group row after each round. Removing the pg_advisory_xact_lock call, or switching it to pg_try_advisory_xact_lock, makes it fail with 2 to 10 winners in a round. The two-caller test and the stress variant share one helper. Workers only send outcomes over a channel and every assertion runs on the test goroutine, after all workers have finished. The stress variant takes its database from the shared container (testhelpers.RequireMigratedDatabase), and a new integration-only TestMain stops that container, as in internal/config. Closes LeanerCloud#64 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Comment |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Issue #64 asks for a high-fanout version of the admin-bootstrap race test. The existing
TestIntegration_CreateAdminIfNone_ConcurrentBootstrapOnceruns 2 callers × 25 rounds. That matches the production case, but it is the smallest contention that can expose a race.This PR adds no production code change. It only adds the test:
TestIntegration_CreateAdminIfNone_ConcurrentBootstrapOnce_Stress(internal/auth/store_postgres_db_test.go,integrationbuild tag) runs 50 barrier-synchronizedCreateAdminIfNonecallers per round, for 10 rounds. After each round it requires:winners == 1,CountGroupMembers(DefaultAdminGroupID) == 1.requireConcurrentBootstrapOnceplusrunBootstrapRound. Worker goroutines only send abootstrapOutcome{}over a buffered channel. Everyrequire.*call runs on the test goroutine, after all workers of the round have finished, so no worker is still using the pool when a failing test's cleanup closes it. The 2-caller test keeps its parameters (2 × 25) and its assertions, with one change: its context now has a 2-minute timeout instead ofcontext.Background().testhelpers.RequireMigratedDatabase, the shared container from test(config): share one migrated Postgres container across integration tests #1165, instead of starting its own. A new integration-onlyinternal/auth/main_integration_test.goadds aTestMainthat callstesthelpers.TerminateSharedPostgres(), the same asinternal/config/main_integration_test.go.Closes #64
Verification
All of this is local evidence on real Postgres (testcontainers
postgres:16-alpine). Only the new test was run under-tags integration. The machine had a load average of about 11 during these runs.Environment for every command:
AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null.Pass on this branch (unmodified
store_postgres.go):Running it again after the mutation checks below and a
git checkoutofstore_postgres.goalso passed 3/3 (28.98s, 4.52s, 2.61s).Timing came from a temporary instrumented run that was not committed. With a warm shared container, per test:
TRUNCATE users CASCADEreset: about 0.3sThat puts the body at about 4s plus the per-test database drop.
Fail with the race fix reverted. These were local mutations of
internal/auth/store_postgres.go, restored withgit checkoutafterwards:SELECT pg_advisory_xact_lock($1)call (the three-lineifblock),-count=10: 10/10 runs FAIL. Winners in the failing round were 10, 10, 9, 10, 9, 5, 5, 10, 7 and 9. An earlier-count=3run had also failed 3/3, with 7, 2 and 10 winners.MaxConnections. Round 0 sometimes passes while the pool is still warming up, which is one reason the test runs several rounds.SELECT pg_try_advisory_xact_lock($1)with the result still ignored,-count=5: 5/5 runs FAIL, with 2, 8, 8, 10 and 2 winners.Static checks and unit tests:
gocyclowas not needed: no non-test Go files changed.Not run locally:
callers=2, iterations=25.internal/authintegration package was not run.Both are left to the combined-tree run below.
Combined-tree verification. This branch was tested together with six other queued branches on a local, never-pushed tree:
queue/platform@77d116c6= origin/maina14dc8f2plus these heads, merged in this order:Linux, Go 1.26.9,
AWS_CONFIG_FILE=/dev/null AWS_SHARED_CREDENTIALS_FILE=/dev/null AWS_EC2_METADATA_DISABLED=true; Docker Postgres via testcontainers:go build ./...,go vet ./...,go vet -tags integration ./...and the fullgo test -race -short -count=1 ./....--build-tags integration, andgocyclo -over 10is silent on the changed non-test files. These ran atb61a9c30, which differs from77d116c6only by one.gitallowedline on fix/issue-1233.-tags integration -count=1):cmd/cleanup-lambda,internal/analytics,internal/auth,internal/database/postgres/migrationsandinternal/purchase.internal/apipasses, except two tests whose Postgres container didn't start, or whose migrations hit a timeout, under machine load. Rerun alone on the same tree, both pass:TestDeleteManagedPlanByExecutionStatusandTestNotifiedRow_RescheduleDoesNotOverwriteConcurrentCancel.internal/configpasses exceptTestPostgresStoreDB_ResolveStaleRIExchange_ValidatesCloudCheck, which fails the same way on unmodified main (fixed by fix(config): compare resolve checked_at at the database's microsecond precision #1252).TESTCONTAINERS_RYUK_DISABLED=trueto avoid a testcontainers reaper race under load.scripts/setup-git-secrets.shpatterns in a fresh repo with an isolated HOME, found nothing in the changed files, and a planted fake key was flagged.scripts/test-git-secrets-allowlist.sh: 137 PASS, 0 FAIL.Out of scope
internal/authintegration tests still start their own container throughsetupAuthTestDB(RequirePostgresContainerplus a full migration run per test), and so does the 2-caller test. MovingsetupAuthTestDBontoRequireMigratedDatabase, as ci: internal/config integration tests take ~15 min against a 20 min job timeout #982/test(config): share one migrated Postgres container across integration tests #1165 did forinternal/config, would cut that package's integration time a lot. It changes every auth DB test, though, so it belongs in its own issue. TheTestMainadded here is the piece that change would need.s.db.Execmutation. One of the issue's motivating examples is a refactor that runs the INSERT throughs.db.Execinstead oftx.Exec. The advisory lock would still be held by the open transaction, so later callers would still serialize behind it and see the committed admin. That mutation therefore keeps the insert-once guarantee, and neither test would flag it, correctly. Only the lock-removal and try-lock mutations were checked.Maintainer: please mirror the issue's triage labels onto this PR:
impact/internal,type/chore,triaged,priority/p3,severity/low,urgency/eventually,effort/s.🤖 Generated with Claude Code