Check also the acceptable time offset

This commit is contained in:
Lee Miller 2024-07-08 01:33:01 +03:00
parent 68bea10ab7
commit 971b661d3c
Signed by: lee.miller
GPG Key ID: 4F97A5EA88F4AB63

View File

@ -127,19 +127,28 @@ class TestNetwork(unittest.TestCase):
else: else:
return 'Spent too much time trying to connect' return 'Spent too much time trying to connect'
def time_offset_connections(nodes, offset): def time_offset_bad_connections(nodes, offset):
"""Spoof time.time and open connections with given time offset""" """Spoof time.time and open connections with given time offset"""
with time_offset(offset) as time_call: with time_offset(offset) as time_call:
result = try_connect(nodes, 200, time_call) result = try_connect(nodes, 200, time_call)
if result: if result:
self.fail(result) self.fail(result)
def time_offset_good_connections(nodes):
"""Connect to at least one node with acceptable time offset"""
with time_offset(-3500) as time_call:
result = try_connect(nodes, 200, time_call)
if not result:
self.fail('Failed to connect with acceptable time offset')
self._make_initial_nodes() self._make_initial_nodes()
nodes = random.sample( nodes = random.sample(
tuple(shared.core_nodes.union(shared.unchecked_node_pool)), 5) tuple(shared.core_nodes.union(shared.unchecked_node_pool)), 5)
time_offset_connections(nodes, 4000) time_offset_bad_connections(nodes, 4000)
time_offset_connections(nodes, -4000) time_offset_bad_connections(nodes, -4000)
time_offset_good_connections(nodes)
class TestConnection(TestProcessProto): class TestConnection(TestProcessProto):