code: def test_delayed_metrics_ledger():
      it = iter([120, 130, 130, 130])
      ledger = metrics.DelayedMetricsLedger(func=lambda: next(it))
      with ledger.record():
          metrics.context_meter.digest_metric("foo", 3, "seconds")
          metrics.context_meter.digest_metric("foo", 10, "bytes")
  
      assert list(ledger.finalize()) == [
          ("foo", 3, "seconds"),
          ("foo", 10, "bytes"),
          ("other", 7, "seconds"),
      ]
      assert list(ledger.finalize(coarse_time="error")) == [
          ("foo", 10, "bytes"),
          ("error", 10, "seconds"),
      ]
      assert list(ledger.finalize(floor=20)) == [
          ("foo", 3, "seconds"),
          ("foo", 10, "bytes"),
          ("other", 20, "seconds"),
      ]
  
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 14 for calling a global function with example usage: test_delayed_metrics_ledger() without return types