code: def test_metrics_pusher_basic():
      start = 0
      timer = MockTimer(start)
  
      with patch("time.time", new=timer.time), patch(
          "time.sleep", new=timer.realistic_sleep
      ):
          counter = {"val": 0}
          result = {}
          expected_result = 20
  
          def task(c, res):
              timer.realistic_sleep(0.001)
              c["val"] += 1
              # At 10 seconds, this task should have been called 20 times
              if timer.time() >= 10 and "val" not in res:
                  res["val"] = c["val"]
  
          metrics_pusher = MetricsPusher()
          metrics_pusher.register_task(
              lambda: task(counter, result), 0.5
          )
  
          metrics_pusher.start()
          # This busy wait loop should run for at most a few hundred milliseconds
          # The test should finish by then, and if the test fails this prevents
          # an infinite loop
          for _ in range(10000000):
              if "val" in result:
                  assert result["val"] == expected_result
                  break
  
          assert result["val"] == expected_result
  
imports: import asyncio
  import json
  import os
  import time
  from unittest.mock import patch
  import numpy
  import pytest
  from fastapi.encoders import jsonable_encoder
  import ray
  from ray import serve
  from ray._private.resource_spec import HEAD_NODE_RESOURCE_NAME
  from ray._private.test_utils import wait_for_condition
  from ray.serve._private.test_utils import MockTimer
  from ray.serve._private.utils import MetricsPusher, calculate_remaining_timeout, get_all_live_placement_group_names, get_current_actor_id, get_head_node_id, is_running_in_asyncio_loop, merge_dict, msgpack_deserialize, msgpack_serialize, override_runtime_envs_except_env_vars, serve_encoders, snake_to_camel_case
  from ray.serve.tests.common.remote_uris import TEST_DAG_PINNED_URI, TEST_DEPLOY_GROUP_PINNED_URI
label_desc: Use image node_id 12 for calling a global function with example usage: test_metrics_pusher_basic() without return types