diff --git a/api/scheduler_handler_test.go b/api/scheduler_handler_test.go index e54423b7a..862145dd4 100644 --- a/api/scheduler_handler_test.go +++ b/api/scheduler_handler_test.go @@ -76,7 +76,7 @@ var _ = Describe("Scheduler Handler", func() { }, "shutdownTimeout": 180, "autoscaling": { - "min": 100, + "min": 10, "up": { "delta": 10, "trigger": { @@ -293,7 +293,7 @@ var _ = Describe("Scheduler Handler", func() { app.Router.ServeHTTP(recorder, request) Expect(recorder.Code).To(Equal(http.StatusOK)) - Expect(recorder.Body.String()).To(Equal(`[{"autoscalingDownTriggerUsage":50,"autoscalingMin":100,"autoscalingUpTriggerUsage":70,"game":"game-name","name":"scheduler1","roomsCreating":2,"roomsOccupied":1,"roomsReady":1,"roomsTerminating":0,"state":"in-sync"}]`)) + Expect(recorder.Body.String()).To(Equal(`[{"autoscalingDownTriggerUsage":50,"autoscalingMin":10,"autoscalingUpTriggerUsage":70,"game":"game-name","name":"scheduler1","roomsCreating":2,"roomsOccupied":1,"roomsReady":1,"roomsTerminating":0,"state":"in-sync"}]`)) }) It("should list empty array when there aren't schedulers", func() { @@ -318,23 +318,23 @@ var _ = Describe("Scheduler Handler", func() { Context("when all services are healthy", func() { It("returns a status code of 201 and success body", func() { mockRedisTraceWrapper.EXPECT().WithContext(gomock.Any(), mockRedisClient).Return(mockRedisClient) - mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline).Times(100) + mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline).Times(10) mockPipeline.EXPECT().HMSet(gomock.Any(), gomock.Any()).Do( func(schedulerName string, statusInfo map[string]interface{}) { Expect(statusInfo["status"]).To(Equal(models.StatusCreating)) Expect(statusInfo["lastPing"]).To(BeNumerically("~", time.Now().Unix(), 1)) }, - ).Times(100) - mockPipeline.EXPECT().ZAdd(models.GetRoomPingRedisKey("scheduler-name"), gomock.Any()).Times(100) - mockPipeline.EXPECT().SAdd(models.GetRoomStatusSetRedisKey("scheduler-name", "creating"), gomock.Any()).Times(100) - mockPipeline.EXPECT().Exec().Times(100) + ).Times(10) + mockPipeline.EXPECT().ZAdd(models.GetRoomPingRedisKey("scheduler-name"), gomock.Any()).Times(10) + mockPipeline.EXPECT().SAdd(models.GetRoomStatusSetRedisKey("scheduler-name", "creating"), gomock.Any()).Times(10) + mockPipeline.EXPECT().Exec().Times(10) MockInsertScheduler(mockDb, nil) MockUpdateScheduler(mockDb, nil, nil) mockRedisClient.EXPECT(). Get(models.GlobalPortsPoolKey). Return(goredis.NewStringResult(workerPortRange, nil)). - Times(100) + Times(10) var configYaml1 models.ConfigYAML err := yaml.Unmarshal([]byte(yamlString), &configYaml1) @@ -564,16 +564,16 @@ autoscaling: It("forwards scheduler event", func() { mockRedisTraceWrapper.EXPECT().WithContext(gomock.Any(), mockRedisClient).Return(mockRedisClient) - mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline).Times(100) + mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline).Times(10) mockPipeline.EXPECT().HMSet(gomock.Any(), gomock.Any()).Do( func(schedulerName string, statusInfo map[string]interface{}) { Expect(statusInfo["status"]).To(Equal(models.StatusCreating)) Expect(statusInfo["lastPing"]).To(BeNumerically("~", time.Now().Unix(), 1)) }, - ).Times(100) - mockPipeline.EXPECT().ZAdd(models.GetRoomPingRedisKey("scheduler-name"), gomock.Any()).Times(100) - mockPipeline.EXPECT().SAdd(models.GetRoomStatusSetRedisKey("scheduler-name", "creating"), gomock.Any()).Times(100) - mockPipeline.EXPECT().Exec().Times(100) + ).Times(10) + mockPipeline.EXPECT().ZAdd(models.GetRoomPingRedisKey("scheduler-name"), gomock.Any()).Times(10) + mockPipeline.EXPECT().SAdd(models.GetRoomStatusSetRedisKey("scheduler-name", "creating"), gomock.Any()).Times(10) + mockPipeline.EXPECT().Exec().Times(10) mockDb.EXPECT().Query( gomock.Any(), @@ -589,7 +589,7 @@ autoscaling: MockInsertScheduler(mockDb, nil) MockUpdateScheduler(mockDb, nil, nil) mockRedisClient.EXPECT().Get(models.GlobalPortsPoolKey). - Return(goredis.NewStringResult(workerPortRange, nil)).Times(100) + Return(goredis.NewStringResult(workerPortRange, nil)).Times(10) var configYaml1 models.ConfigYAML err := yaml.Unmarshal([]byte(yamlString), &configYaml1) @@ -699,7 +699,7 @@ autoscaling: }, "shutdownTimeout": 180, "autoscaling": { - "min": 100, + "min": 10, "up": { "delta": 10, "trigger": { @@ -779,8 +779,8 @@ autoscaling: // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, nil) @@ -1111,8 +1111,8 @@ autoscaling: // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, nil) @@ -1202,8 +1202,8 @@ autoscaling: // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, errors.New("err on db")) @@ -2381,8 +2381,8 @@ game: game-name // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, nil) @@ -2439,8 +2439,8 @@ game: game-name // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, nil) @@ -2780,8 +2780,8 @@ game: game-name // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, nil) @@ -2873,7 +2873,7 @@ game: game-name // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, nil) @@ -2954,8 +2954,8 @@ game: game-name // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd) + MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + MockGetPortsFromPool(&configYaml, mockRedisClient, nil, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table MockUpdateSchedulersTable(mockDb, nil) diff --git a/controller/controller.go b/controller/controller.go index 3ca89e7a1..c7fcfbaa4 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -693,7 +693,7 @@ waitForLock: deletedPods := []v1.Pod{} for i, chunk := range podChunks { - l.Debugf("deleting chunk %d: %v", i, names(chunk)) + l.Debugf("updating chunk %d: %v", i, names(chunk)) newlyCreatedPods, newlyDeletedPods, timedout, canceled := replacePodsAndWait( l, roomManager, mr, clientset, db, redisClient.Client, diff --git a/controller/controller_test.go b/controller/controller_test.go index 7949a3f90..0d325e72a 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -353,7 +353,7 @@ var _ = Describe("Controller", func() { mt.MockInsertScheduler(mockDb, nil) mt.MockUpdateScheduler(mockDb, nil, nil) - mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd) + mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd, 0) err = mt.MockSetScallingAmount( mockRedisClient, @@ -440,7 +440,7 @@ cmd: mt.MockInsertScheduler(mockDb, nil) mt.MockUpdateScheduler(mockDb, nil, nil) - mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd) + mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd, 0) err = mt.MockSetScallingAmount( mockRedisClient, @@ -545,7 +545,7 @@ portRange: schedulerPortStart := configYaml1.PortRange.Start schedulerPortEnd := configYaml1.PortRange.End mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, - workerPortRange, schedulerPortStart, schedulerPortEnd) + workerPortRange, schedulerPortStart, schedulerPortEnd, 0) err = mt.MockSetScallingAmount( mockRedisClient, @@ -1723,7 +1723,7 @@ portRange: schedulerPortStart := configYaml.PortRange.Start schedulerPortEnd := configYaml.PortRange.End mt.MockGetPortsFromPool(&configYaml, mockRedisClient, mockPortChooser, - workerPortRange, schedulerPortStart, schedulerPortEnd) + workerPortRange, schedulerPortStart, schedulerPortEnd, 0) err = mt.MockSetScallingAmount( mockRedisClient, @@ -3610,10 +3610,10 @@ cmd: // Remove old rooms mt.MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml2) - // Create new roome + // Create new rooms // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2) - mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2, 0) + mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table mt.MockUpdateSchedulersTable(mockDb, nil) @@ -3750,7 +3750,7 @@ portRange: // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale mt.MockCreateRoomsWithPorts(mockRedisClient, mockPipeline, &configYaml2) mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, - workerPortRange, configYaml2.PortRange.Start, configYaml2.PortRange.End) + workerPortRange, configYaml2.PortRange.Start, configYaml2.PortRange.End, 0) // Update new config on schedulers table mt.MockUpdateSchedulersTable(mockDb, nil) @@ -3917,9 +3917,9 @@ cmd: mt.MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml1) // Create new rooms - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2, 0) mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, - workerPortRange, portStart, portEnd) + workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table mt.MockUpdateSchedulersTable(mockDb, nil) @@ -4094,7 +4094,7 @@ portRange: // Create new rooms mt.MockCreateRoomsWithPorts(mockRedisClient, mockPipeline, &configYaml2) mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, - workerPortRange, 20000, 20020) + workerPortRange, 20000, 20020, 0) // Update new config on schedulers table mt.MockUpdateSchedulersTable(mockDb, nil) @@ -4419,11 +4419,12 @@ cmd: calls.Append( mt.MockSelectScheduler(yaml1, mockDb, nil)) + calls.Append(mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, + workerPortRange, portStart, portEnd, 1)) + // Create rooms calls.Append( - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1)) - calls.Append(mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, - workerPortRange, portStart, portEnd)) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1, 1)) // Get timeout for waiting pod to be created calls.Add( @@ -4433,7 +4434,7 @@ cmd: // Delete newly created rooms calls.Append( - mt.MockRemoveAnyRoomsFromRedis(mockRedisClient, mockPipeline, 3, &configYaml1)) + mt.MockRemoveAnyRoomsFromRedis(mockRedisClient, mockPipeline, 1, &configYaml1)) calls.Append( mt.MockReturnRedisLock(mockRedisClient, lockKey, nil)) @@ -4479,11 +4480,11 @@ cmd: calls.Append( mt.MockSelectScheduler(yaml1, mockDb, nil)) - // Create rooms + // Create room calls.Append( - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1)) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1, 1)) calls.Append(mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, - workerPortRange, portStart, portEnd)) + workerPortRange, portStart, portEnd, 1)) calls.Add( mockClock.EXPECT(). Now(). @@ -4491,7 +4492,7 @@ cmd: // Delete old rooms calls.Append( - mt.MockRemoveAnyRoomsFromRedis(mockRedisClient, mockPipeline, 3, &configYaml1)) + mt.MockRemoveAnyRoomsFromRedis(mockRedisClient, mockPipeline, 1, &configYaml1)) // Get timeout for waiting old pods to be deleted calls.Add( @@ -4501,13 +4502,13 @@ cmd: // Delete newly created rooms calls.Append( - mt.MockRemoveAnyRoomsFromRedis(mockRedisClient, mockPipeline, 3, &configYaml1)) + mt.MockRemoveAnyRoomsFromRedis(mockRedisClient, mockPipeline, 1, &configYaml1)) // Recreate old rooms calls.Append( - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1)) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1, 1)) calls.Append(mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, - workerPortRange, portStart, portEnd)) + workerPortRange, portStart, portEnd, 1)) calls.Append( mt.MockReturnRedisLock(mockRedisClient, lockKey, nil)) @@ -4556,20 +4557,22 @@ cmd: // Get scheduler from DB calls.Append(mt.MockSelectScheduler(yaml1, mockDb, nil)) - // Create new pods - calls.Append( - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2)) - calls.Append( - mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, - workerPortRange, portStart, portEnd)) - calls.Add( - mockClock.EXPECT(). - Now(). - Return(time.Unix(0, 0))) - - // Delete rooms + // Create and Delete rooms errRedis := errors.New("redis error") for _, pod := range pods.Items { + + // Create new pod + calls.Append( + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2, 1)) + calls.Append( + mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, + workerPortRange, portStart, portEnd, 1)) + // Get time.Now() + calls.Add( + mockClock.EXPECT(). + Now(). + Return(time.Unix(int64(timeoutSec-100), 1))) + // Retrieve ports to pool room := models.NewRoom(pod.GetName(), pod.GetNamespace()) calls.Add( @@ -4599,11 +4602,6 @@ cmd: Return(nil, errRedis)) } - calls.Add( - mockClock.EXPECT(). - Now(). - Return(time.Unix(0, 0))) - calls.Append( mt.MockUpdateSchedulersTable(mockDb, nil)) @@ -4683,8 +4681,8 @@ cmd: // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2) - mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml2, 0) + mt.MockGetPortsFromPool(&configYaml2, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table mt.MockUpdateSchedulersTable(mockDb, nil) @@ -5083,8 +5081,8 @@ containers: // Create new roome // It will use the same number of rooms as config1, and ScaleUp to new min in Watcher at AutoScale - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1) - mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml1, 0) + mt.MockGetPortsFromPool(&configYaml1, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table mt.MockUpdateSchedulersTable(mockDb, nil) @@ -5310,8 +5308,8 @@ containers: mt.MockRemoveRoomsFromRedis(mockRedisClient, mockPipeline, pods, &configYaml) // Create new rooms - mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml) - mt.MockGetPortsFromPool(&configYaml, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd) + mt.MockCreateRooms(mockRedisClient, mockPipeline, &configYaml, 0) + mt.MockGetPortsFromPool(&configYaml, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd, 0) // Update new config on schedulers table mt.MockUpdateSchedulersTable(mockDb, nil) diff --git a/controller/utils.go b/controller/utils.go index b5a152923..9d678cb77 100644 --- a/controller/utils.go +++ b/controller/utils.go @@ -39,7 +39,7 @@ func replacePodsAndWait( willTimeoutAt time.Time, clock clockinterfaces.Clock, configYAML *models.ConfigYAML, - podsToDelete []v1.Pod, + podsChunk []v1.Pod, scheduler *models.Scheduler, operationManager *models.OperationManager, ) (createdPods []v1.Pod, deletedPods []v1.Pod, timedout, canceled bool) { @@ -47,46 +47,51 @@ func replacePodsAndWait( deletedPods = []v1.Pod{} // create a chunk of pods (chunkSize = maxSurge) - for range podsToDelete { + for _, pod := range podsChunk { logger.Debug("creating pods") + // create new pod newPod, err := roomManager.Create(logger, mr, redisClient, db, clientset, configYAML, scheduler) if err != nil { logger.WithError(err).Debug("error creating pod") - } else { - createdPods = append(createdPods, *newPod) + continue } - } - timeout := willTimeoutAt.Sub(clock.Now()) - timedout, canceled = waitCreatingPods( - logger, clientset, timeout, configYAML.Name, - createdPods, operationManager, mr) - if timedout || canceled { - return createdPods, deletedPods, timedout, canceled - } + createdPods = append(createdPods, *newPod) - for _, pod := range podsToDelete { - logger.Debugf("deleting pod %s", pod.GetName()) + // wait for new pod to be created + timeout := willTimeoutAt.Sub(clock.Now()) + timedout, canceled = waitCreatingPods( + logger, clientset, timeout, configYAML.Name, + []v1.Pod{*newPod}, operationManager, mr) + if timedout || canceled { + return createdPods, deletedPods, timedout, canceled + } - err := DeletePodAndRoom(logger, roomManager, mr, clientset, redisClient, + // delete old pod + logger.Debugf("deleting pod %s", pod.GetName()) + err = DeletePodAndRoom(logger, roomManager, mr, clientset, redisClient, configYAML, pod.GetName(), reportersConstants.ReasonUpdate) if err == nil || strings.Contains(err.Error(), "redis") { deletedPods = append(deletedPods, pod) } if err != nil { logger.WithError(err).Debugf("error deleting pod %s", pod.GetName()) + continue } - } - timeout = willTimeoutAt.Sub(clock.Now()) - timedout, canceled = waitTerminatingPods( - logger, clientset, timeout, configYAML.Name, - deletedPods, operationManager, mr) - if timedout || canceled { - return createdPods, deletedPods, timedout, canceled + // wait for old pods to be deleted + // we assume that maxSurge == maxUnavailable as we can't set maxUnavailable yet + // so for every pod created in a chunk one is deleted right after it + timeout = willTimeoutAt.Sub(clock.Now()) + timedout, canceled = waitTerminatingPods( + logger, clientset, timeout, configYAML.Name, + []v1.Pod{pod}, operationManager, mr) + if timedout || canceled { + return createdPods, deletedPods, timedout, canceled + } } return createdPods, deletedPods, false, false diff --git a/testing/common.go b/testing/common.go index 36a54a959..147e76f1b 100644 --- a/testing/common.go +++ b/testing/common.go @@ -276,10 +276,16 @@ func mockCreateRooms( mockRedisClient *redismocks.MockRedisClient, mockPipeline *redismocks.MockPipeliner, configYaml *models.ConfigYAML, + roomCount int, ) (calls *Calls) { calls = NewCalls() - for i := 0; i < configYaml.AutoScaling.Min; i++ { + count := configYaml.AutoScaling.Min + if roomCount > 0 { + count = roomCount + } + + for i := 0; i < count; i++ { calls.Add( mockRedisClient.EXPECT(). TxPipeline(). @@ -316,8 +322,9 @@ func MockCreateRooms( mockRedisClient *redismocks.MockRedisClient, mockPipeline *redismocks.MockPipeliner, configYaml *models.ConfigYAML, + roomCount int, ) (calls *Calls) { - return mockCreateRooms(mockRedisClient, mockPipeline, configYaml) + return mockCreateRooms(mockRedisClient, mockPipeline, configYaml, roomCount) } // MockCreateRoomsWithPorts mocks the creation of rooms on redis when @@ -327,7 +334,7 @@ func MockCreateRoomsWithPorts( mockPipeline *redismocks.MockPipeliner, configYaml *models.ConfigYAML, ) (calls *Calls) { - return mockCreateRooms(mockRedisClient, mockPipeline, configYaml) + return mockCreateRooms(mockRedisClient, mockPipeline, configYaml, 0) } // MockCreateScheduler mocks the creation of a scheduler @@ -386,7 +393,7 @@ func MockCreateScheduler( Times(configYaml.AutoScaling.Min)) calls.Append( - MockGetPortsFromPool(&configYaml, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd)) + MockGetPortsFromPool(&configYaml, mockRedisClient, mockPortChooser, workerPortRange, portStart, portEnd, 0)) calls.Append( MockUpdateScheduler(mockDb, nil, nil)) @@ -404,10 +411,15 @@ func MockGetPortsFromPool( mockRedisClient *redismocks.MockRedisClient, mockPortChooser *mocks.MockPortChooser, workerPortRange string, - portStart, portEnd int, + portStart, portEnd, times int, ) (calls *Calls) { calls = NewCalls() + callTimes := configYaml.AutoScaling.Min + if times > 0 { + callTimes = times + } + if !configYaml.HasPorts() { return } @@ -416,7 +428,7 @@ func MockGetPortsFromPool( mockRedisClient.EXPECT(). Get(models.GlobalPortsPoolKey). Return(goredis.NewStringResult(workerPortRange, nil)). - Times(configYaml.AutoScaling.Min) + Times(callTimes) } if mockPortChooser == nil { @@ -431,7 +443,7 @@ func MockGetPortsFromPool( mockPortChooser.EXPECT(). Choose(portStart, portEnd, nPorts). Return(ports). - Times(configYaml.AutoScaling.Min) + Times(callTimes) } if configYaml.Version() == "v1" {