@@ -21,6 +21,7 @@ import (
2121 "code.gitea.io/gitea/modules/json"
2222 "code.gitea.io/gitea/modules/setting"
2323 api "code.gitea.io/gitea/modules/structs"
24+ actions_service "code.gitea.io/gitea/services/actions"
2425
2526 runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
2627 "connectrpc.com/connect"
@@ -452,6 +453,9 @@ func TestActionsGiteaContextEphemeral(t *testing.T) {
452453 runner := newMockRunner ()
453454 runner .registerAsRepoRunner (t , baseRepo .OwnerName , baseRepo .Name , "mock-runner" , []string {"ubuntu-latest" }, true )
454455
456+ // verify CleanupEphemeralRunners does not remove this runner
457+ actions_service .CleanupEphemeralRunners (t .Context ())
458+
455459 // init the workflow
456460 wfTreePath := ".gitea/workflows/pull.yml"
457461 wfFileContent := `name: Pull Request
@@ -524,11 +528,18 @@ jobs:
524528 token := gtCtx ["token" ].GetStringValue ()
525529 assert .Equal (t , actionTask .TokenLastEight , token [len (token )- 8 :])
526530
531+ // verify CleanupEphemeralRunners does not remove this runner
532+ actions_service .CleanupEphemeralRunners (t .Context ())
533+
527534 resp , err := runner .client .runnerServiceClient .FetchTask (t .Context (), connect .NewRequest (& runnerv1.FetchTaskRequest {
528535 TasksVersion : 0 ,
529536 }))
530537 assert .NoError (t , err )
531538 assert .Nil (t , resp .Msg .Task )
539+
540+ // verify CleanupEphemeralRunners does not remove this runner
541+ actions_service .CleanupEphemeralRunners (t .Context ())
542+
532543 runner .client .runnerServiceClient .UpdateTask (t .Context (), connect .NewRequest (& runnerv1.UpdateTaskRequest {
533544 State : & runnerv1.TaskState {
534545 Id : actionTask .ID ,
@@ -546,6 +557,27 @@ jobs:
546557 }))
547558 assert .Error (t , err )
548559 assert .Nil (t , resp )
560+
561+ // create an runner that picks a job and get force cancelled
562+ runnerToBeRemoved := newMockRunner ()
563+ runnerToBeRemoved .registerAsRepoRunner (t , baseRepo .OwnerName , baseRepo .Name , "mock-runner-to-be-removed" , []string {"ubuntu-latest" }, true )
564+
565+ taskToStopApiObj := runnerToBeRemoved .fetchTask (t )
566+
567+ taskToStop := unittest .AssertExistsAndLoadBean (t , & actions_model.ActionTask {ID : taskToStopApiObj .Id })
568+
569+ // verify CleanupEphemeralRunners does not remove the custom crafted runner
570+ actions_service .CleanupEphemeralRunners (t .Context ())
571+
572+ runnerToRemove := unittest .AssertExistsAndLoadBean (t , & actions_model.ActionRunner {ID : taskToStop .RunnerID })
573+
574+ err = actions_model .StopTask (t .Context (), taskToStop .ID , actions_model .StatusFailure )
575+ assert .NoError (t , err )
576+
577+ // verify CleanupEphemeralRunners does remove the custom crafted runner
578+ actions_service .CleanupEphemeralRunners (t .Context ())
579+
580+ unittest .AssertNotExistsBean (t , runnerToRemove )
549581 })
550582}
551583
0 commit comments