Skip to content

fix(test): serialize harness client cache under parallel integration tests - #289

Merged
adlerhurst merged 3 commits into
mainfrom
cursor/fix-harness-parallel-test-race-3d00
Jun 15, 2026
Merged

fix(test): serialize harness client cache under parallel integration tests#289
adlerhurst merged 3 commits into
mainfrom
cursor/fix-harness-parallel-test-race-3d00

Conversation

@adlerhurst

@adlerhurst adlerhurst commented Jun 15, 2026

Copy link
Copy Markdown
Member

Summary

Fixes a flaky fatal error: concurrent map writes panic in go-integration-test-postgres when parallel subtests share one integration test Harness.

The harness lazily caches API clients and fake security sources in maps (apiClients, fakeSecuritySources) without synchronization. Parallel subtests (for example in flow definition tests) can write to those maps concurrently and crash the test binary.

This change adds a mutex on Harness and serializes map initialization and writes in EnsureAPIClient, EnsureAnonymousAPIClient, and the fake security source helpers.

No product behavior change — test harness only.

Validation

  • CI go-integration-test-postgres (primary proof)
  • go build ./...

Release notes / changeset

No changeset required — no public npm package files changed.

Notes

Extracted from #287 so the lifecycle storage work stays focused on ADR 024 / Fixes #267.

Open in Web Open in Cursor 

…ests

Co-authored-by: Silvan <adlerhurst@users.noreply.github.com>
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
nextgen Error Error Jun 15, 2026 1:04pm

Request Review

@adlerhurst
adlerhurst marked this pull request as ready for review June 15, 2026 12:07
Copilot AI review requested due to automatic review settings June 15, 2026 12:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses a flaky fatal error: concurrent map writes panic in Go integration tests by making the shared integration test Harness safe to use across parallel subtests. It does so by introducing a mutex on the harness and serializing lazy cache initialization for API clients and fake security sources.

Changes:

  • Add a sync.Mutex to Harness to guard shared mutable state.
  • Serialize initialization/writes for apiClients, anonymousClient, fakeSecuritySources, and anonymousSecuritySource in the harness helper methods.
  • Add an empty changeset documenting a test-only fix.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
internal/api/integration_test/helpers/harness.go Adds a mutex to the shared integration test harness.
internal/api/integration_test/helpers/client.go Uses the harness mutex to guard cached client/security-source creation.
.changeset/fix-harness-parallel-test-race.md Empty changeset for a test-only harness concurrency fix.

Comment thread internal/api/integration_test/helpers/client.go Outdated
Comment thread internal/api/integration_test/helpers/client.go Outdated
Co-authored-by: Silvan <adlerhurst@users.noreply.github.com>
@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown

@adlerhurst must be a member of the zitadel team on Vercel to deploy.
- Click here to add @adlerhurst to the team.
- If you initiated this build, request access.

Learn more about collaboration on Vercel and other options here.

@adlerhurst
adlerhurst merged commit 637914f into main Jun 15, 2026
17 of 18 checks passed
@adlerhurst
adlerhurst deleted the cursor/fix-harness-parallel-test-race-3d00 branch June 15, 2026 13:12
adlerhurst added a commit that referenced this pull request Jul 20, 2026
…#287)

<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
## Summary

Fixes #267

Align user/team storage with [ADR
024](docs/adrs/024-user-team-lifecycle-ownership.md):

- Replace `users.team_id` with nullable `lifecycle_owner_team_id` (NULL
= self-owned, set = team-owned)
- Add `users.status` (active/suspended/deactivated/pending_purge)
- Add `team_memberships` N:N table with membership status
- Add `teams.status` and lifecycle `Deactivate` methods on team/user
repositories
- Remove `ON DELETE CASCADE` on the user/team graph; lifecycle deletes
via repository policy
- Backfill existing `team_id` data in migration
`000011_user_team_lifecycle.sql` (Postgres + Spanner)

## Validation

- `go test -tags=postgres_integration
./internal/storage/database/repository/... -count=1`
- `corepack pnpm run check -- --only go`

## Release notes / changeset

`.changeset/user-team-lifecycle-storage.md` — `@zitadel/server` patch:
align user/team lifecycle storage with ADR 024.

## Notes

Closes #267

Branch merged with `main` before review fixes. Harness mutex fix landed
via #289.

Migration backfill maps legacy `users.team_id` to
`lifecycle_owner_team_id` as a conservative alpha default (old schema
required a team context, so self-serve vs enterprise provenance cannot
be distinguished retroactively). New creates stay self-owned unless
`LifecycleOwnerTeamID` is set.

Acceptance checklist:
- [x] Self-owned user survives team deletion
- [x] Team-owned user deactivated when owning team deleted
- [x] Deleting a user does not cascade-delete teams they created
- [x] No ON DELETE CASCADE on user/team graph
- [x] Team-owned users lose all memberships when owning team is
deactivated

<!-- CURSOR_AGENT_PR_BODY_END -->

<div><a
href="https://cursor.com/agents/bc-f52f2c82-7c40-4962-bf78-39a8915c3d00"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-web-light.png"><img
alt="Open in Web" width="114" height="28"
src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a>&nbsp;<a
href="https://cursor.com/background-agent?bcId=bc-f52f2c82-7c40-4962-bf78-39a8915c3d00"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source
media="(prefers-color-scheme: light)"
srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img
alt="Open in Cursor" width="131" height="28"
src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a>&nbsp;</div>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Silvan <adlerhurst@users.noreply.github.com>
Co-authored-by: Florian Forster <florian@zitadel.com>
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.

feat: align user/team lifecycle with ADR 023

3 participants