code: def test_spillbuffer(tmp_path):
      buf = SpillBuffer(str(tmp_path), target=300)
      # Convenience aliases
      assert buf.memory is buf.fast
      assert buf.disk is buf.slow
  
      assert_buf(buf, tmp_path, {}, {})
  
      a, b, c, d = "a" * 100, "b" * 99, "c" * 98, "d" * 97
  
      # Test assumption made by this test, mostly for non CPython implementations
      assert 100 < sizeof(a) < 200
  
      buf["a"] = a
      assert_buf(buf, tmp_path, {"a": a}, {})
      assert buf["a"] == a
  
      buf["b"] = b
      assert_buf(buf, tmp_path, {"a": a, "b": b}, {})
  
      buf["c"] = c
      assert_buf(buf, tmp_path, {"b": b, "c": c}, {"a": a})
  
      assert buf["a"] == a
      assert_buf(buf, tmp_path, {"a": a, "c": c}, {"b": b})
  
      buf["d"] = d
      assert_buf(buf, tmp_path, {"a": a, "d": d}, {"b": b, "c": c})
  
      # Deleting an in-memory key does not automatically move spilled keys back to memory
      del buf["a"]
      assert_buf(buf, tmp_path, {"d": d}, {"b": b, "c": c})
      with pytest.raises(KeyError):
          buf["a"]
  
      # Deleting a spilled key updates the metadata
      del buf["b"]
      assert_buf(buf, tmp_path, {"d": d}, {"c": c})
      with pytest.raises(KeyError):
          buf["b"]
  
      # Updating a spilled key moves it to the top of the LRU and to memory
      c2 = c * 2
      buf["c"] = c2
      assert_buf(buf, tmp_path, {"c": c2}, {"d": d})
  
      # Single key is larger than target and goes directly into slow
      e = "e" * 500
  
      buf["e"] = e
      assert_buf(buf, tmp_path, {"c": c2}, {"d": d, "e": e})
  
      # Updating a spilled key with another larger than target updates slow directly
      d = "d" * 500
      buf["d"] = d
      assert_buf(buf, tmp_path, {"c": c2}, {"d": d, "e": e})
  
imports: from __future__ import annotations
  import array
  import os
  import random
  import uuid
  from pathlib import Path
  import pytest
  import dask.config
  from dask.sizeof import sizeof
  from distributed import profile
  from distributed.compatibility import WINDOWS
  from distributed.metrics import meter
  from distributed.spill import SpillBuffer
  from distributed.utils import RateLimiterFilter
  from distributed.utils_test import captured_logger
label_desc: Use image node_id 4 for calling a global function with example usage: test_spillbuffer(tmp_path) without return types