code: def test_store_get_experts(n_peers=10):
      peers = [hivemind.DHT(start=True)]
      initial_peers = peers[0].get_visible_maddrs()
      peers += [
          hivemind.DHT(initial_peers=initial_peers, start=True)
          for _ in range(n_peers - 1)
      ]
  
      first_peer = random.choice(peers)
      other_peer = random.choice(peers)
  
      expert_uids = [f"my_expert.{i}" for i in range(50)]
      batch_size = 10
      for batch_start in range(0, len(expert_uids), batch_size):
          declare_experts(
              first_peer,
              expert_uids[batch_start : batch_start + batch_size],
              get_dht_time() + 30,
          )
  
      found = get_experts(
          other_peer, random.sample(expert_uids, 5) + ["foo", "bar"]
      )
      assert all(
          res is not None for res in found[:-2]
      ), "Could not find some existing experts"
      assert all(
          res is None for res in found[-2:]
      ), "Found non-existing experts"
  
      other_expert = "my_other_expert.1337"
      declare_experts(other_peer, [other_expert], get_dht_time() + 30)
      first_notfound, first_found = get_experts(
          first_peer, ["foobar", other_expert]
      )
      assert isinstance(first_found, hivemind.RemoteExpert)
      assert first_found.peer_id == other_peer.peer_id
      assert first_notfound is None
  
      # test graceful shutdown
      first_peer.shutdown()
      other_peer.shutdown()
      time.sleep(1.0)
      remaining_peer1 = random.choice(
          [peer for peer in peers if peer.is_alive()]
      )
      remaining_peer2 = random.choice(
          [peer for peer in peers if peer.is_alive()]
      )
      assert all(
          declare_experts(
              remaining_peer1,
              ["new_expert.1"],
              expiration_time=get_dht_time() + 30,
          )
      )
      assert (
          get_experts(remaining_peer2, ["new_expert.1"])[0].peer_id
          == remaining_peer1.peer_id
      )
  
file_path: hivemind/tests/test_dht_experts.py
imports: import asyncio
  import random
  import time
  import numpy
  import pytest
  import hivemind
  from hivemind import get_dht_time
  from hivemind.dht.node import DHTNode
  from hivemind.moe.client.beam_search import MoEBeamSearcher
  from hivemind.moe.expert_uid import ExpertInfo, is_valid_prefix, is_valid_uid, split_uid
  from hivemind.moe.server.dht_handler import declare_experts, get_experts
label_desc: Use image node_id 1 for calling a global function with example usage: test_store_get_experts(n_peers) without return types