code: def test_context_meter():
      it = iter([123, 124, 125, 126])
      cbs = []
  
      with metrics.context_meter.add_callback(
          lambda l, v, u: cbs.append((l, v, u))
      ):
          with metrics.context_meter.meter(
              "m1", func=lambda: next(it)
          ) as m1:
              assert m1.start == 123
              assert math.isnan(m1.stop)
              assert math.isnan(m1.delta)
          with metrics.context_meter.meter(
              "m2", func=lambda: next(it), unit="foo"
          ) as m2:
              assert m2.start == 125
              assert math.isnan(m2.stop)
              assert math.isnan(m2.delta)
  
          metrics.context_meter.digest_metric("m1", 2, "seconds")
          metrics.context_meter.digest_metric("m1", 1, "foo")
  
      # Not recorded - out of context
      metrics.context_meter.digest_metric("m1", 123, "foo")
  
      assert m1.start == 123
      assert m1.stop == 124
      assert m1.delta == 1
      assert m2.start == 125
      assert m2.stop == 126
      assert m2.delta == 1
      assert cbs == [
          ("m1", 1, "seconds"),
          ("m2", 1, "foo"),
          ("m1", 2, "seconds"),
          ("m1", 1, "foo"),
      ]
  
imports: from __future__ import annotations
  import math
  import pickle
  import threading
  import time
  import pytest
  from distributed import metrics
  from distributed.compatibility import WINDOWS
  from distributed.utils import offload
  from distributed.utils_test import gen_test
label_desc: Use image node_id 6 for calling a global function with example usage: test_context_meter() without return types