File tree Expand file tree Collapse file tree
apps/sim/lib/concurrency/__tests__ Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( ) => {
You can’t perform that action at this time.
0 commit comments