diff options
author | Joas Schilling <nickvergessen@gmx.de> | 2013-04-30 15:48:29 +0200 |
---|---|---|
committer | Joas Schilling <nickvergessen@gmx.de> | 2013-04-30 15:48:29 +0200 |
commit | 714092ab4e52dc039536a05846b50f4d4d488799 (patch) | |
tree | 0f31a91f6aa0aeddfe2d256d669e4e894228f808 /tests/lock | |
parent | [ticket/11495] Remove useless cast (diff) | |
download | phpbb-714092ab4e52dc039536a05846b50f4d4d488799.tar.gz phpbb-714092ab4e52dc039536a05846b50f4d4d488799.tar.bz2 phpbb-714092ab4e52dc039536a05846b50f4d4d488799.zip |
[ticket/11495] Add owns_lock() method to lock classes
PHPBB3-11495
Diffstat (limited to 'tests/lock')
-rw-r--r-- | tests/lock/db_test.php | 14 | ||||
-rw-r--r-- | tests/lock/flock_test.php | 11 |
2 files changed, 25 insertions, 0 deletions
diff --git a/tests/lock/db_test.php b/tests/lock/db_test.php index f7b1557a0c..de7a23fd05 100644 --- a/tests/lock/db_test.php +++ b/tests/lock/db_test.php @@ -32,13 +32,18 @@ class phpbb_lock_db_test extends phpbb_database_test_case public function test_new_lock() { + $this->assertFalse($this->lock->owns_lock()); + $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $this->assertFalse($lock2->acquire()); + $this->assertFalse($lock2->owns_lock()); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); } @@ -50,31 +55,40 @@ class phpbb_lock_db_test extends phpbb_database_test_case public function test_double_lock() { + $this->assertFalse($this->lock->owns_lock()); + $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertTrue(isset($this->config['test_lock']), 'Lock was created'); $value = $this->config['test_lock']; $this->assertFalse($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertEquals($value, $this->config['test_lock'], 'Second lock failed'); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'Lock was released'); } public function test_double_unlock() { $this->assertTrue($this->lock->acquire()); + $this->assertTrue($this->lock->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'First lock is acquired'); $this->lock->release(); + $this->assertFalse($this->lock->owns_lock()); $this->assertEquals('0', $this->config['test_lock'], 'First lock is released'); $lock2 = new phpbb_lock_db('test_lock', $this->config, $this->db); $this->assertTrue($lock2->acquire()); + $this->assertTrue($lock2->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'Second lock is acquired'); $this->lock->release(); + $this->assertTrue($lock2->owns_lock()); $this->assertFalse(empty($this->config['test_lock']), 'Double release of first lock is ignored'); $lock2->release(); diff --git a/tests/lock/flock_test.php b/tests/lock/flock_test.php index 1edc96b3a4..8f0b866ab3 100644 --- a/tests/lock/flock_test.php +++ b/tests/lock/flock_test.php @@ -26,15 +26,21 @@ class phpbb_lock_flock_test extends phpbb_test_case $lock = new phpbb_lock_flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $lock->release(); + $this->assertFalse($lock->owns_lock()); } /* This hangs the process. @@ -77,15 +83,18 @@ class phpbb_lock_flock_test extends phpbb_test_case $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $this->assertGreaterThan(0.5, $delta, 'First lock acquired too soon'); $lock->release(); + $this->assertFalse($lock->owns_lock()); // acquire again, this should be instantaneous $start = time(); $ok = $lock->acquire(); $delta = time() - $start; $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); $this->assertLessThan(0.1, $delta, 'Second lock not acquired instantaneously'); // reap the child @@ -99,8 +108,10 @@ class phpbb_lock_flock_test extends phpbb_test_case $lock = new phpbb_lock_flock($path); $ok = $lock->acquire(); $this->assertTrue($ok); + $this->assertTrue($lock->owns_lock()); sleep(2); $lock->release(); + $this->assertFalse($lock->owns_lock()); // and go away silently pcntl_exec('/usr/bin/env', array('true')); |