-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMutexLockTest.php
More file actions
57 lines (49 loc) · 1.33 KB
/
MutexLockTest.php
File metadata and controls
57 lines (49 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php declare(strict_types=1);
namespace Tests\DEQue;
use PHPUnit\Framework\TestCase;
/**
* 测试 php-deque\DEQue\MutexLock
*
* @author fdipzone
*/
final class MutexLockTest extends TestCase
{
/**
* @covers \DEQue\MutexLock::__construct
* @covers \DEQue\MutexLock::lock
*/
public function testLock()
{
// 不设置标识
$mutex = new \DEQue\MutexLock();
$ret = $mutex->lock();
$this->assertSame(true, $ret);
// 设置标识
$mutex = new \DEQue\MutexLock('abc');
$ret = $mutex->lock(100);
$this->assertSame(true, $ret);
// 可重入
$ret = $mutex->lock(100);
$this->assertSame(true, $ret);
}
/**
* @covers \DEQue\MutexLock::__construct
* @covers \DEQue\MutexLock::unlock
*/
public function testUnLock()
{
// 没加锁,直接调用解锁
$mutex = new \DEQue\MutexLock();
$ret = $mutex->unlock();
$this->assertSame(false, $ret);
// 加锁后调用解锁
$mutex = new \DEQue\MutexLock('abc');
$ret = $mutex->lock(-1);
$this->assertSame(true, $ret);
$ret = $mutex->unlock();
$this->assertSame(true, $ret);
// 解锁后再调用解锁
$ret = $mutex->unlock();
$this->assertSame(false, $ret);
}
}