Rev 2354: Add some basic locking tests which should currently pass on all platforms. in http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/locking

John Arbash Meinel john at arbash-meinel.com
Tue Mar 13 19:11:14 GMT 2007


At http://bzr.arbash-meinel.com/branches/bzr/0.15-dev/locking

------------------------------------------------------------
revno: 2354
revision-id: john at arbash-meinel.com-20070313191105-dlkexxbr3jvva1rx
parent: pqm at pqm.ubuntu.com-20070313175755-809681c81472204a
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: locking
timestamp: Tue 2007-03-13 13:11:05 -0600
message:
  Add some basic locking tests which should currently pass on all platforms.
added:
  bzrlib/tests/test_lock.py      test_lock.py-20070313190612-mfpoa7t8kvrgrhj2-1
modified:
  bzrlib/tests/__init__.py       selftest.py-20050531073622-8d0e3c8845c97a64
-------------- next part --------------
=== 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	2007-03-13 19:11:05 +0000
@@ -0,0 +1,75 @@
+# Copyright (C) 2007 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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Tests for OS level locks."""
+
+from bzrlib import (
+    lock,
+    tests,
+    )
+
+
+class TestLock(tests.TestCaseInTempDir):
+
+    def setUp(self):
+        super(TestLock, self).setUp()
+        self.build_tree(['a-file'])
+
+    def test_read_lock(self):
+        """Smoke test for read locks."""
+        a_lock = lock.ReadLock('a-file')
+        self.addCleanup(a_lock.unlock)
+        # The lock file should be opened for reading
+        txt = a_lock.f.read()
+        self.assertEqual('contents of a-file\n', txt)
+
+    def test_create_if_needed_read(self):
+        """We will create the file if it doesn't exist yet."""
+        a_lock = lock.ReadLock('other-file')
+        self.addCleanup(a_lock.unlock)
+        txt = a_lock.f.read()
+        self.assertEqual('', txt)
+
+    def test_create_if_needed_write(self):
+        """We will create the file if it doesn't exist yet."""
+        a_lock = lock.WriteLock('other-file')
+        self.addCleanup(a_lock.unlock)
+        txt = a_lock.f.read()
+        self.assertEqual('', txt)
+        a_lock.f.write('foo\n')
+        a_lock.f.seek(0)
+        txt = a_lock.f.read()
+        self.assertEqual('foo\n', txt)
+
+    def test_write_lock(self):
+        """Smoke test for write locks."""
+        a_lock = lock.WriteLock('a-file')
+        self.addCleanup(a_lock.unlock)
+        # You should be able to read and write to the lock file.
+        txt = a_lock.f.read()
+        self.assertEqual('contents of a-file\n', txt)
+        a_lock.f.write('more content\n')
+        a_lock.f.seek(0)
+        txt = a_lock.f.read()
+        self.assertEqual('contents of a-file\nmore content\n', txt)
+
+    def test_multiple_read_locks(self):
+        """You can take out more than one read lock on the same file."""
+        a_lock = lock.ReadLock('a-file')
+        self.addCleanup(a_lock.unlock)
+        b_lock = lock.ReadLock('a-file')
+        self.addCleanup(b_lock.unlock)
+

=== modified file 'bzrlib/tests/__init__.py'
--- a/bzrlib/tests/__init__.py	2007-03-12 20:55:23 +0000
+++ b/bzrlib/tests/__init__.py	2007-03-13 19:11:05 +0000
@@ -1950,6 +1950,7 @@
                    'bzrlib.tests.test_knit',
                    'bzrlib.tests.test_lazy_import',
                    'bzrlib.tests.test_lazy_regex',
+                   'bzrlib.tests.test_lock',
                    'bzrlib.tests.test_lockdir',
                    'bzrlib.tests.test_lockable_files',
                    'bzrlib.tests.test_log',



More information about the bazaar-commits mailing list