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

Side by Side Diff: tests/gclient_utils_test.py

Issue 2241843002: gclient: kill git fetch operation that hangs. (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Final. Created 4 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
« gclient_scm.py ('K') | « tests/gclient_scm_test.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
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 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 os 6 import os
7 import StringIO 7 import StringIO
8 import sys 8 import sys
9 import threading
9 10
10 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 11 sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
11 12
12 from testing_support.super_mox import SuperMoxTestBase 13 from testing_support.super_mox import SuperMoxTestBase
13 from testing_support import trial_dir 14 from testing_support import trial_dir
14 15
15 import gclient_utils 16 import gclient_utils
16 import subprocess2 17 import subprocess2
17 18
18 19
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 75
75 def testNoLF(self): 76 def testNoLF(self):
76 # Exactly as testCheckCallAndFilterAndHeader without trailing \n 77 # Exactly as testCheckCallAndFilterAndHeader without trailing \n
77 args = ['boo', 'foo', 'bar'] 78 args = ['boo', 'foo', 'bar']
78 test_string = 'ahah\naccb\nallo\naddb' 79 test_string = 'ahah\naccb\nallo\naddb'
79 self._inner(args, test_string) 80 self._inner(args, test_string)
80 self.checkstdout('\n________ running \'boo foo bar\' in \'bleh\'\n' 81 self.checkstdout('\n________ running \'boo foo bar\' in \'bleh\'\n'
81 'ahah\naccb\nallo\naddb\n' 82 'ahah\naccb\nallo\naddb\n'
82 '________ running \'boo foo bar\' in \'bleh\'\nahah\naccb\nallo\naddb') 83 '________ running \'boo foo bar\' in \'bleh\'\nahah\naccb\nallo\naddb')
83 84
85 def _checkKillTimeout(self, output_block_for=0, kill_raises=False):
86 cv = threading.Condition()
87 order = []
88
89 output = list(reversed('output'))
90 def kid_stdout_read(_):
91 if output:
92 return output.pop()
93 else:
94 with cv:
95 order.append('block')
96 cv.wait(timeout=output_block_for)
97 order.append('unblock')
98 return ''
99 def kid_kill():
100 with cv:
101 order.append('killed')
102 cv.notify() # unblock reader.
103 if kill_raises:
104 raise OSError('somethign went wrong')
105
106 kid = self.ProcessIdMock('')
107 kid.stdout.read = kid_stdout_read
108 kid.kill = kid_kill
109 cwd = 'bleh'
110 args = ['ar', 'gs']
111 gclient_utils.sys.stdout.write(
112 '\n________ running \'ar gs\' in \'bleh\'\noutput')
113 os.getcwd()
114 subprocess2.Popen(
115 args, cwd=cwd,
116 stdout=subprocess2.PIPE,
117 stderr=subprocess2.STDOUT,
118 bufsize=0).AndReturn(kid)
119 self.mox.ReplayAll()
120
121 # This test relies on the testing machine's ability to process 1 char
122 # of output in <0.01 seconds set in kill_timeout.
123 gclient_utils.CheckCallAndFilterAndHeader(
124 args, cwd=cwd, always=True, kill_timeout=0.01)
125 self.checkstdout(
126 '\n________ running \'ar gs\' in \'bleh\'\noutput\n'
127 '________ running \'ar gs\' in \'bleh\'\noutput')
128 return order
129
130 def testKillTimeout(self):
131 order = self._checkKillTimeout(output_block_for=1.0)
132 self.assertEquals(order, ['block', 'killed', 'unblock'])
133
134 def testKillRaise(self):
135 order = self._checkKillTimeout(output_block_for=1.0, kill_raises=True)
136 self.assertEquals(order, ['block', 'killed', 'unblock'])
137
138 def testNoKill(self):
139 order = self._checkKillTimeout(output_block_for=0.0)
140 self.assertEquals(order, ['block', 'unblock'])
141
84 142
85 class SplitUrlRevisionTestCase(GclientUtilBase): 143 class SplitUrlRevisionTestCase(GclientUtilBase):
86 def testSSHUrl(self): 144 def testSSHUrl(self):
87 url = "ssh://test@example.com/test.git" 145 url = "ssh://test@example.com/test.git"
88 rev = "ac345e52dc" 146 rev = "ac345e52dc"
89 out_url, out_rev = gclient_utils.SplitUrlRevision(url) 147 out_url, out_rev = gclient_utils.SplitUrlRevision(url)
90 self.assertEquals(out_rev, None) 148 self.assertEquals(out_rev, None)
91 self.assertEquals(out_url, url) 149 self.assertEquals(out_url, url)
92 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev)) 150 out_url, out_rev = gclient_utils.SplitUrlRevision("%s@%s" % (url, rev))
93 self.assertEquals(out_rev, rev) 151 self.assertEquals(out_rev, rev)
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 ], 254 ],
197 ['VIEW_VC:http://r/s', {'VIEW_VC': 'https://r/s'}], 255 ['VIEW_VC:http://r/s', {'VIEW_VC': 'https://r/s'}],
198 ] 256 ]
199 for content, expected in values: 257 for content, expected in values:
200 self.assertEquals( 258 self.assertEquals(
201 expected, gclient_utils.ParseCodereviewSettingsContent(content)) 259 expected, gclient_utils.ParseCodereviewSettingsContent(content))
202 260
203 261
204 if __name__ == '__main__': 262 if __name__ == '__main__':
205 import unittest 263 import unittest
264 import logging
265 level = logging.DEBUG if '-v' in sys.argv else logging.FATAL
266 logging.basicConfig(
267 level=level,
268 format='%(asctime).19s %(levelname)s %(filename)s:'
269 '%(lineno)s %(message)s')
206 unittest.main() 270 unittest.main()
207 271
208 # vim: ts=2:sw=2:tw=80:et: 272 # vim: ts=2:sw=2:tw=80:et:
OLDNEW
« gclient_scm.py ('K') | « tests/gclient_scm_test.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698