@@ -377,6 +377,93 @@ func TestListener_deleteLastMessage(t *testing.T) {
377377 err = l .deleteLastMessage (ctx )
378378 assert .NotNil (t , err )
379379 })
380+
381+ t .Run ("RefreshAndSucceeds" , func (t * testing.T ) {
382+ t .Parallel ()
383+
384+ ctx := context .Background ()
385+ config := Config {
386+ ScaleSetID : 1 ,
387+ Metrics : metrics .Discard ,
388+ }
389+
390+ client := listenermocks .NewClient (t )
391+
392+ newUUID := uuid .New ()
393+ session := & actions.RunnerScaleSetSession {
394+ SessionId : & newUUID ,
395+ OwnerName : "example" ,
396+ RunnerScaleSet : & actions.RunnerScaleSet {},
397+ MessageQueueUrl : "https://example.com" ,
398+ MessageQueueAccessToken : "1234567890" ,
399+ Statistics : nil ,
400+ }
401+ client .On ("RefreshMessageSession" , ctx , mock .Anything , mock .Anything ).Return (session , nil ).Once ()
402+
403+ client .On ("DeleteMessage" , ctx , mock .Anything , mock .Anything , mock .Anything ).Return (& actions.MessageQueueTokenExpiredError {}).Once ()
404+
405+ client .On ("DeleteMessage" , ctx , mock .Anything , mock .Anything , mock .MatchedBy (func (lastMessageID any ) bool {
406+ return lastMessageID .(int64 ) == int64 (5 )
407+ })).Return (nil ).Once ()
408+ config .Client = client
409+
410+ l , err := New (config )
411+ require .Nil (t , err )
412+
413+ oldUUID := uuid .New ()
414+ l .session = & actions.RunnerScaleSetSession {
415+ SessionId : & oldUUID ,
416+ RunnerScaleSet : & actions.RunnerScaleSet {},
417+ }
418+ l .lastMessageID = 5
419+
420+ config .Client = client
421+
422+ err = l .deleteLastMessage (ctx )
423+ assert .NoError (t , err )
424+ })
425+
426+ t .Run ("RefreshAndFails" , func (t * testing.T ) {
427+ t .Parallel ()
428+
429+ ctx := context .Background ()
430+ config := Config {
431+ ScaleSetID : 1 ,
432+ Metrics : metrics .Discard ,
433+ }
434+
435+ client := listenermocks .NewClient (t )
436+
437+ newUUID := uuid .New ()
438+ session := & actions.RunnerScaleSetSession {
439+ SessionId : & newUUID ,
440+ OwnerName : "example" ,
441+ RunnerScaleSet : & actions.RunnerScaleSet {},
442+ MessageQueueUrl : "https://example.com" ,
443+ MessageQueueAccessToken : "1234567890" ,
444+ Statistics : nil ,
445+ }
446+ client .On ("RefreshMessageSession" , ctx , mock .Anything , mock .Anything ).Return (session , nil ).Once ()
447+
448+ client .On ("DeleteMessage" , ctx , mock .Anything , mock .Anything , mock .Anything ).Return (& actions.MessageQueueTokenExpiredError {}).Twice ()
449+
450+ config .Client = client
451+
452+ l , err := New (config )
453+ require .Nil (t , err )
454+
455+ oldUUID := uuid .New ()
456+ l .session = & actions.RunnerScaleSetSession {
457+ SessionId : & oldUUID ,
458+ RunnerScaleSet : & actions.RunnerScaleSet {},
459+ }
460+ l .lastMessageID = 5
461+
462+ config .Client = client
463+
464+ err = l .deleteLastMessage (ctx )
465+ assert .Error (t , err )
466+ })
380467}
381468
382469func TestListener_Listen (t * testing.T ) {
0 commit comments