TestListDomains flakes with expected: 2 actual: 3 due to Cassandra domain-store orphan race
Author: c-warrenCreated Sep 28, 2026Updated Sep 28, 2026
Labelsbugtriage/needs-info
What test is failing?
host/persistence/cassandra → TestCassandraDomainPersistence/TestListDomains
Failure
metadataPersistenceV2Test.go:1358: Not equal: expected: 2 actual: 3. TestListDomains asserts an exact count of all domains returned by ListDomains, and an extra, orphaned domain shows up.
Observed in CI run: https://github.com/cadence-workflow/cadence/actions/runs/31034914206 (job "history queue v2 with alert").
Root cause
The orphan is left behind by TestConcurrentCreateDomain, which runs earlier in the same suite and drives heavy contention on domain creation:
InsertDomain(common/persistence/nosql/nosqlplugin/cassandra/domain.go, ~line 123-135) unconditionally deletes the by-IDdomainsrow whenever the batch CAS is not applied, before checking whether the failure was actually a "name already exists" case. This delete races with a sibling goroutine's re-insert of the same row, and under contention can leave adomains_by_name_v2(by-name) row with no matchingdomains(by-ID) row.- The test suite's per-test cleanup deletes domains by ID, and
DeleteDomainsilently returnsnilwhen the by-ID row is already missing, so the orphaned by-name row survives every cleanup untilTestListDomainscounts it.
Evidence
- CI run 31034914206, commit 1f9180688, job "history queue v2 with alert": the log shows
Domain already existsfor a domain name duringTestConcurrentCreateDomain, a branch only reachable when the by-name row exists but the by-ID row does not. That's direct evidence the orphan state occurred mid-run. - This passes on subsequent CI jobs indicating that this is a flake.
Suggested fix
- In
InsertDomain's not-applied path, inspect the CASpreviousrows before deleting the by-ID row, and skip the delete when the by-name row already holds the same domain ID (that by-ID row is a repair, not something to clean up). - Alternatively, have the test suite's cleanup delete by name (not just by ID) so an orphaned by-name row actually gets removed between tests.
Acceptance criteria
- Concurrent domain creation under CAS contention cannot leave an orphaned
domains_by_name_v2row. TestListDomainsno longer flakes due to leftover domains fromTestConcurrentCreateDomain.
Source: cadence-workflow/cadence