@@ -20,6 +20,7 @@ import (
2020"context"
2121"errors"
2222"fmt"
23+ "math"
2324"math/rand"
2425"reflect"
2526"runtime"
@@ -2940,47 +2941,57 @@ func fakeResourceVersion(object interface{}) {
29402941obj .SetResourceVersion (strconv .FormatInt (intValue + 1 , 10 ))
29412942}
29422943}
2943-
29442944func TestParallelScale (t * testing.T ) {
29452945for _ , tc := range []struct {
2946- desc string
2947- replicas int32
2948- desiredReplicas int32
2946+ desc string
2947+ replicas int32
2948+ desiredReplicas int32
2949+ expectedMinParallelRequests int
29492950}{
29502951{
2951- desc : "scale up from 3 to 30" ,
2952- replicas : 3 ,
2953- desiredReplicas : 30 ,
2952+ desc : "scale up from 3 to 30" ,
2953+ replicas : 3 ,
2954+ desiredReplicas : 30 ,
2955+ expectedMinParallelRequests : 2 ,
29542956},
29552957{
2956- desc : "scale down from 10 to 1" ,
2957- replicas : 10 ,
2958- desiredReplicas : 1 ,
2958+ desc : "scale down from 10 to 1" ,
2959+ replicas : 10 ,
2960+ desiredReplicas : 1 ,
2961+ expectedMinParallelRequests : 2 ,
29592962},
29602963
29612964{
2962- desc : "scale down to 0" ,
2963- replicas : 501 ,
2964- desiredReplicas : 0 ,
2965+ desc : "scale down to 0" ,
2966+ replicas : 501 ,
2967+ desiredReplicas : 0 ,
2968+ expectedMinParallelRequests : 10 ,
29652969},
29662970{
2967- desc : "scale up from 0" ,
2968- replicas : 0 ,
2969- desiredReplicas : 1000 ,
2971+ desc : "scale up from 0" ,
2972+ replicas : 0 ,
2973+ desiredReplicas : 1000 ,
2974+ expectedMinParallelRequests : 20 ,
29702975},
29712976} {
29722977t .Run (tc .desc , func (t * testing.T ) {
29732978set := burst (newStatefulSet (0 ))
29742979set .Spec .VolumeClaimTemplates [0 ].ObjectMeta .Labels = map [string ]string {"test" : "test" }
2975- parallelScale (t , set , tc .replicas , tc .desiredReplicas , assertBurstInvariants )
2980+ parallelScale (t , set , tc .replicas , tc .desiredReplicas , tc . expectedMinParallelRequests , assertBurstInvariants )
29762981})
29772982}
29782983
29792984}
29802985
2981- func parallelScale (t * testing.T , set * apps.StatefulSet , replicas , desiredReplicas int32 , invariants invariantFunc ) {
2986+ func parallelScale (t * testing.T , set * apps.StatefulSet , replicas , desiredReplicas int32 , expectedMinParallelRequests int , invariants invariantFunc ) {
29822987var err error
29832988diff := desiredReplicas - replicas
2989+
2990+ // maxParallelRequests: MaxBatchSize of the controller is 500, We divide the diff by 4 to allow maximum of the half of the last batch.
2991+ if maxParallelRequests := min (500 , math .Abs (float64 (diff ))/ 4 ); expectedMinParallelRequests < 2 || float64 (expectedMinParallelRequests ) > maxParallelRequests {
2992+ t .Fatalf ("expectedMinParallelRequests should be between 2 and %v. Batch size of the controller is expontially increasing until 500. " +
2993+ "Got expectedMinParallelRequests %v, " , maxParallelRequests , expectedMinParallelRequests )
2994+ }
29842995client := fake .NewSimpleClientset (set )
29852996om , _ , ssc := setupController (client )
29862997om .createPodTracker .shouldTrackParallelRequests = true
@@ -3016,8 +3027,8 @@ func parallelScale(t *testing.T, set *apps.StatefulSet, replicas, desiredReplica
30163027t .Errorf ("Failed to scale statefulset to %v replicas, got %v replicas" , desiredReplicas , set .Status .Replicas )
30173028}
30183029
3019- if ( diff < - 1 || diff > 1 ) && om .createPodTracker .maxParallelRequests <= 1 {
3020- t .Errorf ("want max parallel requests > 1 , got %v" , om .createPodTracker .maxParallelRequests )
3030+ if om .createPodTracker .maxParallelRequests < expectedMinParallelRequests {
3031+ t .Errorf ("want max parallelRequests requests >= %v , got %v" , expectedMinParallelRequests , om .createPodTracker .maxParallelRequests )
30213032}
30223033}
30233034
0 commit comments