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

Unified Diff: tests/rietveld_test.py

Issue 174313002: Added a default timeout to rietveld requests. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Addressing comments Created 6 years, 10 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 | « rietveld.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/rietveld_test.py
diff --git a/tests/rietveld_test.py b/tests/rietveld_test.py
index 17627a5fd1b2a69903e809612d5e0d8e80d6862b..3ac2444881686ae66d864d5947c9a81780b9b130 100755
--- a/tests/rietveld_test.py
+++ b/tests/rietveld_test.py
@@ -8,11 +8,13 @@
import logging
import os
import sys
+import traceback
import unittest
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from testing_support.patches_data import GIT, RAW
+from testing_support import auto_stub
import patch
import rietveld
@@ -421,6 +423,46 @@ class CachingRietveldTest(BaseFixture):
self.assertEqual(expected, self.rietveld.get_patchset_properties(1, 2))
+class ProbeException(Exception):
+ """Deep-probe a value."""
+ value = None
+
+ def __init__(self, value):
+ super(ProbeException, self).__init__()
+ self.value = value
+
+
+def MockSend(request_path, payload=None,
+ content_type="application/octet-stream",
+ timeout=None,
+ extra_headers=None,
+ **kwargs):
+ """Mock upload.py's Send() to probe the timeout value"""
+ raise ProbeException(timeout)
+
+
+class DefaultTimeoutTest(auto_stub.TestCase):
+ TESTED_CLASS = rietveld.Rietveld
+
+ def setUp(self):
+ super(DefaultTimeoutTest, self).setUp()
+ self.rietveld = self.TESTED_CLASS('url', 'email', 'password')
+ self.mock(self.rietveld.rpc_server, 'Send', MockSend)
+
+ def test_timeout_get(self):
+ with self.assertRaises(ProbeException) as cm:
+ self.rietveld.get('/api/1234')
+
+ self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
+ % traceback.format_exc())
+
+ def test_timeout_post(self):
+ with self.assertRaises(ProbeException) as cm:
+ self.rietveld.post('/api/1234', [('key', 'data')])
+
+ self.assertIsNotNone(cm.exception.value, 'Rietveld timeout was not set: %s'
+ % traceback.format_exc())
+
if __name__ == '__main__':
logging.basicConfig(level=[
« no previous file with comments | « rietveld.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698