Skip to content

Commit 869a7fc

Browse files
authored
fix: stabilize FetchDispatchable_RespectsScheduledAt against CRDB SKIP LOCKED flakiness (#2046)
CockroachDB's FOR UPDATE SKIP LOCKED under READ COMMITTED can skip rows with unresolved write intents from recently-committed transactions. Wrap the assertion in await.Until to retry until intent resolution completes. Co-authored-by: Ben Coombs <bjcoombs@users.noreply.github.com>
1 parent 5e8d1f8 commit 869a7fc

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

services/operational-gateway/adapters/persistence/instruction_repository_test.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/google/uuid"
99
"github.com/meridianhub/meridian/services/operational-gateway/domain"
1010
"github.com/meridianhub/meridian/services/operational-gateway/ports"
11+
"github.com/meridianhub/meridian/shared/platform/await"
1112
"github.com/stretchr/testify/assert"
1213
"github.com/stretchr/testify/require"
1314
"gorm.io/gorm"
@@ -212,12 +213,22 @@ func TestInstructionRepository_FetchDispatchable_RespectsScheduledAt(t *testing.
212213
ready := makeInstruction(t, tenantID, connID.String(), domain.PriorityNormal)
213214
require.NoError(t, repo.Save(ctx, ready, fmt.Sprintf("idem-%s", ready.ID)))
214215

215-
results, err := repo.FetchDispatchable(ctx, ports.FetchDispatchableParams{
216-
Limit: 10,
217-
AsOf: time.Now(),
218-
})
219-
require.NoError(t, err)
220-
require.Len(t, results, 1)
216+
// CockroachDB's FOR UPDATE SKIP LOCKED under READ COMMITTED may skip rows
217+
// with unresolved write intents from recently-committed transactions.
218+
// Retry until the intent is resolved and the row becomes visible.
219+
var results []*domain.Instruction
220+
err = await.New().
221+
AtMost(5 * time.Second).
222+
PollInterval(50 * time.Millisecond).
223+
Until(func() bool {
224+
var fetchErr error
225+
results, fetchErr = repo.FetchDispatchable(ctx, ports.FetchDispatchableParams{
226+
Limit: 10,
227+
AsOf: time.Now(),
228+
})
229+
return fetchErr == nil && len(results) == 1
230+
})
231+
require.NoError(t, err, "expected 1 dispatchable instruction within timeout")
221232
assert.Equal(t, ready.ID, results[0].ID)
222233
}
223234

0 commit comments

Comments
 (0)