~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-12 08:08:54 UTC
  • mfrom: (4327.1.12 failing-lock-tests)
  • mto: This revision was merged to the branch mainline in revision 4354.
  • Revision ID: v.ladeuil+lp@free.fr-20090512080854-jrius5e8zdapzin9
Fix unbalanced locks in tests, the check is now fatal (use -Dlock to turn it into a warning).

Show diffs side-by-side

added added

removed removed

Lines of Context:
586
586
            '')
587
587
        self.assertEqual(SuccessfulSmartServerResponse(()), result)
588
588
        self.assertEqual('bar', config.get_option('foo'))
 
589
        # Cleanup
 
590
        branch.unlock()
589
591
 
590
592
    def test_value_name_section(self):
591
593
        branch = self.make_branch('.')
597
599
            'gam')
598
600
        self.assertEqual(SuccessfulSmartServerResponse(()), result)
599
601
        self.assertEqual('bar', config.get_option('foo', 'gam'))
 
602
        # Cleanup
 
603
        branch.unlock()
600
604
 
601
605
 
602
606
class SetLastRevisionTestBase(TestLockedBranch):
915
919
        # with a new branch object.
916
920
        new_branch = repository.bzrdir.open_branch()
917
921
        self.assertRaises(errors.LockContention, new_branch.lock_write)
 
922
        # Cleanup
 
923
        request = smart.branch.SmartServerBranchRequestUnlock(backing)
 
924
        response = request.execute('', branch_nonce, repository_nonce)
918
925
 
919
926
    def test_lock_write_on_locked_branch(self):
920
927
        backing = self.get_transport()
921
928
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
922
929
        branch = self.make_branch('.')
923
 
        branch.lock_write()
 
930
        branch_token = branch.lock_write()
924
931
        branch.leave_lock_in_place()
925
932
        branch.unlock()
926
933
        response = request.execute('')
927
934
        self.assertEqual(
928
935
            SmartServerResponse(('LockContention',)), response)
 
936
        # Cleanup
 
937
        branch.lock_write(branch_token)
 
938
        branch.dont_leave_lock_in_place()
 
939
        branch.unlock()
929
940
 
930
941
    def test_lock_write_with_tokens_on_locked_branch(self):
931
942
        backing = self.get_transport()
941
952
                                   branch_token, repo_token)
942
953
        self.assertEqual(
943
954
            SmartServerResponse(('ok', branch_token, repo_token)), response)
 
955
        # Cleanup
 
956
        branch.repository.lock_write(repo_token)
 
957
        branch.repository.dont_leave_lock_in_place()
 
958
        branch.repository.unlock()
 
959
        branch.lock_write(branch_token)
 
960
        branch.dont_leave_lock_in_place()
 
961
        branch.unlock()
944
962
 
945
963
    def test_lock_write_with_mismatched_tokens_on_locked_branch(self):
946
964
        backing = self.get_transport()
956
974
                                   branch_token+'xxx', repo_token)
957
975
        self.assertEqual(
958
976
            SmartServerResponse(('TokenMismatch',)), response)
 
977
        # Cleanup
 
978
        branch.repository.lock_write(repo_token)
 
979
        branch.repository.dont_leave_lock_in_place()
 
980
        branch.repository.unlock()
 
981
        branch.lock_write(branch_token)
 
982
        branch.dont_leave_lock_in_place()
 
983
        branch.unlock()
959
984
 
960
985
    def test_lock_write_on_locked_repo(self):
961
986
        backing = self.get_transport()
962
987
        request = smart.branch.SmartServerBranchRequestLockWrite(backing)
963
988
        branch = self.make_branch('.', format='knit')
964
 
        branch.repository.lock_write()
965
 
        branch.repository.leave_lock_in_place()
966
 
        branch.repository.unlock()
 
989
        repo = branch.repository
 
990
        repo_token = repo.lock_write()
 
991
        repo.leave_lock_in_place()
 
992
        repo.unlock()
967
993
        response = request.execute('')
968
994
        self.assertEqual(
969
995
            SmartServerResponse(('LockContention',)), response)
 
996
        # Cleanup
 
997
        repo.lock_write(repo_token)
 
998
        repo.dont_leave_lock_in_place()
 
999
        repo.unlock()
970
1000
 
971
1001
    def test_lock_write_on_readonly_transport(self):
972
1002
        backing = self.get_readonly_transport()
1031
1061
            '', 'branch token', repo_token)
1032
1062
        self.assertEqual(
1033
1063
            SmartServerResponse(('TokenMismatch',)), response)
 
1064
        # Cleanup
 
1065
        branch.repository.lock_write(repo_token)
 
1066
        branch.repository.dont_leave_lock_in_place()
 
1067
        branch.repository.unlock()
1034
1068
 
1035
1069
 
1036
1070
class TestSmartServerRepositoryRequest(tests.TestCaseWithMemoryTransport):
1282
1316
        # object.
1283
1317
        new_repo = repository.bzrdir.open_repository()
1284
1318
        self.assertRaises(errors.LockContention, new_repo.lock_write)
 
1319
        # Cleanup
 
1320
        request = smart.repository.SmartServerRepositoryUnlock(backing)
 
1321
        response = request.execute('', nonce)
1285
1322
 
1286
1323
    def test_lock_write_on_locked_repo(self):
1287
1324
        backing = self.get_transport()
1288
1325
        request = smart.repository.SmartServerRepositoryLockWrite(backing)
1289
1326
        repository = self.make_repository('.', format='knit')
1290
 
        repository.lock_write()
 
1327
        repo_token = repository.lock_write()
1291
1328
        repository.leave_lock_in_place()
1292
1329
        repository.unlock()
1293
1330
        response = request.execute('')
1294
1331
        self.assertEqual(
1295
1332
            SmartServerResponse(('LockContention',)), response)
 
1333
        # Cleanup
 
1334
        repository.lock_write(repo_token)
 
1335
        repository.dont_leave_lock_in_place()
 
1336
        repository.unlock()
1296
1337
 
1297
1338
    def test_lock_write_on_readonly_transport(self):
1298
1339
        backing = self.get_readonly_transport()