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

Side by Side Diff: tests/swarm_get_results_test.py

Issue 23431002: [Abandoned] Move url_open with dependencies to utils.net module. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/swarm_client
Patch Set: Created 7 years, 3 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/run_isolated_test.py ('k') | tests/swarm_trigger_step_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 import json 6 import json
7 import logging 7 import logging
8 import os 8 import os
9 import StringIO 9 import StringIO
10 import sys 10 import sys
11 import threading 11 import threading
12 import unittest 12 import unittest
13 import urllib2 13 import urllib2
14 14
15 import auto_stub 15 import auto_stub
16 16
17 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
18 sys.path.insert(0, ROOT_DIR) 18 sys.path.insert(0, ROOT_DIR)
19 19
20 import run_isolated
21 import swarm_get_results 20 import swarm_get_results
21 from utils import net
22 22
23 23
24 TEST_CASE_SUCCESS = ( 24 TEST_CASE_SUCCESS = (
25 '[----------] 2 tests from StaticCookiePolicyTest\n' 25 '[----------] 2 tests from StaticCookiePolicyTest\n'
26 '[ RUN ] StaticCookiePolicyTest.AllowAllCookiesTest\n' 26 '[ RUN ] StaticCookiePolicyTest.AllowAllCookiesTest\n'
27 '[ OK ] StaticCookiePolicyTest.AllowAllCookiesTest (0 ms)\n' 27 '[ OK ] StaticCookiePolicyTest.AllowAllCookiesTest (0 ms)\n'
28 '[ RUN ] StaticCookiePolicyTest.BlockAllCookiesTest\n' 28 '[ RUN ] StaticCookiePolicyTest.BlockAllCookiesTest\n'
29 '[ OK ] StaticCookiePolicyTest.BlockAllCookiesTest (0 ms)\n' 29 '[ OK ] StaticCookiePolicyTest.BlockAllCookiesTest (0 ms)\n'
30 '[----------] 2 tests from StaticCookiePolicyTest (0 ms total)\n' 30 '[----------] 2 tests from StaticCookiePolicyTest (0 ms total)\n'
31 '\n' 31 '\n'
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 'http://host:9001', keys, 10., None)) 138 'http://host:9001', keys, 10., None))
139 139
140 140
141 class TestCase(auto_stub.TestCase): 141 class TestCase(auto_stub.TestCase):
142 """Base class that defines the url_open mock.""" 142 """Base class that defines the url_open mock."""
143 def setUp(self): 143 def setUp(self):
144 super(TestCase, self).setUp() 144 super(TestCase, self).setUp()
145 self._lock = threading.Lock() 145 self._lock = threading.Lock()
146 self.requests = [] 146 self.requests = []
147 self.mock( 147 self.mock(
148 swarm_get_results.run_isolated, 'url_open', 148 swarm_get_results.net, 'url_open',
149 self._url_open) 149 self._url_open)
150 150
151 def tearDown(self): 151 def tearDown(self):
152 try: 152 try:
153 if not self.has_failed(): 153 if not self.has_failed():
154 self.assertEqual([], self.requests) 154 self.assertEqual([], self.requests)
155 finally: 155 finally:
156 super(TestCase, self).tearDown() 156 super(TestCase, self).tearDown()
157 157
158 def _url_open(self, url, **kwargs): 158 def _url_open(self, url, **kwargs):
(...skipping 11 matching lines...) Expand all
170 170
171 171
172 class TestGetTestKeys(TestCase): 172 class TestGetTestKeys(TestCase):
173 def test_no_keys(self): 173 def test_no_keys(self):
174 self.mock(swarm_get_results.time, 'sleep', lambda x: x) 174 self.mock(swarm_get_results.time, 'sleep', lambda x: x)
175 self.requests = [ 175 self.requests = [
176 ( 176 (
177 'http://host:9001/get_matching_test_cases?name=my_test', 177 'http://host:9001/get_matching_test_cases?name=my_test',
178 {'retry_404': True}, 178 {'retry_404': True},
179 StringIO.StringIO('No matching Test Cases'), 179 StringIO.StringIO('No matching Test Cases'),
180 ) for _ in range(run_isolated.URL_OPEN_MAX_ATTEMPTS) 180 ) for _ in range(net.URL_OPEN_MAX_ATTEMPTS)
181 ] 181 ]
182 try: 182 try:
183 swarm_get_results.get_test_keys('http://host:9001', 'my_test') 183 swarm_get_results.get_test_keys('http://host:9001', 'my_test')
184 self.fail() 184 self.fail()
185 except swarm_get_results.Failure as e: 185 except swarm_get_results.Failure as e:
186 msg = ( 186 msg = (
187 'Error: Unable to find any tests with the name, my_test, on swarm ' 187 'Error: Unable to find any tests with the name, my_test, on swarm '
188 'server') 188 'server')
189 self.assertEqual(msg, e.args[0]) 189 self.assertEqual(msg, e.args[0])
190 190
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 expected = [gen_yielded_data(0, SWARM_OUTPUT_WITH_NO_TEST_OUTPUT, '0, 0')] 255 expected = [gen_yielded_data(0, SWARM_OUTPUT_WITH_NO_TEST_OUTPUT, '0, 0')]
256 actual = get_swarm_results(['key1']) 256 actual = get_swarm_results(['key1'])
257 self.assertEqual(expected, actual) 257 self.assertEqual(expected, actual)
258 258
259 def test_no_keys(self): 259 def test_no_keys(self):
260 actual = get_swarm_results([]) 260 actual = get_swarm_results([])
261 self.assertEqual([], actual) 261 self.assertEqual([], actual)
262 262
263 def test_url_errors(self): 263 def test_url_errors(self):
264 # NOTE: get_swarm_results() hardcodes timeout=10. range(12) is because of an 264 # NOTE: get_swarm_results() hardcodes timeout=10. range(12) is because of an
265 # additional time.time() call deep in run_isolated.url_open(). 265 # additional time.time() call deep in net.url_open().
266 now = {} 266 now = {}
267 lock = threading.Lock() 267 lock = threading.Lock()
268 def get_now(): 268 def get_now():
269 t = threading.current_thread() 269 t = threading.current_thread()
270 with lock: 270 with lock:
271 return now.setdefault(t, range(12)).pop(0) 271 return now.setdefault(t, range(12)).pop(0)
272 self.mock( 272 self.mock(
273 swarm_get_results.run_isolated.HttpService, 273 swarm_get_results.net.HttpService,
274 'sleep_before_retry', 274 'sleep_before_retry',
275 staticmethod(lambda _x, _y: None)) 275 staticmethod(lambda _x, _y: None))
276 self.mock(swarm_get_results, 'now', get_now) 276 self.mock(swarm_get_results, 'now', get_now)
277 # The actual number of requests here depends on 'now' progressing to 10 277 # The actual number of requests here depends on 'now' progressing to 10
278 # seconds. It's called twice per loop. 278 # seconds. It's called twice per loop.
279 self.requests = [ 279 self.requests = [
280 ( 280 (
281 'http://host:9001/get_result?r=key1', 281 'http://host:9001/get_result?r=key1',
282 {'retry_404': False, 'retry_50x': False}, 282 {'retry_404': False, 'retry_50x': False},
283 None, 283 None,
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 actual = get_swarm_results(['key1', 'key1-repeat', 'key2', 'key3']) 356 actual = get_swarm_results(['key1', 'key1-repeat', 'key2', 'key3'])
357 self.assertEqual(expected, sorted(actual)) 357 self.assertEqual(expected, sorted(actual))
358 358
359 359
360 if __name__ == '__main__': 360 if __name__ == '__main__':
361 logging.basicConfig( 361 logging.basicConfig(
362 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR) 362 level=logging.DEBUG if '-v' in sys.argv else logging.ERROR)
363 if '-v' in sys.argv: 363 if '-v' in sys.argv:
364 unittest.TestCase.maxDiff = None 364 unittest.TestCase.maxDiff = None
365 unittest.main() 365 unittest.main()
OLDNEW
« no previous file with comments | « tests/run_isolated_test.py ('k') | tests/swarm_trigger_step_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698