Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: build/android/pylib/utils/timeout_retry_unittest.py

Issue 60043003: [android] Add timeout_retry module to pylib/utils/. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed comments Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « build/android/pylib/utils/timeout_retry.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2013 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
4
5 """Unittests for timeout_and_retry.py."""
6
7 import unittest
8
9 import reraiser_thread
10 import timeout_retry
11
12
13 class TestException(Exception):
14 pass
15
16
17 def _NeverEnding(tries=[0]):
18 tries[0] += 1
19 while True:
20 pass
21
22
23 def _CountTries(tries):
24 tries[0] += 1
25 raise TestException
26
27
28 class TestRun(unittest.TestCase):
29 """Tests for timeout_retry.Run."""
30
31 def testRun(self):
32 self.assertTrue(timeout_retry.Run(
33 lambda x: x, 30, 3, [True], {}))
34
35 def testTimeout(self):
36 tries = [0]
37 self.assertRaises(reraiser_thread.TimeoutError,
38 timeout_retry.Run, lambda: _NeverEnding(tries), 0, 3)
39 self.assertEqual(tries[0], 4)
40
41 def testRetries(self):
42 tries = [0]
43 self.assertRaises(TestException,
44 timeout_retry.Run, lambda: _CountTries(tries), 30, 3)
45 self.assertEqual(tries[0], 4)
46
47 def testReturnValue(self):
48 self.assertTrue(timeout_retry.Run(lambda: True, 30, 3))
49
50
51 if __name__ == '__main__':
52 unittest.main()
OLDNEW
« no previous file with comments | « build/android/pylib/utils/timeout_retry.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698