|
4 | 4 | # file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
5 | 5 | """Test the -alertnotify option."""
|
6 | 6 | import os
|
7 |
| -import time |
8 | 7 |
|
9 | 8 | from test_framework.test_framework import BitcoinTestFramework
|
| 9 | +from test_framework.util import assert_equal, wait_until |
10 | 10 |
|
11 | 11 | class ForkNotifyTest(BitcoinTestFramework):
|
12 | 12 | def set_test_params(self):
|
13 | 13 | self.num_nodes = 2
|
14 | 14 |
|
15 | 15 | def setup_network(self):
|
16 | 16 | 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], |
20 | 18 | ["-blockversion=211"]]
|
21 | 19 | super().setup_network()
|
22 | 20 |
|
23 | 21 | def run_test(self):
|
24 |
| - # Mine 51 up-version blocks |
| 22 | + # Mine 51 up-version blocks. -alertnotify should trigger on the 51st. |
25 | 23 | self.nodes[1].generate(51)
|
26 | 24 | 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() |
32 | 25 |
|
33 | 26 | # 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) |
42 | 28 |
|
43 | 29 | with open(self.alert_filename, 'r', encoding='utf8') as f:
|
44 | 30 | alert_text = f.read()
|
45 | 31 |
|
46 | 32 | # 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) |
50 | 34 | self.sync_all()
|
51 | 35 |
|
52 | 36 | with open(self.alert_filename, 'r', encoding='utf8') as f:
|
53 | 37 | alert_text2 = f.read()
|
54 | 38 |
|
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) |
57 | 41 |
|
58 | 42 | if __name__ == '__main__':
|
59 | 43 | ForkNotifyTest().main()
|
0 commit comments