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

Side by Side Diff: tests/fake_repos.py

Issue 6681019: make unit tests pass on the mac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: update with better comments Created 9 years, 9 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 | « no previous file | tests/gclient_scm_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/python 1 #!/usr/bin/python
2 # Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2010 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 """Generate fake repositories for testing.""" 6 """Generate fake repositories for testing."""
7 7
8 import atexit 8 import atexit
9 import datetime 9 import datetime
10 import errno
10 import logging 11 import logging
11 import os 12 import os
12 import pprint 13 import pprint
13 import re 14 import re
14 import socket 15 import socket
15 import subprocess 16 import subprocess
16 import sys 17 import sys
17 import tempfile 18 import tempfile
19 import time
18 20
19 # trial_dir must be first for non-system libraries. 21 # trial_dir must be first for non-system libraries.
20 from tests import trial_dir 22 from tests import trial_dir
21 import gclient_utils 23 import gclient_utils
22 import scm 24 import scm
23 25
24 ## Utility functions 26 ## Utility functions
25 27
26 28
27 def kill_pid(pid): 29 def kill_pid(pid):
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 """Kills the servers and delete the directories.""" 232 """Kills the servers and delete the directories."""
231 self.tear_down_svn() 233 self.tear_down_svn()
232 self.tear_down_git() 234 self.tear_down_git()
233 # This deletes the directories. 235 # This deletes the directories.
234 self.trial.tear_down() 236 self.trial.tear_down()
235 self.trial = None 237 self.trial = None
236 238
237 def tear_down_svn(self): 239 def tear_down_svn(self):
238 if self.svnserve: 240 if self.svnserve:
239 logging.debug('Killing svnserve pid %s' % self.svnserve.pid) 241 logging.debug('Killing svnserve pid %s' % self.svnserve.pid)
240 self.svnserve.kill() 242 try:
243 self.svnserve.kill()
244 except OSError, e:
245 if e.errno != errno.ESRCH: # no such process
246 raise
241 self.wait_for_port_to_free(self.svn_port) 247 self.wait_for_port_to_free(self.svn_port)
242 self.svnserve = None 248 self.svnserve = None
243 if not self.trial.SHOULD_LEAK: 249 if not self.trial.SHOULD_LEAK:
244 logging.debug('Removing %s' % self.svn_repo) 250 logging.debug('Removing %s' % self.svn_repo)
245 gclient_utils.rmtree(self.svn_repo) 251 gclient_utils.rmtree(self.svn_repo)
246 logging.debug('Removing %s' % self.svn_checkout) 252 logging.debug('Removing %s' % self.svn_checkout)
247 gclient_utils.rmtree(self.svn_checkout) 253 gclient_utils.rmtree(self.svn_checkout)
248 else: 254 else:
249 return False 255 return False
250 return True 256 return True
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return False 302 return False
297 write(join(self.svn_repo, 'conf', 'svnserve.conf'), 303 write(join(self.svn_repo, 'conf', 'svnserve.conf'),
298 '[general]\n' 304 '[general]\n'
299 'anon-access = read\n' 305 'anon-access = read\n'
300 'auth-access = write\n' 306 'auth-access = write\n'
301 'password-db = passwd\n') 307 'password-db = passwd\n')
302 text = '[users]\n' 308 text = '[users]\n'
303 text += ''.join('%s = %s\n' % (usr, pwd) for usr, pwd in self.USERS) 309 text += ''.join('%s = %s\n' % (usr, pwd) for usr, pwd in self.USERS)
304 write(join(self.svn_repo, 'conf', 'passwd'), text) 310 write(join(self.svn_repo, 'conf', 'passwd'), text)
305 311
312 # Mac 10.6 ships with a buggy subversion build and we need this line
313 # to work around the bug.
314 write(join(self.svn_repo, 'db', 'fsfs.conf'),
315 '[rep-sharing]\n'
316 'enable-rep-sharing = false\n')
317
306 # Start the daemon. 318 # Start the daemon.
307 cmd = ['svnserve', '-d', '--foreground', '-r', self.root_dir] 319 cmd = ['svnserve', '-d', '--foreground', '-r', self.root_dir]
308 if self.host == '127.0.0.1': 320 if self.host == '127.0.0.1':
309 cmd.append('--listen-host=' + self.host) 321 cmd.append('--listen-host=' + self.host)
310 self.check_port_is_free(self.svn_port) 322 self.check_port_is_free(self.svn_port)
311 self.svnserve = Popen(cmd, cwd=self.svn_repo) 323 self.svnserve = Popen(cmd, cwd=self.svn_repo)
312 self.wait_for_port_to_bind(self.svn_port, self.svnserve) 324 self.wait_for_port_to_bind(self.svn_port, self.svnserve)
313 self.populateSvn() 325 self.populateSvn()
314 self.svn_dirty = False 326 self.svn_dirty = False
315 return True 327 return True
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 sock.connect((self.host, port)) 381 sock.connect((self.host, port))
370 # It worked, throw. 382 # It worked, throw.
371 assert False, '%d shouldn\'t be bound' % port 383 assert False, '%d shouldn\'t be bound' % port
372 except EnvironmentError: 384 except EnvironmentError:
373 pass 385 pass
374 finally: 386 finally:
375 sock.close() 387 sock.close()
376 388
377 def wait_for_port_to_bind(self, port, process): 389 def wait_for_port_to_bind(self, port, process):
378 sock = socket.socket() 390 sock = socket.socket()
391
392 if sys.platform == 'darwin':
393 # On Mac SnowLeopard, if we attempt to connect to the socket
394 # immediately, it fails with EINVAL and never gets a chance to
395 # connect (putting us into a hard spin and then failing).
396 # Linux doesn't need this.
397 time.sleep(0.1)
398
379 try: 399 try:
380 start = datetime.datetime.utcnow() 400 start = datetime.datetime.utcnow()
381 maxdelay = datetime.timedelta(seconds=30) 401 maxdelay = datetime.timedelta(seconds=30)
382 while (datetime.datetime.utcnow() - start) < maxdelay: 402 while (datetime.datetime.utcnow() - start) < maxdelay:
383 try: 403 try:
384 sock.connect((self.host, port)) 404 sock.connect((self.host, port))
385 logging.debug('%d is now bound' % port) 405 logging.debug('%d is now bound' % port)
386 return 406 return
387 except EnvironmentError: 407 except EnvironmentError:
388 pass 408 pass
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 fake.set_up_git() 747 fake.set_up_git()
728 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.') 748 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.')
729 sys.stdin.readline() 749 sys.stdin.readline()
730 except KeyboardInterrupt: 750 except KeyboardInterrupt:
731 trial_dir.TrialDir.SHOULD_LEAK.leak = True 751 trial_dir.TrialDir.SHOULD_LEAK.leak = True
732 return 0 752 return 0
733 753
734 754
735 if __name__ == '__main__': 755 if __name__ == '__main__':
736 sys.exit(main(sys.argv)) 756 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « no previous file | tests/gclient_scm_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698