~ubuntu-branches/debian/jessie/armory/jessie

« back to all changes in this revision

Viewing changes to pytest/testAnnounce.py

  • Committer: Package Import Robot
  • Author(s): Joseph Bisch
  • Date: 2014-10-07 10:22:45 UTC
  • Revision ID: package-import@ubuntu.com-20141007102245-2s3x3rhjxg689hek
Tags: upstream-0.92.3
ImportĀ upstreamĀ versionĀ 0.92.3

Show diffs side-by-side

added added

removed removed

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