@@ -20,6 +20,7 @@ import (
20
20
"context"
21
21
"errors"
22
22
"fmt"
23
+ "math"
23
24
"math/rand"
24
25
"reflect"
25
26
"runtime"
@@ -2940,47 +2941,57 @@ func fakeResourceVersion(object interface{}) {
2940
2941
obj .SetResourceVersion (strconv .FormatInt (intValue + 1 , 10 ))
2941
2942
}
2942
2943
}
2943
-
2944
2944
func TestParallelScale (t * testing.T ) {
2945
2945
for _ , tc := range []struct {
2946
- desc string
2947
- replicas int32
2948
- desiredReplicas int32
2946
+ desc string
2947
+ replicas int32
2948
+ desiredReplicas int32
2949
+ expectedMinParallelRequests int
2949
2950
}{
2950
2951
{
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 ,
2954
2956
},
2955
2957
{
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 ,
2959
2962
},
2960
2963
2961
2964
{
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 ,
2965
2969
},
2966
2970
{
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 ,
2970
2975
},
2971
2976
} {
2972
2977
t .Run (tc .desc , func (t * testing.T ) {
2973
2978
set := burst (newStatefulSet (0 ))
2974
2979
set .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 )
2976
2981
})
2977
2982
}
2978
2983
2979
2984
}
2980
2985
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 ) {
2982
2987
var err error
2983
2988
diff := 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
+ }
2984
2995
client := fake .NewSimpleClientset (set )
2985
2996
om , _ , ssc := setupController (client )
2986
2997
om .createPodTracker .shouldTrackParallelRequests = true
@@ -3016,8 +3027,8 @@ func parallelScale(t *testing.T, set *apps.StatefulSet, replicas, desiredReplica
3016
3027
t .Errorf ("Failed to scale statefulset to %v replicas, got %v replicas" , desiredReplicas , set .Status .Replicas )
3017
3028
}
3018
3029
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 )
3021
3032
}
3022
3033
}
3023
3034
0 commit comments