Skip to content

Conversation

@torcolvin
Copy link
Collaborator

CBG-3605 fix test flake: wait for stat

This flake is reproducible with adding a sleep here

Copilot AI review requested due to automatic review settings February 2, 2026 22:56
Copy link
Contributor

Copilot AI left a comment

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 test flakiness in TestActiveReplicatorPullBasic where the test was asserting the replication status immediately after a document write, leading to occasional failures due to a race condition between document persistence and status updates.

Changes:

  • Replaced immediate assertion with an eventually-consistent wait pattern to handle timing variance between document write and status update

Comment on lines +2134 to +2137
require.EventuallyWithT(t, func(c *assert.CollectT) {
status := ar.GetStatus(ctx1)
assert.Equal(c, strconv.FormatUint(remoteDoc.Sequence, 10), status.LastSeqPull, "status=%#+v", status)
}, 5*time.Second, 10*time.Millisecond)
Copy link

Copilot AI Feb 2, 2026

Choose a reason for hiding this comment

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

The timeout (5 seconds) and poll interval (10 milliseconds) should be defined as named constants rather than magic numbers. This improves maintainability and makes it easier to adjust timing parameters consistently across tests.

Suggested change
require.EventuallyWithT(t, func(c *assert.CollectT) {
status := ar.GetStatus(ctx1)
assert.Equal(c, strconv.FormatUint(remoteDoc.Sequence, 10), status.LastSeqPull, "status=%#+v", status)
}, 5*time.Second, 10*time.Millisecond)
const (
// These constants control how long we wait, and how often we poll, for the replicator status to reflect
// the sequence of the last pulled document.
replicatorStatusTimeout = 5 * time.Second
replicatorStatusPollInterval = 10 * time.Millisecond
)
require.EventuallyWithT(t, func(c *assert.CollectT) {
status := ar.GetStatus(ctx1)
assert.Equal(c, strconv.FormatUint(remoteDoc.Sequence, 10), status.LastSeqPull, "status=%#+v", status)
}, replicatorStatusTimeout, replicatorStatusPollInterval)

Copilot uses AI. Check for mistakes.
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.

2 participants