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.
5 """Unittests for timeout_and_retry.py."""
9 from pylib
.utils
import reraiser_thread
10 from pylib
.utils
import timeout_retry
13 class TestException(Exception):
17 def _NeverEnding(tries
):
23 def _CountTries(tries
):
28 class TestRun(unittest
.TestCase
):
29 """Tests for timeout_retry.Run."""
32 self
.assertTrue(timeout_retry
.Run(
33 lambda x
: x
, 30, 3, [True], {}))
35 def testTimeout(self
):
37 self
.assertRaises(reraiser_thread
.TimeoutError
,
38 timeout_retry
.Run
, lambda: _NeverEnding(tries
), 0, 3)
39 self
.assertEqual(tries
[0], 4)
41 def testRetries(self
):
43 self
.assertRaises(TestException
,
44 timeout_retry
.Run
, lambda: _CountTries(tries
), 30, 3)
45 self
.assertEqual(tries
[0], 4)
47 def testReturnValue(self
):
48 self
.assertTrue(timeout_retry
.Run(lambda: True, 30, 3))
51 if __name__
== '__main__':