blob: fadeab5eb7e5d95ca37d3c681b141c8bee26daf8 [file] [log] [blame]
Max Rasskazovc018e382015-06-03 15:22:04 +03001#-*- coding: utf-8 -*-
2
3import unittest
4
5import utils
6
7
8logger = utils.logger.getChild('TestUtils')
9
10
11class TestUtils(unittest.TestCase):
12
13 def setUp(self):
14 self.gen10 = self.get_generator(10)
15
16 def get_generator(self, max):
17 for i in xrange(max):
18 yield i
19
20 def test_retry_3_from_5(self):
21 res = utils.Retry(timeout=1,
22 attempts=5).wait_result(self.gen10.next, 3)
23 self.assertEqual(res, 3)
24
25 def test_retry_failed(self):
26 retryer = utils.Retry(timeout=1, attempts=3)
27 self.assertRaises(utils.ResultNotProduced,
28 retryer.wait_result, self.gen10.next, 5)
29
30if __name__ == '__main__':
31 unittest.main()