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

Unified Diff: build/android/devil/utils/timeout_retry_unittest.py

Issue 1376473006: Associate threads in reraiser_thread.RunAsync with the calling ThreadGroup (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase due to patch failure on win bot Created 5 years, 2 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/devil/utils/timeout_retry.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/devil/utils/timeout_retry_unittest.py
diff --git a/build/android/devil/utils/timeout_retry_unittest.py b/build/android/devil/utils/timeout_retry_unittest.py
old mode 100644
new mode 100755
index c48deb61a11b355ab08ec27c9e1aa7feae16fae7..f2ceef7d6045c29f71818c394b35e3a0d1ef12c1
--- a/build/android/devil/utils/timeout_retry_unittest.py
+++ b/build/android/devil/utils/timeout_retry_unittest.py
@@ -1,23 +1,23 @@
+#!/usr/bin/python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Unittests for timeout_and_retry.py."""
+import logging
+import time
import unittest
from devil.utils import reraiser_thread
from devil.utils import timeout_retry
-class TestException(Exception):
- pass
+_DEFAULT_TIMEOUT = .1
-def _NeverEnding(tries):
- tries[0] += 1
- while True:
- pass
+class TestException(Exception):
+ pass
def _CountTries(tries):
@@ -34,18 +34,43 @@ class TestRun(unittest.TestCase):
def testTimeout(self):
tries = [0]
- self.assertRaises(reraiser_thread.TimeoutError,
- timeout_retry.Run, lambda: _NeverEnding(tries), 0, 3)
- self.assertEqual(tries[0], 4)
+ def _sleep():
+ tries[0] += 1
+ time.sleep(1)
+
+ self.assertRaises(
+ reraiser_thread.TimeoutError, timeout_retry.Run, _sleep, .0001, 1,
+ error_log_func=logging.debug)
+ self.assertEqual(tries[0], 2)
def testRetries(self):
tries = [0]
- self.assertRaises(TestException,
- timeout_retry.Run, lambda: _CountTries(tries), 30, 3)
+ self.assertRaises(
+ TestException, timeout_retry.Run, lambda: _CountTries(tries),
+ _DEFAULT_TIMEOUT, 3, error_log_func=logging.debug)
self.assertEqual(tries[0], 4)
+ def testNoRetries(self):
+ tries = [0]
+ self.assertRaises(
+ TestException, timeout_retry.Run, lambda: _CountTries(tries),
+ _DEFAULT_TIMEOUT, 0, error_log_func=logging.debug)
+ self.assertEqual(tries[0], 1)
+
def testReturnValue(self):
- self.assertTrue(timeout_retry.Run(lambda: True, 30, 3))
+ self.assertTrue(timeout_retry.Run(lambda: True, _DEFAULT_TIMEOUT, 3))
+
+ def testCurrentTimeoutThreadGroup(self):
+ def InnerFunc():
+ current_thread_group = timeout_retry.CurrentTimeoutThreadGroup()
+ self.assertIsNotNone(current_thread_group)
+ def InnerInnerFunc():
+ self.assertEqual(current_thread_group,
+ timeout_retry.CurrentTimeoutThreadGroup())
+ return True
+ return reraiser_thread.RunAsync((InnerInnerFunc,))[0]
+
+ self.assertTrue(timeout_retry.Run(InnerFunc, _DEFAULT_TIMEOUT, 3))
if __name__ == '__main__':
« no previous file with comments | « build/android/devil/utils/timeout_retry.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698