Skip to content

Commit f3120cf

Browse files
committed
test(oauth): exercise last-chance read in follower timeout test
1 parent ab928e3 commit f3120cf

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

apps/sim/lib/concurrency/__tests__/leader-lock.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,23 +120,25 @@ describe('withLeaderLock', () => {
120120
it('follower does a final read after timeout to catch a just-finished leader', async () => {
121121
redisConfigMockFns.mockAcquireLock.mockResolvedValueOnce(false)
122122

123+
// pollInterval=5, maxWait=9 → loop exits after 2 in-loop polls (T+5, T+10);
124+
// the third call (polls=3) is the post-deadline last-chance read.
123125
let polls = 0
124126
const onFollower = vi.fn(async () => {
125127
polls += 1
126-
// Return null during the poll loop, value on the post-deadline read.
127128
if (polls <= 2) return null
128129
return 'late-leader'
129130
})
130131

131132
const result = await withLeaderLock<string>({
132133
key: 'k',
133134
pollIntervalMs: 5,
134-
maxWaitMs: 12,
135+
maxWaitMs: 9,
135136
onLeader: async () => 'should-not-run',
136137
onFollower,
137138
})
138139

139140
expect(result).toBe('late-leader')
141+
expect(onFollower).toHaveBeenCalledTimes(3)
140142
})
141143

142144
it('follower returns null after timeout', async () => {

0 commit comments

Comments
 (0)