code: def test_heapset_sort_duplicate():
      """See https://github.com/dask/distributed/issues/6951"""
      heap = HeapSet(key=operator.attrgetter("i"))
      c1 = C("x", 1)
      c2 = C("2", 2)
  
      heap.add(c1)
      heap.add(c2)
      heap.discard(c1)
      heap.add(c1)
  
      assert list(heap.sorted()) == [c1, c2]
  
imports: from __future__ import annotations
  import heapq
  import operator
  import pickle
  import random
  from collections.abc import Mapping
  import pytest
  from distributed.collections import LRU, HeapSet, sum_mappings
label_desc: Use image node_id 8 for calling a global function with example usage: test_heapset_sort_duplicate() without return types