2018-07-04 21:37:22 +00:00
|
|
|
<?php
|
|
|
|
|
2018-07-05 18:57:31 +00:00
|
|
|
namespace Friendica\Test\src\Core\Lock;
|
2018-07-04 21:37:22 +00:00
|
|
|
|
|
|
|
use Friendica\App;
|
|
|
|
use Friendica\Core\Config;
|
|
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
|
|
|
|
abstract class LockTest extends TestCase
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \Friendica\Core\Lock\ILockDriver
|
|
|
|
*/
|
|
|
|
protected $instance;
|
|
|
|
|
|
|
|
abstract protected function getInstance();
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
global $a;
|
|
|
|
parent::setUp();
|
|
|
|
$this->instance = $this->getInstance();
|
|
|
|
|
|
|
|
// Reusable App object
|
|
|
|
$this->app = new App(__DIR__.'/../');
|
|
|
|
$a = $this->app;
|
|
|
|
|
|
|
|
// Default config
|
|
|
|
Config::set('config', 'hostname', 'localhost');
|
|
|
|
Config::set('system', 'throttle_limit_day', 100);
|
|
|
|
Config::set('system', 'throttle_limit_week', 100);
|
|
|
|
Config::set('system', 'throttle_limit_month', 100);
|
|
|
|
Config::set('system', 'theme', 'system_theme');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testLock() {
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->instance->acquireLock('foo', 1);
|
2018-07-04 21:37:22 +00:00
|
|
|
$this->assertTrue($this->instance->isLocked('foo'));
|
|
|
|
$this->assertFalse($this->instance->isLocked('bar'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testDoubleLock() {
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->instance->acquireLock('foo', 1);
|
2018-07-04 21:37:22 +00:00
|
|
|
$this->assertTrue($this->instance->isLocked('foo'));
|
|
|
|
// We already locked it
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
2018-07-04 21:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReleaseLock() {
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->instance->acquireLock('foo', 1);
|
2018-07-04 21:37:22 +00:00
|
|
|
$this->assertTrue($this->instance->isLocked('foo'));
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->instance->releaseLock('foo');
|
2018-07-04 21:37:22 +00:00
|
|
|
$this->assertFalse($this->instance->isLocked('foo'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testReleaseAll() {
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->instance->acquireLock('foo', 1);
|
|
|
|
$this->instance->acquireLock('bar', 1);
|
|
|
|
$this->instance->acquireLock('nice', 1);
|
2018-07-04 21:37:22 +00:00
|
|
|
|
|
|
|
$this->instance->releaseAll();
|
|
|
|
|
|
|
|
$this->assertFalse($this->instance->isLocked('foo'));
|
|
|
|
$this->assertFalse($this->instance->isLocked('bar'));
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->assertFalse($this->instance->isLocked('nice'));
|
2018-07-04 21:37:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testReleaseAfterUnlock() {
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->instance->acquireLock('foo', 1);
|
|
|
|
$this->instance->acquireLock('bar', 1);
|
|
|
|
$this->instance->acquireLock('nice', 1);
|
2018-07-04 21:37:22 +00:00
|
|
|
|
2018-07-05 18:57:31 +00:00
|
|
|
$this->instance->releaseLock('foo');
|
2018-07-04 21:37:22 +00:00
|
|
|
|
|
|
|
$this->instance->releaseAll();
|
|
|
|
|
|
|
|
$this->assertFalse($this->instance->isLocked('bar'));
|
|
|
|
$this->assertFalse($this->instance->isLocked('#/$%§'));
|
|
|
|
}
|
|
|
|
}
|