@@ -37,6 +37,7 @@ import (
3737 sandboxv1alpha1 "github.com/alibaba/OpenSandbox/sandbox-k8s/apis/sandbox/v1alpha1"
3838 taskscheduler "github.com/alibaba/OpenSandbox/sandbox-k8s/internal/scheduler"
3939 "github.com/alibaba/OpenSandbox/sandbox-k8s/internal/utils/fieldindex"
40+ taskexecutor "github.com/alibaba/OpenSandbox/sandbox-k8s/pkg/task-executor"
4041)
4142
4243// newTestReconciler creates a BatchSandboxReconciler with a fake client for testing.
@@ -80,6 +81,11 @@ func (f *forbiddenTaskScheduler) StopTask() []taskscheduler.Task {
8081 return nil
8182}
8283
84+ func (f * forbiddenTaskScheduler ) AddTasks (_ []* taskexecutor.Task ) error {
85+ f .t .Fatalf ("task scheduler should not add tasks while sandbox is paused" )
86+ return nil
87+ }
88+
8389type fakeSchedulerTask struct {
8490 name string
8591 state taskscheduler.TaskState
@@ -128,6 +134,10 @@ func (r *recordingTaskScheduler) StopTask() []taskscheduler.Task {
128134 return r .tasks
129135}
130136
137+ func (r * recordingTaskScheduler ) AddTasks (_ []* taskexecutor.Task ) error {
138+ return nil
139+ }
140+
131141// ---------- dispatchPauseResume 5-case tests ----------
132142
133143func TestDispatchPauseResume_Case1_PauseTrue (t * testing.T ) {
@@ -932,6 +942,7 @@ func TestContinueResume_PoolMode(t *testing.T) {
932942 Namespace : "default" ,
933943 Generation : 2 ,
934944 UID : "test-uid" ,
945+ Finalizers : []string {FinalizerPoolAllocation },
935946 },
936947 Spec : sandboxv1alpha1.BatchSandboxSpec {
937948 Pause : ptr .To (false ),
@@ -958,6 +969,7 @@ func TestContinueResume_PoolMode(t *testing.T) {
958969 updated := & sandboxv1alpha1.BatchSandbox {}
959970 require .NoError (t , r .Get (context .Background (), types.NamespacedName {Namespace : "default" , Name : "test-bs" }, updated ))
960971 assert .Equal (t , "" , updated .Spec .PoolRef )
972+ assert .NotContains (t , updated .Finalizers , FinalizerPoolAllocation )
961973}
962974
963975func TestContinueResume_UsesPatchedTemplateWhenCacheReturnsStaleObject (t * testing.T ) {
@@ -2054,6 +2066,7 @@ func TestCompletePause_PooledSandboxDetachesForPoolGC(t *testing.T) {
20542066 Namespace : "default" ,
20552067 Generation : 2 ,
20562068 UID : "test-bs-uid" ,
2069+ Finalizers : []string {FinalizerPoolAllocation },
20572070 },
20582071 Spec : sandboxv1alpha1.BatchSandboxSpec {
20592072 Pause : ptr .To (true ),
@@ -2107,6 +2120,7 @@ func TestCompletePause_PooledSandboxDetachesForPoolGC(t *testing.T) {
21072120 assert .NotContains (t , updated .Spec .Template .Labels , LabelPoolRevision )
21082121 assert .Equal (t , "" , updated .Spec .Template .Spec .NodeName )
21092122 assert .NotContains (t , updated .Annotations , AnnoAllocReleaseKey )
2123+ assert .NotContains (t , updated .Finalizers , FinalizerPoolAllocation )
21102124}
21112125
21122126func TestCompletePause_PooledSandboxDoesNotDeleteSourcePod (t * testing.T ) {
0 commit comments