Skip to content

Commit 3ba2c08

Browse files
committed
[tests] fix disconnect_ban intermittency
1 parent 7ee5236 commit 3ba2c08

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

test/functional/disconnect_ban.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test node disconnect and ban behavior"""
6+
import time
67

78
from test_framework.mininode import wait_until
89
from test_framework.test_framework import BitcoinTestFramework
@@ -56,11 +57,16 @@ def run_test(self):
5657
self.log.info("setban: test persistence across node restart")
5758
self.nodes[1].setban("127.0.0.0/32", "add")
5859
self.nodes[1].setban("127.0.0.0/24", "add")
60+
# Set the mocktime so we can control when bans expire
61+
old_time = int(time.time())
62+
self.nodes[1].setmocktime(old_time)
5963
self.nodes[1].setban("192.168.0.1", "add", 1) # ban for 1 seconds
6064
self.nodes[1].setban("2001:4d48:ac57:400:cacf:e9ff:fe1d:9c63/19", "add", 1000) # ban for 1000 seconds
6165
listBeforeShutdown = self.nodes[1].listbanned()
6266
assert_equal("192.168.0.1/32", listBeforeShutdown[2]['address'])
63-
assert wait_until(lambda: len(self.nodes[1].listbanned()) == 3, timeout=10)
67+
# Move time forward by 3 seconds so the third ban has expired
68+
self.nodes[1].setmocktime(old_time + 3)
69+
assert_equal(len(self.nodes[1].listbanned()), 3)
6470

6571
stop_node(self.nodes[1], 1)
6672

0 commit comments

Comments
 (0)