github.com/mit-dci/lit@v0.0.0-20221102210550-8c3d3b49f2ce/test/itest_reconnect.py (about)

     1  
     2  import testlib
     3  
     4  def simple(env):
     5      print('Starting nodes')
     6      lit1 = env.new_lit_node()
     7      lit2 = env.new_lit_node()
     8  
     9      print('Connecting nodes...')
    10      lit1.connect_to_peer(lit2)
    11      # lXpY : X == node, Y == peerIdx sample
    12      l2p1 = lit1.get_peer_id(lit2)
    13  
    14      print('OK, shutting down node 1...')
    15      lit1.shutdown()
    16  
    17      print('Restarting...')
    18      lit1.start()
    19  
    20      print('Connecting to node 2...')
    21      lit1.connect_to_peer(lit2)
    22      l2p2 = lit1.get_peer_id(lit2)
    23  
    24      print('Checking IDs match...')
    25      print('Node 2: %s -> %s' % (l2p1, l2p2))
    26      assert l2p1 == l2p2, 'peer IDs on node 1 don\'t match across restarts!'
    27      print('OK')
    28  
    29  def inbound(env):
    30      print('Starting nodes')
    31      lit1 = env.new_lit_node()
    32      lit2 = env.new_lit_node()
    33  
    34      print('Connecting nodes...')
    35      lit1.connect_to_peer(lit2)
    36      # lXpY : X == node, Y == peerIdx sample
    37      l2p1 = lit1.get_peer_id(lit2)
    38  
    39      print('OK, shutting down node 1...')
    40      lit1.shutdown()
    41  
    42      print('Restarting...')
    43      lit1.start()
    44  
    45      print('Connecting to node 2 (inbound)...')
    46      lit2.connect_to_peer(lit1)
    47      l2p2 = lit1.get_peer_id(lit2)
    48  
    49      print('Checking IDs match...')
    50      print('Node 2: %s -> %s' % (l2p1, l2p2))
    51      assert l2p1 == l2p2, 'peer IDs on node 1 don\'t match across restarts!'
    52      print('OK')
    53  
    54  def reordered(env):
    55      print('Starting nodes')
    56      lit1 = env.new_lit_node()
    57      lit2 = env.new_lit_node()
    58      lit3 = env.new_lit_node()
    59  
    60      print('Connecting nodes... (2 then 3)')
    61      lit1.connect_to_peer(lit2)
    62      lit1.connect_to_peer(lit3)
    63      # lXpY : X == node, Y == peerIdx sample
    64      l2p1 = lit1.get_peer_id(lit2)
    65      l3p1 = lit1.get_peer_id(lit3)
    66  
    67      print('OK, shutting down node 1...')
    68      lit1.shutdown()
    69  
    70      print('Restarting...')
    71      lit1.start()
    72      lit1.resync()
    73  
    74      print('Connecting nodes again... (3 then 2)')
    75      lit1.connect_to_peer(lit3)
    76      lit1.connect_to_peer(lit2)
    77      l2p2 = lit1.get_peer_id(lit2)
    78      l3p2 = lit1.get_peer_id(lit3)
    79  
    80      print('Checking IDs match...')
    81      print('Node 2: %s -> %s' % (l2p1, l2p2))
    82      print('Node 3: %s -> %s' % (l3p1, l3p2))
    83      assert l2p1 == l2p2, 'peer IDs on node 1 don\'t match across restarts for node 2!'
    84      assert l3p1 == l3p2, 'peer IDs on node 1 don\'t match across restarts for node 3!'
    85      print('OK')
    86  
    87  def reordered_inbound(env):
    88      print('Starting nodes')
    89      lit1 = env.new_lit_node()
    90      lit2 = env.new_lit_node()
    91      lit3 = env.new_lit_node()
    92  
    93      print('Connecting nodes... (2 then 3)')
    94      lit1.connect_to_peer(lit2)
    95      lit1.connect_to_peer(lit3)
    96      # lXpY : X == node, Y == peerIdx sample
    97      l2p1 = lit1.get_peer_id(lit2)
    98      l3p1 = lit1.get_peer_id(lit3)
    99  
   100      print('OK, shutting down node 1...')
   101      lit1.shutdown()
   102  
   103      print('Restarting...')
   104      lit1.start()
   105      lit1.resync()
   106  
   107      print('Connecting nodes again... (3 then 2, reversed)')
   108      lit2.connect_to_peer(lit1)
   109      lit3.connect_to_peer(lit1)
   110      l2p2 = lit1.get_peer_id(lit2)
   111      l3p2 = lit1.get_peer_id(lit3)
   112  
   113      print('Checking IDs match...')
   114      print('Node 2: %s -> %s' % (l2p1, l2p2))
   115      print('Node 3: %s -> %s' % (l3p1, l3p2))
   116      assert l2p1 == l2p2, 'peer IDs on node 1 don\'t match across restarts for node 2!'
   117      assert l3p1 == l3p2, 'peer IDs on node 1 don\'t match across restarts for node 3!'
   118      print('OK')