@@ -247,6 +247,11 @@ func TestExptMangerImpl_CompleteRun(t *testing.T) {
247247 spaceID : 789 ,
248248 opts : []entity.CompleteExptOptionFn {},
249249 setup : func () {
250+ mgr .mutex .(* lockMocks.MockILocker ).
251+ EXPECT ().
252+ Lock (ctx , "expt_completing_mutex_lock:123:456" , time .Minute * 3 ).
253+ Return (true , nil )
254+
250255 runLog := & entity.ExptRunLog {
251256 ID : 456 ,
252257 ExptID : 123 ,
@@ -269,13 +274,18 @@ func TestExptMangerImpl_CompleteRun(t *testing.T) {
269274
270275 mgr .mutex .(* lockMocks.MockILocker ).
271276 EXPECT ().
272- Unlock ( gomock . Any () ).
277+ UnlockForce ( ctx , "expt_run_mutex_lock:123" ).
273278 Return (true , nil )
274279
275280 mgr .runLogRepo .(* repoMocks.MockIExptRunLogRepo ).
276281 EXPECT ().
277282 Save (ctx , gomock .Any ()).
278283 Return (nil )
284+
285+ mgr .mutex .(* lockMocks.MockILocker ).
286+ EXPECT ().
287+ Unlock (gomock .Any ()).
288+ Return (true , nil )
279289 },
280290 wantErr : false ,
281291 },
@@ -296,6 +306,11 @@ func TestExptMangerImpl_CompleteRun(t *testing.T) {
296306 Exist (ctx , "CompleteRun:test_cid" ).
297307 Return (false , nil )
298308
309+ mgr .mutex .(* lockMocks.MockILocker ).
310+ EXPECT ().
311+ Lock (ctx , "expt_completing_mutex_lock:123:456" , time .Minute * 3 ).
312+ Return (true , nil )
313+
299314 runLog := & entity.ExptRunLog {
300315 ID : 456 ,
301316 ExptID : 123 ,
@@ -314,14 +329,19 @@ func TestExptMangerImpl_CompleteRun(t *testing.T) {
314329
315330 mgr .mutex .(* lockMocks.MockILocker ).
316331 EXPECT ().
317- Unlock ( gomock . Any () ).
332+ UnlockForce ( ctx , "expt_run_mutex_lock:123" ).
318333 Return (true , nil )
319334
320335 mgr .runLogRepo .(* repoMocks.MockIExptRunLogRepo ).
321336 EXPECT ().
322337 Save (ctx , gomock .Any ()).
323338 Return (nil )
324339
340+ mgr .mutex .(* lockMocks.MockILocker ).
341+ EXPECT ().
342+ Unlock (gomock .Any ()).
343+ Return (true , nil )
344+
325345 mgr .idem .(* idemMocks.MockIdempotentService ).
326346 EXPECT ().
327347 Set (ctx , "CompleteRun:test_cid" , time .Second * 60 * 3 ).
@@ -356,6 +376,11 @@ func TestExptMangerImpl_CompleteRun(t *testing.T) {
356376 entity .WithCompleteInterval (time .Millisecond * 100 ),
357377 },
358378 setup : func () {
379+ mgr .mutex .(* lockMocks.MockILocker ).
380+ EXPECT ().
381+ Lock (ctx , "expt_completing_mutex_lock:123:456" , time .Minute * 3 ).
382+ Return (true , nil )
383+
359384 runLog := & entity.ExptRunLog {
360385 ID : 456 ,
361386 ExptID : 123 ,
@@ -375,13 +400,18 @@ func TestExptMangerImpl_CompleteRun(t *testing.T) {
375400
376401 mgr .mutex .(* lockMocks.MockILocker ).
377402 EXPECT ().
378- Unlock ( gomock . Any () ).
403+ UnlockForce ( ctx , "expt_run_mutex_lock:123" ).
379404 Return (true , nil )
380405
381406 mgr .runLogRepo .(* repoMocks.MockIExptRunLogRepo ).
382407 EXPECT ().
383408 Save (ctx , gomock .Any ()).
384409 Return (nil )
410+
411+ mgr .mutex .(* lockMocks.MockILocker ).
412+ EXPECT ().
413+ Unlock (gomock .Any ()).
414+ Return (true , nil )
385415 },
386416 wantErr : false ,
387417 },
@@ -393,10 +423,20 @@ func TestExptMangerImpl_CompleteRun(t *testing.T) {
393423 spaceID : 789 ,
394424 opts : []entity.CompleteExptOptionFn {},
395425 setup : func () {
426+ mgr .mutex .(* lockMocks.MockILocker ).
427+ EXPECT ().
428+ Lock (ctx , "expt_completing_mutex_lock:123:456" , time .Minute * 3 ).
429+ Return (true , nil )
430+
396431 mgr .runLogRepo .(* repoMocks.MockIExptRunLogRepo ).
397432 EXPECT ().
398433 Get (ctx , int64 (123 ), int64 (456 )).
399434 Return (nil , errors .New ("run log not found" ))
435+
436+ mgr .mutex .(* lockMocks.MockILocker ).
437+ EXPECT ().
438+ Unlock (gomock .Any ()).
439+ Return (true , nil )
400440 },
401441 wantErr : true ,
402442 },
@@ -758,6 +798,8 @@ func TestExptMangerImpl_LogRetryItemsRun(t *testing.T) {
758798 EXPECT ().
759799 BackoffLockWithValue (ctx , gomock .Any (), "1002" , 300 * time .Second , time .Second ).
760800 Return (false , "1001" , nil )
801+ mgr .mutex .(* lockMocks.MockILocker ).
802+ EXPECT ().Exists (ctx , "expt_completing_mutex_lock:123:1001" ).Return (false , nil )
761803 existingLog := & entity.ExptRunLog {ID : 1001 , ExptID : exptID , ExptRunID : 1001 }
762804 mgr .runLogRepo .(* repoMocks.MockIExptRunLogRepo ).
763805 EXPECT ().Get (ctx , exptID , int64 (1001 )).
@@ -826,6 +868,8 @@ func TestExptMangerImpl_LogRetryItemsRun(t *testing.T) {
826868 EXPECT ().
827869 BackoffLockWithValue (ctx , gomock .Any (), "1005" , 300 * time .Second , time .Second ).
828870 Return (false , "1001" , nil )
871+ mgr .mutex .(* lockMocks.MockILocker ).
872+ EXPECT ().Exists (ctx , "expt_completing_mutex_lock:123:1001" ).Return (false , nil )
829873 mgr .runLogRepo .(* repoMocks.MockIExptRunLogRepo ).
830874 EXPECT ().Get (ctx , exptID , int64 (1001 )).
831875 Return (nil , errors .New ("get run log failed" ))
0 commit comments