Skip to content

CBG-5557: fix TestReplicationStatusActions flake#8426

Merged
torcolvin merged 1 commit into
mainfrom
CBG-5557
Jul 7, 2026
Merged

CBG-5557: fix TestReplicationStatusActions flake#8426
torcolvin merged 1 commit into
mainfrom
CBG-5557

Conversation

@torcolvin

Copy link
Copy Markdown
Collaborator

CBG-5557: fix TestReplicationStatusActions flake

After action=reset, the sgReplicateManager goroutine calls alignState(ctx, resetting) on the local ActiveReplicator, which clears the checkpoint (c.Checkpointer = nil) and removes the persisted status document. At this point the in-memory replicator reports status=stopped and LastSeqPull="". The test's EventuallyWithT saw both conditions satisfied and proceeded to call action=start.

However, the manager hadn't yet called UpdateReplicationState(id, stopped) to persist TargetState=stopped back to the cluster config. That call happens synchronously after alignState returns, but there is a window between the two where TargetState is still "resetting" in the cluster config. UpdateReplicationState (called by action=start) reads the cluster config and passes TargetState to isValidStateChange, which rejects the "resetting -> running" transition with a 400.

After action=reset, the sgReplicateManager goroutine calls
alignState(ctx, resetting) on the local ActiveReplicator, which clears
the checkpoint (c.Checkpointer = nil) and removes the persisted status
document. At this point the in-memory replicator reports status=stopped
and LastSeqPull="". The test's EventuallyWithT saw both conditions
satisfied and proceeded to call action=start.

However, the manager hadn't yet called UpdateReplicationState(id, stopped)
to persist TargetState=stopped back to the cluster config. That call
happens synchronously after alignState returns, but there is a window
between the two where TargetState is still "resetting" in the cluster
config. UpdateReplicationState (called by action=start) reads the
cluster config and passes TargetState to isValidStateChange, which
rejects the "resetting -> running" transition with a 400.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 6, 2026 15:01

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 test flake in Sync Gateway’s sg-replicate status-action flow by ensuring the test waits not only for the in-memory replication status to be reset/stopped, but also for the persisted replication config’s TargetState to be updated back to stopped before issuing a subsequent start action.

Changes:

  • Improve failure attribution in test helpers by marking key assertion/wait helper functions as t.Helper().
  • Harden TestReplicationStatusActions by additionally waiting until the replication config in /_replication/ reflects TargetState=stopped after a reset.
  • Add a lightweight guard/assertion that the replication config entry exists before checking TargetState.

Reviewed changes

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

File Description
rest/utilities_testing.go Marks RequireStatus/AssertStatus as helpers to improve test failure line reporting.
rest/utilities_testing_resttester.go Marks several RestTester helper methods as helpers for clearer stack traces in failing tests.
rest/replicatortest/replicator_test.go Extends the reset verification in TestReplicationStatusActions to also wait for persisted TargetState to become stopped, closing the flake window.

@torcolvin torcolvin merged commit 527ce41 into main Jul 7, 2026
49 checks passed
@torcolvin torcolvin deleted the CBG-5557 branch July 7, 2026 13:36
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.

3 participants