docstr: Simulates a workload that switches between too many and too few
  ongoing requests.
docstr_tok: ["Simulates","a","workload","that","switches","between","too","many","and","too","few","ongoing","requests","."]
code: def test_fluctuating_ongoing_requests(self, delay_s):
      """
      Simulates a workload that switches between too many and too few
      ongoing requests.
      """
  
      config = AutoscalingConfig(
          min_replicas=1,
          max_replicas=10,
          target_num_ongoing_requests_per_replica=50,
          upscale_delay_s=delay_s,
          downscale_delay_s=delay_s,
      )
  
      policy_manager = AutoscalingPolicyManager(config)
  
      if delay_s > 0:
          wait_periods = int(delay_s / CONTROL_LOOP_PERIOD_S)
          assert wait_periods > 1
  
      underload_requests, overload_requests = [20, 20], [100]
      trials = 1000
  
      new_num_replicas = None
      for trial in range(trials):
          if trial % 2 == 0:
              new_num_replicas = (
                  policy_manager.get_decision_num_replicas(
                      current_num_ongoing_requests=overload_requests,
                      curr_target_num_replicas=1,
                      current_handle_queued_queries=0,
                  )
              )
              if delay_s > 0:
                  assert new_num_replicas == 1, trial
              else:
                  assert new_num_replicas == 2, trial
          else:
              new_num_replicas = (
                  policy_manager.get_decision_num_replicas(
                      current_num_ongoing_requests=underload_requests,
                      curr_target_num_replicas=2,
                      current_handle_queued_queries=0,
                  )
              )
              if delay_s > 0:
                  assert new_num_replicas == 2, trial
              else:
                  assert new_num_replicas == 1, trial
  
imports: import sys
  import numpy
  import pytest
  from ray.serve._private.autoscaling_policy import AutoscalingPolicyManager
  from ray.serve._private.constants import CONTROL_LOOP_PERIOD_S
  from ray.serve.autoscaling_policy import _calculate_desired_num_replicas
  from ray.serve.config import AutoscalingConfig
label_desc: Use image node_id 5 for calling the TestGetDecisionNumReplicas obj's underlying member method code with example usage: obj.test_fluctuating_ongoing_requests(delay_s) without return types