mirror of
https://github.com/friendica/friendica
synced 2025-04-23 02:30:20 +00:00
Adding multihost - locking
Adding Unit-Tests for it
This commit is contained in:
parent
b07dfbb03f
commit
aac94d1d74
22 changed files with 741 additions and 154 deletions
80
tests/src/Core/Lock/LockTest.php
Normal file
80
tests/src/Core/Lock/LockTest.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Test\src\Core\Lock;
|
||||
|
||||
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() {
|
||||
$this->instance->acquireLock('foo', 1);
|
||||
$this->assertTrue($this->instance->isLocked('foo'));
|
||||
$this->assertFalse($this->instance->isLocked('bar'));
|
||||
}
|
||||
|
||||
public function testDoubleLock() {
|
||||
$this->instance->acquireLock('foo', 1);
|
||||
$this->assertTrue($this->instance->isLocked('foo'));
|
||||
// We already locked it
|
||||
$this->assertTrue($this->instance->acquireLock('foo', 1));
|
||||
}
|
||||
|
||||
public function testReleaseLock() {
|
||||
$this->instance->acquireLock('foo', 1);
|
||||
$this->assertTrue($this->instance->isLocked('foo'));
|
||||
$this->instance->releaseLock('foo');
|
||||
$this->assertFalse($this->instance->isLocked('foo'));
|
||||
}
|
||||
|
||||
public function testReleaseAll() {
|
||||
$this->instance->acquireLock('foo', 1);
|
||||
$this->instance->acquireLock('bar', 1);
|
||||
$this->instance->acquireLock('#/$%§', 1);
|
||||
|
||||
$this->instance->releaseAll();
|
||||
|
||||
$this->assertFalse($this->instance->isLocked('foo'));
|
||||
$this->assertFalse($this->instance->isLocked('bar'));
|
||||
$this->assertFalse($this->instance->isLocked('#/$%§'));
|
||||
}
|
||||
|
||||
public function testReleaseAfterUnlock() {
|
||||
$this->instance->acquireLock('foo', 1);
|
||||
$this->instance->acquireLock('bar', 1);
|
||||
$this->instance->acquireLock('#/$%§', 1);
|
||||
|
||||
$this->instance->releaseLock('foo');
|
||||
|
||||
$this->instance->releaseAll();
|
||||
|
||||
$this->assertFalse($this->instance->isLocked('bar'));
|
||||
$this->assertFalse($this->instance->isLocked('#/$%§'));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue