Rev 4524: Start adding some direct testing for read and write locks. in http://bazaar.launchpad.net/~jameinel/bzr/1.18-lock-warnings
John Arbash Meinel
john at arbash-meinel.com
Fri Jul 10 18:51:06 BST 2009
At http://bazaar.launchpad.net/~jameinel/bzr/1.18-lock-warnings
------------------------------------------------------------
revno: 4524
revision-id: john at arbash-meinel.com-20090710175054-u0mp3mc7pbjd8xgl
parent: pqm at pqm.ubuntu.com-20090709014400-y2e7prh8mejs2j26
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.18-lock-warnings
timestamp: Fri 2009-07-10 12:50:54 -0500
message:
Start adding some direct testing for read and write locks.
-------------- next part --------------
=== modified file 'bzrlib/lock.py'
--- a/bzrlib/lock.py 2009-07-07 09:00:59 +0000
+++ b/bzrlib/lock.py 2009-07-10 17:50:54 +0000
@@ -399,15 +399,15 @@
DWORD, # dwFlagsAndAttributes
HANDLE # hTemplateFile
)((_function_name, ctypes.windll.kernel32))
-
+
INVALID_HANDLE_VALUE = -1
-
+
GENERIC_READ = 0x80000000
GENERIC_WRITE = 0x40000000
FILE_SHARE_READ = 1
OPEN_ALWAYS = 4
FILE_ATTRIBUTE_NORMAL = 128
-
+
ERROR_ACCESS_DENIED = 5
ERROR_SHARING_VIOLATION = 32
=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py 2009-07-02 21:17:35 +0000
+++ b/bzrlib/tests/__init__.py 2009-07-10 17:50:54 +0000
@@ -3414,6 +3414,7 @@
'bzrlib.tests.test_knit',
'bzrlib.tests.test_lazy_import',
'bzrlib.tests.test_lazy_regex',
+ 'bzrlib.tests.test_lock',
'bzrlib.tests.test_lockable_files',
'bzrlib.tests.test_lockdir',
'bzrlib.tests.test_log',
=== added file 'bzrlib/tests/test_lock.py'
--- a/bzrlib/tests/test_lock.py 1970-01-01 00:00:00 +0000
+++ b/bzrlib/tests/test_lock.py 2009-07-10 17:50:54 +0000
@@ -0,0 +1,62 @@
+# Copyright (C) 2009 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+"""Tests for OS Locks."""
+
+
+
+from bzrlib import (
+ lock,
+ errors,
+ tests,
+ )
+
+
+def load_tests(standard_tests, module, loader):
+ """Parameterize tests for all versions of groupcompress."""
+ scenarios = []
+ for name, write_lock, read_lock in lock._lock_classes:
+ scenarios.append((name, {'write_lock': write_lock,
+ 'read_lock': read_lock}))
+ suite = loader.suiteClass()
+ result = tests.multiply_tests(standard_tests, scenarios, suite)
+ return result
+
+
+class TestOSLock(tests.TestCaseInTempDir):
+
+ # Set by load_tests
+ read_lock = None
+ write_lock = None
+
+ def test_create_read_lock(self):
+ self.build_tree(['a-lock-file'])
+ lock = self.read_lock('a-lock-file')
+ lock.unlock()
+
+ def test_create_write_lock(self):
+ self.build_tree(['a-lock-file'])
+ lock = self.write_lock('a-lock-file')
+ lock.unlock()
+
+ def test_write_locks_are_exclusive(self):
+ self.build_tree(['a-lock-file'])
+ lock = self.write_lock('a-lock-file')
+ try:
+ self.assertRaises(errors.LockContention,
+ self.write_lock, 'a-lock-file')
+ finally:
+ lock.unlock()
More information about the bazaar-commits
mailing list