3 namespace Friendica\Test\src\Core\Lock;
5 use Friendica\Core\Cache;
6 use Friendica\Core\Lock\DatabaseLockDriver;
7 use Friendica\Test\Util\DbaLockMockTrait;
10 * @runTestsInSeparateProcesses
11 * @preserveGlobalState disabled
13 class DatabaseLockDriverTest extends LockTest
19 protected function setUp()
21 $this->mockConnected();
24 $this->mockReleaseAll($this->pid, 2);
29 protected function getInstance()
31 return new DatabaseLockDriver($this->pid);
34 public function testLock()
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);
44 public function testDoubleLock()
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);
51 parent::testDoubleLock();
54 public function testReleaseLock()
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);
62 parent::testReleaseLock();
65 public function testReleaseAll()
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);
71 $this->mockIsLocked('foo', true, $this->startTime, 1);
72 $this->mockIsLocked('bar', true, $this->startTime, 1);
73 $this->mockIsLocked('nice', true, $this->startTime, 1);
75 $this->mockReleaseAll($this->pid, 1);
77 $this->mockIsLocked('foo', false, $this->startTime, 1);
78 $this->mockIsLocked('bar', false, $this->startTime, 1);
79 $this->mockIsLocked('nice', false, $this->startTime, 1);
81 parent::testReleaseAll();
84 public function testReleaseAfterUnlock()
86 $this->mockIsLocked('foo', false, $this->startTime, 1);
87 $this->mockIsLocked('bar', false, $this->startTime, 1);
88 $this->mockIsLocked('nice', false, $this->startTime, 1);
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);
94 $this->mockReleaseLock('foo', $this->pid, 1);
96 $this->mockIsLocked('foo', false, $this->startTime, 1);
97 $this->mockIsLocked('bar', true, $this->startTime, 1);
98 $this->mockIsLocked('nice', true, $this->startTime, 1);
100 $this->mockReleaseAll($this->pid, 1);
102 $this->mockIsLocked('bar', false, $this->startTime, 1);
103 $this->mockIsLocked('nice', false, $this->startTime, 1);
105 parent::testReleaseAfterUnlock();