Skip to content

Commit 9c72a46

Browse files
jnewberypromag
authored andcommitted
[tests] Tidy up forknotify.py
1 parent e022463 commit 9c72a46

File tree

1 file changed

+7
-23
lines changed

1 file changed

+7
-23
lines changed

test/functional/forknotify.py

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,56 +4,40 @@
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the -alertnotify option."""
66
import os
7-
import time
87

98
from test_framework.test_framework import BitcoinTestFramework
9+
from test_framework.util import assert_equal, wait_until
1010

1111
class ForkNotifyTest(BitcoinTestFramework):
1212
def set_test_params(self):
1313
self.num_nodes = 2
1414

1515
def setup_network(self):
1616
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
17-
with open(self.alert_filename, 'w', encoding='utf8'):
18-
pass # Just open then close to create zero-length file
19-
self.extra_args = [["-blockversion=2", "-alertnotify=echo %s >> \"" + self.alert_filename + "\""],
17+
self.extra_args = [["-alertnotify=echo %%s >> %s" % self.alert_filename],
2018
["-blockversion=211"]]
2119
super().setup_network()
2220

2321
def run_test(self):
24-
# Mine 51 up-version blocks
22+
# Mine 51 up-version blocks. -alertnotify should trigger on the 51st.
2523
self.nodes[1].generate(51)
2624
self.sync_all()
27-
# -alertnotify should trigger on the 51'st,
28-
# but mine and sync another to give
29-
# -alertnotify time to write
30-
self.nodes[1].generate(1)
31-
self.sync_all()
3225

3326
# Give bitcoind 10 seconds to write the alert notification
34-
timeout = 10.0
35-
while timeout > 0:
36-
if os.path.exists(self.alert_filename) and os.path.getsize(self.alert_filename):
37-
break
38-
time.sleep(0.1)
39-
timeout -= 0.1
40-
else:
41-
assert False, "-alertnotify did not warn of up-version blocks"
27+
wait_until(lambda: os.path.isfile(self.alert_filename) and os.path.getsize(self.alert_filename), timeout=10)
4228

4329
with open(self.alert_filename, 'r', encoding='utf8') as f:
4430
alert_text = f.read()
4531

4632
# Mine more up-version blocks, should not get more alerts:
47-
self.nodes[1].generate(1)
48-
self.sync_all()
49-
self.nodes[1].generate(1)
33+
self.nodes[1].generate(2)
5034
self.sync_all()
5135

5236
with open(self.alert_filename, 'r', encoding='utf8') as f:
5337
alert_text2 = f.read()
5438

55-
if alert_text != alert_text2:
56-
raise AssertionError("-alertnotify excessive warning of up-version blocks")
39+
self.log.info("-alertnotify should not continue notifying for more unknown version blocks")
40+
assert_equal(alert_text, alert_text2)
5741

5842
if __name__ == '__main__':
5943
ForkNotifyTest().main()

0 commit comments

Comments
 (0)