MCPcopy
hub / github.com/cortexlabs/cortex / TestAutoscaler_MinReplicas

Function TestAutoscaler_MinReplicas

pkg/autoscaler/autoscaler_test.go:319–389  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

317}
318
319func TestAutoscaler_MinReplicas(t *testing.T) {
320 t.Parallel()
321 log := newLogger(t)
322
323 mux := sync.RWMutex{}
324 var latestRequest int32
325
326 minReplicas := int32(5)
327 maxReplicas := int32(10)
328
329 scalerMock := &ScalerFunc{
330 ScaleFunc: func(apiName string, request int32) error {
331 mux.Lock()
332 defer mux.Unlock()
333
334 latestRequest = request
335 return nil
336 },
337 GetInFlightRequestsFunc: func(apiName string, window time.Duration) (*float64, error) {
338 return pointer.Float64(0), nil
339 },
340 GetAutoscalingSpecFunc: func(apiName string) (*userconfig.Autoscaling, error) {
341 return &userconfig.Autoscaling{
342 MinReplicas: minReplicas,
343 MaxReplicas: maxReplicas,
344 InitReplicas: minReplicas,
345 TargetInFlight: pointer.Float64(1),
346 Window: 500 * time.Millisecond,
347 MaxDownscaleFactor: 0.75,
348 MaxUpscaleFactor: 1.5,
349 }, nil
350 },
351 CurrentRequestedReplicasFunc: func(apiName string) (int32, error) {
352 return minReplicas + 1, nil
353 },
354 }
355
356 autoScaler := &Autoscaler{
357 logger: log,
358 crons: make(map[string]cron.Cron),
359 scalers: make(map[userconfig.Kind]Scaler),
360 recs: make(map[string]*recommendations),
361 }
362 autoScaler.AddScaler(scalerMock, userconfig.RealtimeAPIKind)
363
364 apiName := "test"
365 api := userconfig.Resource{
366 Name: apiName,
367 Kind: userconfig.RealtimeAPIKind,
368 }
369
370 autoscaleFn, err := autoScaler.autoscaleFn(api)
371 require.NoError(t, err)
372
373 ticker := time.NewTicker(250 * time.Millisecond)
374 go func() {
375 for {
376 select {

Callers

nothing calls this directly

Calls 4

AddScalerMethod · 0.95
autoscaleFnMethod · 0.95
Float64Function · 0.92
newLoggerFunction · 0.70

Tested by

no test coverage detected