fix: Use memcached to lock daily processes on Distributed Pollers (#7735)

* fix: use memcached to lock daily processes on Distributed Pollers

* All the locks!
This commit is contained in:
Tony Murray
2017-11-24 03:37:52 -06:00
committed by Neil Lathwood
parent 9c0a74debb
commit 2e73b75297
13 changed files with 603 additions and 230 deletions

View File

@@ -25,7 +25,8 @@
namespace LibreNMS\Tests;
use LibreNMS\FileLock;
use LibreNMS\Exceptions\LockException;
use LibreNMS\Util\FileLock;
use PHPUnit\Framework\TestCase;
class LockTest extends TestCase
@@ -33,40 +34,35 @@ class LockTest extends TestCase
public function testFileLock()
{
$lock = FileLock::lock('tests');
$this->assertNotFalse($lock, 'Failed to acquire initial lock!');
$lock->release();
$new_lock = FileLock::lock('tests');
$this->assertNotFalse($new_lock, 'Failed to release the lock with release()');
unset($new_lock);
$this->assertNotFalse(FileLock::lock('tests'), 'Failed to remove lock when the lock object was destroyed');
FileLock::lock('tests');
}
public function testFileLockFail()
{
$lock = FileLock::lock('tests');
$this->assertNotFalse($lock, 'Failed to acquire initial lock!');
$this->setExpectedException('LibreNMS\Exceptions\LockException');
$failed_lock = FileLock::lock('tests');
$this->assertFalse($failed_lock, 'Additional lock attempt did not fail');
}
public function testFileLockWait()
{
$lock = FileLock::lock('tests');
$this->assertNotFalse($lock, 'Failed to acquire initial lock!');
$start = microtime(true);
$this->setExpectedException('LibreNMS\Exceptions\LockException');
$wait_lock = FileLock::lock('tests', 1);
$this->assertGreaterThan(1, microtime(true) - $start, 'Lock did not wait.');
$this->assertFalse($wait_lock, 'Waiting lock attempt did not fail');
$lock->release();
$start = microtime(true);
$wait_lock = FileLock::lock('tests', 5);
$this->assertLessThan(1, microtime(true) - $start, 'Lock waited when it should not have');
$this->assertNotFalse($wait_lock, 'Second wait lock did not succeed');
}
}