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

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: tweak svn configuration to make work on mac 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 # This is needed on the Mac for some reason.
313 write(join(self.svn_repo, 'db', 'fsfs.conf'),
314 '[rep-sharing]\n'
315 'enable-rep-sharing = false\n')
316
306 # Start the daemon. 317 # Start the daemon.
307 cmd = ['svnserve', '-d', '--foreground', '-r', self.root_dir] 318 cmd = ['svnserve', '-d', '--foreground', '-r', self.root_dir]
308 if self.host == '127.0.0.1': 319 if self.host == '127.0.0.1':
309 cmd.append('--listen-host=' + self.host) 320 cmd.append('--listen-host=' + self.host)
310 self.check_port_is_free(self.svn_port) 321 self.check_port_is_free(self.svn_port)
311 self.svnserve = Popen(cmd, cwd=self.svn_repo) 322 self.svnserve = Popen(cmd, cwd=self.svn_repo)
312 self.wait_for_port_to_bind(self.svn_port, self.svnserve) 323 self.wait_for_port_to_bind(self.svn_port, self.svnserve)
313 self.populateSvn() 324 self.populateSvn()
314 self.svn_dirty = False 325 self.svn_dirty = False
315 return True 326 return True
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 sock.connect((self.host, port)) 380 sock.connect((self.host, port))
370 # It worked, throw. 381 # It worked, throw.
371 assert False, '%d shouldn\'t be bound' % port 382 assert False, '%d shouldn\'t be bound' % port
372 except EnvironmentError: 383 except EnvironmentError:
373 pass 384 pass
374 finally: 385 finally:
375 sock.close() 386 sock.close()
376 387
377 def wait_for_port_to_bind(self, port, process): 388 def wait_for_port_to_bind(self, port, process):
378 sock = socket.socket() 389 sock = socket.socket()
390
391 if sys.platform == 'darwin':
M-A Ruel 2011/03/12 15:39:17 ?? What happen otherwise? I'd rather have a time.
392 # Mac seems a bit slow, so give the daemon a chance to start up.
393 time.sleep(0.1)
394
379 try: 395 try:
380 start = datetime.datetime.utcnow() 396 start = datetime.datetime.utcnow()
381 maxdelay = datetime.timedelta(seconds=30) 397 maxdelay = datetime.timedelta(seconds=30)
382 while (datetime.datetime.utcnow() - start) < maxdelay: 398 while (datetime.datetime.utcnow() - start) < maxdelay:
383 try: 399 try:
384 sock.connect((self.host, port)) 400 sock.connect((self.host, port))
385 logging.debug('%d is now bound' % port) 401 logging.debug('%d is now bound' % port)
386 return 402 return
387 except EnvironmentError: 403 except EnvironmentError:
388 pass 404 pass
(...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
727 fake.set_up_git() 743 fake.set_up_git()
728 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.') 744 print('Fake setup, press enter to quit or Ctrl-C to keep the checkouts.')
729 sys.stdin.readline() 745 sys.stdin.readline()
730 except KeyboardInterrupt: 746 except KeyboardInterrupt:
731 trial_dir.TrialDir.SHOULD_LEAK.leak = True 747 trial_dir.TrialDir.SHOULD_LEAK.leak = True
732 return 0 748 return 0
733 749
734 750
735 if __name__ == '__main__': 751 if __name__ == '__main__':
736 sys.exit(main(sys.argv)) 752 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