Skip to content

Commit a4fd89f

Browse files
author
John Newbery
committed
Make forknotify.py more robust
forknotify would intermittently fail because the alert file was not being written fast enough. This commit adds a timeout so the test does not fail immediately.
1 parent 1f3d78b commit a4fd89f

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

test/functional/forknotify.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the -alertnotify option."""
6+
import os
7+
import time
68

79
from test_framework.test_framework import BitcoinTestFramework
810
from test_framework.util import *
@@ -41,12 +43,19 @@ def run_test(self):
4143
self.nodes[1].generate(1)
4244
self.sync_all()
4345

46+
# Give bitcoind 10 seconds to write the alert notification
47+
timeout = 10.0
48+
while timeout > 0:
49+
if os.path.exists(self.alert_filename) and os.path.getsize(self.alert_filename):
50+
break
51+
time.sleep(0.1)
52+
timeout -= 0.1
53+
else:
54+
assert False, "-alertnotify did not warn of up-version blocks"
55+
4456
with open(self.alert_filename, 'r', encoding='utf8') as f:
4557
alert_text = f.read()
4658

47-
if len(alert_text) == 0:
48-
raise AssertionError("-alertnotify did not warn of up-version blocks")
49-
5059
# Mine more up-version blocks, should not get more alerts:
5160
self.nodes[1].generate(1)
5261
self.sync_all()

0 commit comments

Comments
 (0)