Changeset View
Changeset View
Standalone View
Standalone View
test/functional/p2p_add_connections.py
Show First 20 Lines • Show All 197 Lines • ▼ Show 20 Lines | def random_test(self): | ||||
} | } | ||||
max_outbounds = sum(remaining_outbounds.values()) | max_outbounds = sum(remaining_outbounds.values()) | ||||
iterations = random.randint(1, 5 * max_outbounds) | iterations = random.randint(1, 5 * max_outbounds) | ||||
self.log.info( | self.log.info( | ||||
f"Randomly insert outbounds of various types {iterations} times") | f"Randomly insert outbounds of various types {iterations} times") | ||||
for _ in range(iterations): | for _ in range(iterations): | ||||
type = random.choice(list(remaining_outbounds)) | conn_type = random.choice(list(remaining_outbounds)) | ||||
if remaining_outbounds[type] <= 0: | if remaining_outbounds[conn_type] <= 0: | ||||
continue | continue | ||||
self.add_outbounds(self.nodes[0], 1, type) | self.add_outbounds(self.nodes[0], 1, conn_type) | ||||
remaining_outbounds[type] -= 1 | remaining_outbounds[conn_type] -= 1 | ||||
check_node_connections( | check_node_connections( | ||||
node=self.nodes[0], | node=self.nodes[0], | ||||
num_in=0, | num_in=0, | ||||
num_out=max_outbounds - sum(remaining_outbounds.values())) | num_out=max_outbounds - sum(remaining_outbounds.values())) | ||||
def run_test(self): | def run_test(self): | ||||
self.simple_test() | self.simple_test() | ||||
self.random_test() | self.random_test() | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
P2PAddConnections().main() | P2PAddConnections().main() |