]> git.mxchange.org Git - friendica.git/blob - tests/src/Core/Lock/DatabaseLockDriverTest.php
Fixing some AutomaticInstallationConsoleTests
[friendica.git] / tests / src / Core / Lock / DatabaseLockDriverTest.php
1 <?php
2
3 namespace Friendica\Test\src\Core\Lock;
4
5 use Friendica\Core\Cache;
6 use Friendica\Core\Lock\DatabaseLockDriver;
7 use Friendica\Test\Util\DbaLockMockTrait;
8
9 /**
10  * @runTestsInSeparateProcesses
11  * @preserveGlobalState disabled
12  */
13 class DatabaseLockDriverTest extends LockTest
14 {
15         use DbaLockMockTrait;
16
17         protected $pid = 123;
18
19         protected function setUp()
20         {
21                 $this->mockConnected();
22                 $this->mockConnect();
23
24                 $this->mockReleaseAll($this->pid, 2);
25
26                 parent::setUp();
27         }
28
29         protected function getInstance()
30         {
31                 return new DatabaseLockDriver($this->pid);
32         }
33
34         public function testLock()
35         {
36                 $this->mockIsLocked('foo', false, $this->startTime, 1);
37                 $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
38                 $this->mockIsLocked('foo', true, $this->startTime, 1);
39                 $this->mockIsLocked('bar', false, $this->startTime, 1);
40
41                 parent::testLock();
42         }
43
44         public function testDoubleLock()
45         {
46                 $this->mockIsLocked('foo', false, $this->startTime, 1);
47                 $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
48                 $this->mockIsLocked('foo', true, $this->startTime, 1);
49                 $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, true, $this->pid, true, $this->startTime, 1);
50
51                 parent::testDoubleLock();
52         }
53
54         public function testReleaseLock()
55         {
56                 $this->mockIsLocked('foo', false, $this->startTime, 1);
57                 $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
58                 $this->mockIsLocked('foo', true, $this->startTime, 1);
59                 $this->mockReleaseLock('foo', $this->pid, 1);
60                 $this->mockIsLocked('foo', false, $this->startTime, 1);
61
62                 parent::testReleaseLock();
63         }
64
65         public function testReleaseAll()
66         {
67                 $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
68                 $this->mockAcquireLock('bar', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
69                 $this->mockAcquireLock('nice', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
70
71                 $this->mockIsLocked('foo', true, $this->startTime, 1);
72                 $this->mockIsLocked('bar', true, $this->startTime, 1);
73                 $this->mockIsLocked('nice', true, $this->startTime, 1);
74
75                 $this->mockReleaseAll($this->pid, 1);
76
77                 $this->mockIsLocked('foo', false, $this->startTime, 1);
78                 $this->mockIsLocked('bar', false, $this->startTime, 1);
79                 $this->mockIsLocked('nice', false, $this->startTime, 1);
80
81                 parent::testReleaseAll();
82         }
83
84         public function testReleaseAfterUnlock()
85         {
86                 $this->mockIsLocked('foo', false, $this->startTime, 1);
87                 $this->mockIsLocked('bar', false, $this->startTime, 1);
88                 $this->mockIsLocked('nice', false, $this->startTime, 1);
89
90                 $this->mockAcquireLock('foo', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
91                 $this->mockAcquireLock('bar', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
92                 $this->mockAcquireLock('nice', Cache::FIVE_MINUTES, false, $this->pid, false, $this->startTime, 1);
93
94                 $this->mockReleaseLock('foo', $this->pid, 1);
95
96                 $this->mockIsLocked('foo', false, $this->startTime, 1);
97                 $this->mockIsLocked('bar', true, $this->startTime, 1);
98                 $this->mockIsLocked('nice', true, $this->startTime, 1);
99
100                 $this->mockReleaseAll($this->pid, 1);
101
102                 $this->mockIsLocked('bar', false, $this->startTime, 1);
103                 $this->mockIsLocked('nice', false, $this->startTime, 1);
104
105                 parent::testReleaseAfterUnlock();
106         }
107
108         public function testReleaseWitTTL()
109         {
110                 $this->mockIsLocked('test', false, $this->startTime, 1);
111                 $this->mockAcquireLock('test', 10, false, $this->pid, false, $this->startTime, 1);
112                 $this->mockIsLocked('test', true, $this->startTime, 1);
113                 $this->mockReleaseLock('test', $this->pid, 1);
114                 $this->mockIsLocked('test', false, $this->startTime, 1);
115
116                 parent::testReleaseWitTTL();
117         }
118 }