Mercurial > hgsubversion
comparison tests/test_push_command.py @ 336:c0b943cef0c3
Use try/finally in an attempt to stop leaking svnserve processes.
| author | Augie Fackler <durin42@gmail.com> |
|---|---|
| date | Wed, 13 May 2009 10:22:18 -0500 |
| parents | 75f082b5897e |
| children | 46e69be8e2c8 |
comparison
equal
deleted
inserted
replaced
| 335:9ef720a611e0 | 336:c0b943cef0c3 |
|---|---|
| 15 | 15 |
| 16 import test_util | 16 import test_util |
| 17 import time | 17 import time |
| 18 | 18 |
| 19 | 19 |
| 20 class PushOverSvnserveTests(test_util.TestBase): | 20 class PushTests(test_util.TestBase): |
| 21 def setUp(self): | 21 def setUp(self): |
| 22 test_util.TestBase.setUp(self) | 22 test_util.TestBase.setUp(self) |
| 23 test_util.load_fixture_and_fetch('simple_branch.svndump', | |
| 24 self.repo_path, | |
| 25 self.wc_path) | |
| 26 | |
| 27 def test_cant_push_empty_ctx(self): | |
| 28 repo = self.repo | |
| 29 def file_callback(repo, memctx, path): | |
| 30 if path == 'adding_file': | |
| 31 return context.memfilectx(path=path, | |
| 32 data='foo', | |
| 33 islink=False, | |
| 34 isexec=False, | |
| 35 copied=False) | |
| 36 raise IOError() | |
| 37 ctx = context.memctx(repo, | |
| 38 (repo['default'].node(), node.nullid), | |
| 39 'automated test', | |
| 40 [], | |
| 41 file_callback, | |
| 42 'an_author', | |
| 43 '2008-10-07 20:59:48 -0500', | |
| 44 {'branch': 'default',}) | |
| 45 new_hash = repo.commitctx(ctx) | |
| 46 hg.update(repo, repo['tip'].node()) | |
| 47 old_tip = repo['tip'].node() | |
| 48 self.pushrevisions() | |
| 49 tip = self.repo['tip'] | |
| 50 self.assertEqual(tip.node(), old_tip) | |
| 51 | |
| 52 def test_push_over_svnserve(self, commit=True): | |
| 23 test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump') | 53 test_util.load_svndump_fixture(self.repo_path, 'simple_branch.svndump') |
| 24 open(os.path.join(self.repo_path, 'conf', 'svnserve.conf'), | 54 open(os.path.join(self.repo_path, 'conf', 'svnserve.conf'), |
| 25 'w').write('[general]\nanon-access=write\n[sasl]\n') | 55 'w').write('[general]\nanon-access=write\n[sasl]\n') |
| 26 self.port = random.randint(socket.IPPORT_USERRESERVED, 65535) | 56 self.port = random.randint(socket.IPPORT_USERRESERVED, 65535) |
| 27 self.host = 'localhost' | 57 self.host = 'localhost' |
| 28 args = ['svnserve', '--daemon', '--foreground', | 58 args = ['svnserve', '--daemon', '--foreground', |
| 29 '--listen-port=%d' % self.port, | 59 '--listen-port=%d' % self.port, |
| 30 '--listen-host=%s' % self.host, | 60 '--listen-host=%s' % self.host, |
| 31 '--root=%s' % self.repo_path] | 61 '--root=%s' % self.repo_path] |
| 32 svnserve = subprocess.Popen(args, stdout=subprocess.PIPE, | 62 |
| 33 stderr=subprocess.STDOUT) | 63 self.svnserve_pid = subprocess.Popen(args).pid |
| 34 self.svnserve_pid = svnserve.pid | 64 try: |
| 35 time.sleep(2) | 65 time.sleep(2) |
| 36 commands.clone(ui.ui(), 'svn://%s:%d/' % (self.host, self.port), | 66 commands.clone(ui.ui(), 'svn://%s:%d/' % (self.host, self.port), |
| 37 self.wc_path, noupdate=True) | 67 self.wc_path, noupdate=True) |
| 38 | 68 |
| 39 def tearDown(self): | 69 repo = self.repo |
| 40 os.kill(self.svnserve_pid, 9) | 70 old_tip = repo['tip'].node() |
| 41 test_util.TestBase.tearDown(self) | 71 expected_parent = repo['default'].node() |
| 42 | 72 def file_callback(repo, memctx, path): |
| 43 def test_push_to_default(self, commit=True): | 73 if path == 'adding_file': |
| 44 repo = self.repo | 74 return context.memfilectx(path=path, |
| 45 old_tip = repo['tip'].node() | 75 data='foo', |
| 46 expected_parent = repo['default'].node() | 76 islink=False, |
| 47 def file_callback(repo, memctx, path): | 77 isexec=False, |
| 48 if path == 'adding_file': | 78 copied=False) |
| 49 return context.memfilectx(path=path, | 79 raise IOError() |
| 50 data='foo', | 80 ctx = context.memctx(repo, |
| 51 islink=False, | 81 (repo['default'].node(), node.nullid), |
| 52 isexec=False, | 82 'automated test', |
| 53 copied=False) | 83 ['adding_file'], |
| 54 raise IOError() | 84 file_callback, |
| 55 ctx = context.memctx(repo, | 85 'an_author', |
| 56 (repo['default'].node(), node.nullid), | 86 '2008-10-07 20:59:48 -0500', |
| 57 'automated test', | 87 {'branch': 'default',}) |
| 58 ['adding_file'], | 88 new_hash = repo.commitctx(ctx) |
| 59 file_callback, | 89 if not commit: |
| 60 'an_author', | 90 return # some tests use this test as an extended setup. |
| 61 '2008-10-07 20:59:48 -0500', | 91 hg.update(repo, repo['tip'].node()) |
| 62 {'branch': 'default',}) | 92 oldauthor = repo['tip'].user() |
| 63 new_hash = repo.commitctx(ctx) | 93 commands.push(repo.ui, repo) |
| 64 if not commit: | 94 tip = self.repo['tip'] |
| 65 return # some tests use this test as an extended setup. | 95 self.assertNotEqual(oldauthor, tip.user()) |
| 66 hg.update(repo, repo['tip'].node()) | 96 self.assertNotEqual(tip.node(), old_tip) |
| 67 oldauthor = repo['tip'].user() | 97 self.assertEqual(tip.parents()[0].node(), expected_parent) |
| 68 commands.push(repo.ui, repo) | 98 self.assertEqual(tip['adding_file'].data(), 'foo') |
| 69 tip = self.repo['tip'] | 99 self.assertEqual(tip.branch(), 'default') |
| 70 self.assertNotEqual(oldauthor, tip.user()) | 100 finally: |
| 71 self.assertNotEqual(tip.node(), old_tip) | 101 os.kill(self.svnserve_pid, 9) |
| 72 self.assertEqual(tip.parents()[0].node(), expected_parent) | |
| 73 self.assertEqual(tip['adding_file'].data(), 'foo') | |
| 74 self.assertEqual(tip.branch(), 'default') | |
| 75 | |
| 76 | |
| 77 class PushTests(test_util.TestBase): | |
| 78 def setUp(self): | |
| 79 test_util.TestBase.setUp(self) | |
| 80 test_util.load_fixture_and_fetch('simple_branch.svndump', | |
| 81 self.repo_path, | |
| 82 self.wc_path) | |
| 83 | |
| 84 def test_cant_push_empty_ctx(self): | |
| 85 repo = self.repo | |
| 86 def file_callback(repo, memctx, path): | |
| 87 if path == 'adding_file': | |
| 88 return context.memfilectx(path=path, | |
| 89 data='foo', | |
| 90 islink=False, | |
| 91 isexec=False, | |
| 92 copied=False) | |
| 93 raise IOError() | |
| 94 ctx = context.memctx(repo, | |
| 95 (repo['default'].node(), node.nullid), | |
| 96 'automated test', | |
| 97 [], | |
| 98 file_callback, | |
| 99 'an_author', | |
| 100 '2008-10-07 20:59:48 -0500', | |
| 101 {'branch': 'default',}) | |
| 102 new_hash = repo.commitctx(ctx) | |
| 103 hg.update(repo, repo['tip'].node()) | |
| 104 old_tip = repo['tip'].node() | |
| 105 self.pushrevisions() | |
| 106 tip = self.repo['tip'] | |
| 107 self.assertEqual(tip.node(), old_tip) | |
| 108 | |
| 109 | 102 |
| 110 def test_push_to_default(self, commit=True): | 103 def test_push_to_default(self, commit=True): |
| 111 repo = self.repo | 104 repo = self.repo |
| 112 old_tip = repo['tip'].node() | 105 old_tip = repo['tip'].node() |
| 113 expected_parent = repo['default'].node() | 106 expected_parent = repo['default'].node() |
| 417 self.assertEqual(e.args[0], | 410 self.assertEqual(e.args[0], |
| 418 'Base text was out of date, maybe rebase?') | 411 'Base text was out of date, maybe rebase?') |
| 419 | 412 |
| 420 | 413 |
| 421 def suite(): | 414 def suite(): |
| 422 test_classes = [PushTests, PushOverSvnserveTests] | 415 test_classes = [PushTests, ] |
| 423 tests = [] | 416 tests = [] |
| 424 # This is the quickest hack I could come up with to load all the tests from | 417 # This is the quickest hack I could come up with to load all the tests from |
| 425 # both classes. Would love a patch that simplifies this without adding | 418 # both classes. Would love a patch that simplifies this without adding |
| 426 # dependencies. | 419 # dependencies. |
| 427 for tc in test_classes: | 420 for tc in test_classes: |
