code: def test_as_completed_cancel(client):
      x = client.submit(inc, 1)
      y = client.submit(inc, 1)
  
      ac = as_completed([x, y])
      x.cancel()
  
      assert next(ac) is x or y
      assert next(ac) is y or x
  
      with pytest.raises(queue.Empty):
          ac.queue.get(timeout=0.1)
  
      res = list(as_completed([x, y, x]))
      assert len(res) == 3
      assert set(res) == {x, y}
      assert res.count(x) == 2
  
imports: from __future__ import annotations
  import asyncio
  import queue
  import random
  from collections.abc import Iterator
  from operator import add
  from time import sleep
  import pytest
  from distributed import TimeoutError
  from distributed.client import _as_completed, _first_completed, as_completed, wait
  from distributed.metrics import time
  from distributed.utils import CancelledError
  from distributed.utils_test import gen_cluster, inc, slowinc, throws
label_desc: Use image node_id 8 for calling a global function with example usage: test_as_completed_cancel(client) without return types