MDL-67594 core_lock: Remove supports_recursion() usages
This commit is contained in:
+22
-22
@@ -70,35 +70,35 @@ class lock_testcase extends advanced_testcase {
|
||||
$this->assertNotEmpty($lock1, 'Get a lock');
|
||||
|
||||
if ($lockfactory->supports_timeout()) {
|
||||
if ($lockfactory->supports_recursion()) {
|
||||
$lock2 = $lockfactory->get_lock('abc', 2);
|
||||
// Attempt to obtain a lock within a 2 sec timeout.
|
||||
$durationlock2 = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 2);
|
||||
$durationlock2 += microtime(true);
|
||||
|
||||
if (!$lock2) { // If the lock was not obtained.
|
||||
$this->assertFalse($lock2, 'Cannot get a stacked lock');
|
||||
// This should timeout after 2 seconds.
|
||||
$this->assertTrue($durationlock2 < 2.5, 'Lock should timeout after no more than 2 seconds');
|
||||
} else {
|
||||
$this->assertNotEmpty($lock2, 'Get a stacked lock');
|
||||
$this->assertTrue($lock2->release(), 'Release a stacked lock');
|
||||
}
|
||||
|
||||
// Attempt to obtain a lock within a 0 sec timeout.
|
||||
$durationlock2 = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 0);
|
||||
$durationlock2 += microtime(true);
|
||||
|
||||
if (!$lock2) { // If the lock was not obtained.
|
||||
// This should timeout almost instantly.
|
||||
$this->assertTrue($durationlock2 < 0.100, 'Lock should timeout almost instantly < 100ms');
|
||||
} else {
|
||||
// This stacked lock should be gained almost instantly.
|
||||
$duration = -microtime(true);
|
||||
$lock3 = $lockfactory->get_lock('abc', 0);
|
||||
$duration += microtime(true);
|
||||
$lock3->release();
|
||||
$this->assertTrue($duration < 0.100, 'Lock should be gained almost instantly');
|
||||
$this->assertTrue($durationlock2 < 0.100, 'Lock should be gained almost instantly');
|
||||
$lock2->release();
|
||||
|
||||
// We should also assert that locks fail instantly if locked
|
||||
// from another process but this is hard to unit test.
|
||||
|
||||
} else {
|
||||
// This should timeout after 2 seconds.
|
||||
$duration = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 2);
|
||||
$duration += microtime(true);
|
||||
$this->assertFalse($lock2, 'Cannot get a stacked lock');
|
||||
$this->assertTrue($duration < 2.5, 'Lock should timeout after no more than 2 seconds');
|
||||
|
||||
// This should timeout almost instantly.
|
||||
$duration = -microtime(true);
|
||||
$lock2 = $lockfactory->get_lock('abc', 0);
|
||||
$duration += microtime(true);
|
||||
$this->assertFalse($lock2, 'Cannot get a stacked lock');
|
||||
$this->assertTrue($duration < 0.100, 'Lock should timeout almost instantly < 100ms');
|
||||
}
|
||||
}
|
||||
// Release the lock.
|
||||
|
||||
Reference in New Issue
Block a user