forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 174
/
testAnnounce.py
100 lines (81 loc) · 3.18 KB
/
testAnnounce.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
from __future__ import print_function
import sys
from unittest.case import SkipTest
sys.path.append('..')
from pytest.Tiab import TiabTest
from armoryengine.ALL import *
from announcefetch import AnnounceDataFetcher
import unittest
forceTestURL = 'https://s3.amazonaws.com/bitcoinarmory-testing/testannounce.txt'
fetchDump = './fetchedFiles'
class AnnouncementTester(TiabTest):
def setUp(self):
pass
def tearDown(self):
pass
def testNoStart(self):
adf = AnnounceDataFetcher(forceTestURL, fetchDir=fetchDump)
adf.setFetchInterval(20)
self.assertFalse(adf.isDisabled())
self.assertFalse(adf.atLeastOneSuccess())
@SkipTest
def testStart(self):
adf = AnnounceDataFetcher(forceTestURL, fetchDir=fetchDump)
adf.setFetchInterval(20)
print('STARTING', end=' ')
print(' Running:', adf.isRunning(), end=' ')
print(' OneSuccess:', adf.atLeastOneSuccess(), end=' ')
print(' #Files',adf.numFiles())
print('Attempting to fetch before ADF is started')
d = adf.getAnnounceFile('notify')
print('*****')
print('LENGTH OF NOTIFY FILE:', (len(d) if d else 0))
print('*****')
print('Attempting to fetch before ADF is started (forced)')
d = adf.getAnnounceFile('notify', forceCheck=True)
print('*****')
print('LENGTH OF NOTIFY FILE:', (len(d) if d else 0))
print('*****')
adf.start()
t = 0
try:
while True:
time.sleep(0.5)
t += 0.5
print(' Running:', adf.isRunning(), end=' ')
print(' OneSuccess:', adf.atLeastOneSuccess(), end=' ')
print(' #Files',adf.numFiles())
if 10<t<11 or 14<t<15:
s = RightNow()
d = adf.getAnnounceFile('notify')
print('*****')
print('LENGTH OF NOTIFY FILE:', (len(d) if d else 0))
print('*****')
print('took %0.6f seconds' % (RightNow() - s))
if 30<t<31 or 34<t<35:
s = RightNow()
d = adf.getAnnounceFile('notify', forceCheck=True)
print('*****')
print('LENGTH OF NOTIFY FILE:', (len(d) if d else 0))
print('*****')
print('took %0.6f seconds' % (RightNow() - s))
if t>40:
adf.shutdown()
if not adf.isRunning():
print('Attempting to fetch after shutdown')
d = adf.getAnnounceFile('notify')
print('*****')
print('LENGTH OF NOTIFY FILE:', (len(d) if d else 0))
print('*****')
print('Attempting to fetch after shutdown (forced)')
d = adf.getAnnounceFile('notify', forceCheck=True)
print('*****')
print('LENGTH OF NOTIFY FILE:', (len(d) if d else 0))
print('*****')
break
except KeyboardInterrupt:
print('Exiting...')
# Running tests with "python <module name>" will NOT work for any Armory tests
# You must run tests with "python -m unittest <module name>" or run all tests with "python -m unittest discover"
# if __name__ == "__main__":
# unittest.main()