(t *testing.T)
| 389 | } |
| 390 | |
| 391 | func TestAutoscaler_MaxReplicas(t *testing.T) { |
| 392 | t.Parallel() |
| 393 | log := newLogger(t) |
| 394 | |
| 395 | mux := sync.RWMutex{} |
| 396 | var latestRequest int32 |
| 397 | |
| 398 | minReplicas := int32(5) |
| 399 | maxReplicas := int32(10) |
| 400 | |
| 401 | scalerMock := &ScalerFunc{ |
| 402 | ScaleFunc: func(apiName string, request int32) error { |
| 403 | mux.Lock() |
| 404 | defer mux.Unlock() |
| 405 | |
| 406 | latestRequest = request |
| 407 | return nil |
| 408 | }, |
| 409 | GetInFlightRequestsFunc: func(apiName string, window time.Duration) (*float64, error) { |
| 410 | return pointer.Float64(20), nil |
| 411 | }, |
| 412 | GetAutoscalingSpecFunc: func(apiName string) (*userconfig.Autoscaling, error) { |
| 413 | return &userconfig.Autoscaling{ |
| 414 | MinReplicas: minReplicas, |
| 415 | MaxReplicas: maxReplicas, |
| 416 | InitReplicas: minReplicas, |
| 417 | TargetInFlight: pointer.Float64(1), |
| 418 | Window: 500 * time.Millisecond, |
| 419 | MaxDownscaleFactor: 0.75, |
| 420 | MaxUpscaleFactor: 1.5, |
| 421 | }, nil |
| 422 | }, |
| 423 | CurrentRequestedReplicasFunc: func(apiName string) (int32, error) { |
| 424 | return minReplicas, nil |
| 425 | }, |
| 426 | } |
| 427 | |
| 428 | autoScaler := &Autoscaler{ |
| 429 | logger: log, |
| 430 | crons: make(map[string]cron.Cron), |
| 431 | scalers: make(map[userconfig.Kind]Scaler), |
| 432 | recs: make(map[string]*recommendations), |
| 433 | } |
| 434 | autoScaler.AddScaler(scalerMock, userconfig.RealtimeAPIKind) |
| 435 | |
| 436 | apiName := "test" |
| 437 | api := userconfig.Resource{ |
| 438 | Name: apiName, |
| 439 | Kind: userconfig.RealtimeAPIKind, |
| 440 | } |
| 441 | |
| 442 | autoscaleFn, err := autoScaler.autoscaleFn(api) |
| 443 | require.NoError(t, err) |
| 444 | |
| 445 | ticker := time.NewTicker(250 * time.Millisecond) |
| 446 | go func() { |
| 447 | for { |
| 448 | select { |
nothing calls this directly
no test coverage detected