3 namespace Friendica\Test\src\Core\Lock;
7 use Friendica\BaseObject;
8 use Friendica\Core\Config\Configuration;
9 use Friendica\Core\Lock\SemaphoreLock;
11 class SemaphoreLockTest extends LockTest
13 public function setUp()
15 $dice = \Mockery::mock(Dice::class)->makePartial();
17 $app = \Mockery::mock(App::class);
18 $app->shouldReceive('getHostname')->andReturn('friendica.local');
19 $dice->shouldReceive('create')->with(App::class)->andReturn($app);
21 $configMock = \Mockery::mock(Configuration::class);
23 ->shouldReceive('get')
24 ->with('system', 'temppath', NULL, false)
26 $dice->shouldReceive('create')->with(Configuration::class)->andReturn($configMock);
28 // @todo Because "get_temppath()" is using static methods, we have to initialize the BaseObject
29 BaseObject::setDependencyInjection($dice);
34 protected function getInstance()
36 return new SemaphoreLock();
39 function testLockTTL()
41 // Semaphore doesn't work with TTL
46 * Test if semaphore locking works even for
48 public function testMissingFileNotOverriding()
50 $file = get_temppath() . '/test.sem';
52 $this->assertTrue(file_exists($file));
53 $this->assertFalse($this->instance->releaseLock('test', false));
54 $this->assertTrue(file_exists($file));
58 * Test overriding semaphore release with already set semaphore
59 * This test proves that semaphore locks cannot get released by other instances except themselves
61 * Check for Bug https://github.com/friendica/friendica/issues/7298#issuecomment-521996540
62 * @see https://github.com/friendica/friendica/issues/7298#issuecomment-521996540
64 public function testMissingFileOverriding()
66 $file = get_temppath() . '/test.sem';
68 $this->assertTrue(file_exists($file));
69 $this->assertFalse($this->instance->releaseLock('test', true));
70 $this->assertTrue(file_exists($file));