Revision 32265e72

b/test/py/ganeti.utils.retry_unittest.py
36 36
    self.retries = 0
37 37
    self.called = 0
38 38
    self.time = 1379601882.0
39
    self.time_for_time_fn = 0
40
    self.time_for_retry_and_succeed = 0
39 41

  
40 42
  def _time_fn(self):
43
    self.time += self.time_for_time_fn
41 44
    return self.time
42 45

  
43 46
  def _wait_fn(self, delay):
......
55 58
    return utils.Retry(self._RaiseRetryAgain, 0.01, 0.02)
56 59

  
57 60
  def _RetryAndSucceed(self, retries):
61
    self.time += self.time_for_retry_and_succeed
58 62
    if self.retries < retries:
59 63
      self.retries += 1
60 64
      raise utils.RetryAgain()
......
89 93
                         True)
90 94
    self.failUnlessEqual(self.retries, 2)
91 95

  
96
  def testCompleteNontrivialTimes(self):
97
    self.time_for_time_fn = 0.01
98
    self.time_for_retry_and_succeed = 0.1
99
    self.failUnlessEqual(utils.Retry(self._RetryAndSucceed, 0, 1, args=[2],
100
                                     wait_fn = self._wait_fn,
101
                                     _time_fn = self._time_fn),
102
                         True)
103
    self.failUnlessEqual(self.retries, 2)
104

  
92 105
  def testNestedLoop(self):
93 106
    try:
94 107
      self.failUnlessRaises(errors.ProgrammerError, utils.Retry,
......
107 120
    else:
108 121
      self.fail("Expected timeout didn't happen")
109 122

  
123
  def testTimeout(self):
124
    self.time_for_time_fn = 0.01
125
    self.time_for_retry_and_succeed = 10
126
    try:
127
      utils.Retry(self._RetryAndSucceed, 1, 18, args=[2],
128
                  wait_fn = self._wait_fn, _time_fn = self._time_fn)
129
    except utils.RetryTimeout, err:
130
      self.failUnlessEqual(err.args, ())
131
    else:
132
      self.fail("Expected timeout didn't happen")
133

  
134
  def testNoTimeout(self):
135
    self.time_for_time_fn = 0.01
136
    self.time_for_retry_and_succeed = 8
137
    self.failUnlessEqual(
138
      utils.Retry(self._RetryAndSucceed, 1, 18, args=[2],
139
                  wait_fn = self._wait_fn, _time_fn = self._time_fn),
140
      True)
141

  
110 142
  def testRaiseInnerWithExc(self):
111 143
    retry_arg="my_important_debugging_message"
112 144
    try:

Also available in: Unified diff