From 10d6a8ad4f09455809a250238782269580c38124 Mon Sep 17 00:00:00 2001 From: doctrine Date: Wed, 7 Jun 2006 12:16:00 +0000 Subject: [PATCH] Added a test case for the first implementation of pessimistic offline locking. --- tests/PessimisticLockingTestCase.php | 67 ++++++++++++++++++++++++++++ tests/run.php | 3 ++ 2 files changed, 70 insertions(+) create mode 100644 tests/PessimisticLockingTestCase.php diff --git a/tests/PessimisticLockingTestCase.php b/tests/PessimisticLockingTestCase.php new file mode 100644 index 000000000..531cf2146 --- /dev/null +++ b/tests/PessimisticLockingTestCase.php @@ -0,0 +1,67 @@ +lockingManager = new Doctrine_Locking_Manager_Pessimistic($this->session); + + // Create sample data to test on + $entry1 = new Forum_Entry(); + $entry1->author = 'Bart Simpson'; + $entry1->topic = 'I love donuts!'; + $entry1->save(); + } + + /** + * Tests the basic locking mechanism + * + * Currently tested: successful lock, failed lock, release lock + */ + public function testLock() + { + $entries = $this->session->query("FROM Forum_Entry WHERE Forum_Entry.author = 'Bart Simpson'"); + + // Test successful lock + $gotLock = $this->lockingManager->getLock($entries[0], 'romanb'); + $this->assertTrue($gotLock); + + // Test failed lock (another user already got a lock on the entry) + $gotLock = $this->lockingManager->getLock($entries[0], 'konstav'); + $this->assertFalse($gotLock); + + // Test release lock + $released = $this->lockingManager->releaseLock($entries[0], 'romanb'); + $this->assertTrue($released); + } + + /** + * Tests the release mechanism of aged locks + */ + public function testReleaseAgedLocks() + { + $entries = $this->session->query("FROM Forum_Entry WHERE Forum_Entry.author = 'Bart Simpson'"); + $this->lockingManager->getLock($entries[0], 'romanb'); + $released = $this->lockingManager->releaseAgedLocks(-1); // age -1 seconds => release all + $this->assertTrue($released); + + // A second call should return false (no locks left) + $released = $this->lockingManager->releaseAgedLocks(-1); + $this->assertFalse($released); + } +} + + + +?> \ No newline at end of file diff --git a/tests/run.php b/tests/run.php index c2696e43a..bc486415e 100644 --- a/tests/run.php +++ b/tests/run.php @@ -12,6 +12,7 @@ require_once("RecordTestCase.php"); require_once("AccessTestCase.php"); require_once("ValidatorTestCase.php"); require_once("CollectionTestCase.php"); +require_once("PessimisticLockingTestCase.php"); require_once("CacheSqliteTestCase.php"); require_once("CollectionOffsetTestCase.php"); @@ -45,6 +46,8 @@ $test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_QueryTestCase()); +$test->addTestCase(new Doctrine_PessimisticLockingTestCase()); + //$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());