From 23594dcc60b87b254aa688ae92efa0dfb35b421d Mon Sep 17 00:00:00 2001 From: Ettore Di Giacinto Date: Wed, 4 Nov 2026 11:55:11 +0000 Subject: [PATCH] test(studio): widen the margin of the turn reap spec The spec "a turn that stops beating is reaped, one that keeps beating is not" beat the live turn once and then made several store calls before the second reap with a 50 ms threshold. Under -race on a loaded runner those calls took longer than 50 ms, so the live turn counted as stale and the second reap found it. Use a 300 ms threshold, sleep twice that for the stale turn, and beat the live turn again right before the second reap. The assertions keep their meaning and the store is unchanged. Assisted-by: Claude:claude-sonnet-5-5 --- core/services/studio/store/storetest/contract.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/core/services/studio/store/storetest/contract.go b/core/services/studio/store/storetest/contract.go index 9034a05bf2..8bc848752d 100644 --- a/core/services/studio/store/storetest/contract.go +++ b/core/services/studio/store/storetest/contract.go @@ -600,15 +600,18 @@ func Run(newStore New) { }) It("a turn that stops beating is reaped, one that keeps beating is not", func() { + // The margin is wide: on a loaded runner under -race a few store calls + // can take longer than a tight threshold. + const stale = 300 * time.Millisecond s := newStore() chat(s, "stale", "alice") chat(s, "alive", "alice") Expect(s.ClaimTurn(ctx(), "alice", "stale", "r-stale")).To(Succeed()) Expect(s.ClaimTurn(ctx(), "alice", "alive", "r-alive")).To(Succeed()) - time.Sleep(100 * time.Millisecond) + time.Sleep(2 * stale) Expect(s.TouchTurn(ctx(), "alice", "alive", "r-alive")).To(Succeed()) - got, err := s.ReapTurns(ctx(), 50*time.Millisecond) + got, err := s.ReapTurns(ctx(), stale) Expect(err).NotTo(HaveOccurred()) Expect(got).To(HaveLen(1), "reaped = %+v, want only the chat that stopped beating", got) Expect(got[0].ChatID).To(Equal("stale")) @@ -622,7 +625,8 @@ func Run(newStore New) { // The run that was reaped can no longer beat or release, and the chat is free. Expect(s.TouchTurn(ctx(), "alice", "stale", "r-stale")).To(MatchError(store.ErrNotClaimed), "TouchTurn on a reaped run") Expect(s.ClaimTurn(ctx(), "alice", "stale", "r-next")).To(Succeed(), "claim after reap") - again, _ := s.ReapTurns(ctx(), 50*time.Millisecond) + Expect(s.TouchTurn(ctx(), "alice", "alive", "r-alive")).To(Succeed()) + again, _ := s.ReapTurns(ctx(), stale) Expect(again).To(BeEmpty(), "a second reap found %+v", again) })