Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/jsxc.nextcloud.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLEDfan <tobia@ledfan.be>2016-01-20 13:08:41 +0300
committerLEDfan <tobia@ledfan.be>2016-01-20 13:08:41 +0300
commit51ee5602651cfe1ee7c5b5458ef9d1648b82b594 (patch)
tree141ca6bcb5d5a98c1e9323be4f1d999bc6808f1e /tests/integration
parent352b3f82ce5b098b671a6281bb0e95096573ec8b (diff)
Add unit tests for MemLock
Diffstat (limited to 'tests/integration')
-rw-r--r--tests/integration/DbLockTest.php12
-rw-r--r--tests/integration/MemLockTest.php71
2 files changed, 41 insertions, 42 deletions
diff --git a/tests/integration/DbLockTest.php b/tests/integration/DbLockTest.php
index 61ce3ca..e294f43 100644
--- a/tests/integration/DbLockTest.php
+++ b/tests/integration/DbLockTest.php
@@ -6,8 +6,11 @@ use Test\TestCase;
use OCA\OJSXC\AppInfo\Application;
use OCA\OJSXC\DbLock;
+$time = 0;
+
function time() {
- return DbLockTest::$time;
+ global $time;
+ return $time;
}
/**
@@ -30,8 +33,6 @@ class DbLockTest extends TestCase {
*/
private $con;
- public static $time;
-
public function setUp() {
parent::setUp();
$app = new Application();
@@ -45,7 +46,8 @@ class DbLockTest extends TestCase {
* and then setting a new lock.
*/
public function testLock() {
- self::$time = 4;
+ global $time;
+ $time = 4;
$this->dbLock = new DbLock(
'john',
$this->container->getServer()->getDb(),
@@ -61,7 +63,7 @@ class DbLockTest extends TestCase {
$this->assertTrue($this->dbLock->stillLocked());
- self::$time = 5;
+ $time = 5;
$this->dbLock2 = new DbLock(
'john',
$this->container->getServer()->getDb(),
diff --git a/tests/integration/MemLockTest.php b/tests/integration/MemLockTest.php
index 465c82b..2a97e1b 100644
--- a/tests/integration/MemLockTest.php
+++ b/tests/integration/MemLockTest.php
@@ -30,6 +30,11 @@ class MemLockTest extends TestCase {
*/
private $container;
+ /**
+ * @var \OCP\ICache
+ */
+ private $memCache;
+
public static $time;
public function setUp() {
@@ -43,52 +48,44 @@ class MemLockTest extends TestCase {
* and then setting a new lock.
*/
public function testLock() {
- self::$time = 4;
+ global $time;
+ $time = 4;
+ $cache = $this->container->getServer()->getMemCacheFactory();
+ if ($cache->isAvailable()) {
+ $this->memCache = $cache->create('ojsxc');
+ } else {
+ die('No memcache available'); // TODO
+ }
+
$this->memLock = new MemLock(
'john',
- $this->container->getServer()->getMemCacheFactory()
+ $this->memCache
);
$this->memLock->setLock();
+ $this->assertTrue($this->memLock->stillLocked());
-// $result = $this->fetchLocks();
-// $this->assertCount(1, $result);
-// $this->assertEquals($result[0]['userid'], 'john');
-// $this->assertEquals($result[0]['appid'], 'ojsxc');
-// $this->assertEquals($result[0]['configkey'], 'longpolling');
-// $this->assertEquals($result[0]['configvalue'], '4');
- $this->assertTrue($this->memLock->stillLocked());
-//
-//
-// self::$time = 5;
-// $this->dbLock2 = new DbLock(
-// 'john',
-// $this->container->getServer()->getDb(),
-// $this->container->getServer()->getConfig()
-// ); // simulate new lock/request
-// $this->dbLock2->setLock();
-//
-// $this->assertFalse($this->dbLock->stillLocked());
-// $this->assertTrue($this->dbLock2->stillLocked());
-// $result = $this->fetchLocks();
-// $this->assertCount(1, $result);
-// $this->assertEquals($result[0]['userid'], 'john');
-// $this->assertEquals($result[0]['appid'], 'ojsxc');
-// $this->assertEquals($result[0]['configkey'], 'longpolling');
-// $this->assertEquals($result[0]['configvalue'], '5');
-// $this->assertTrue($this->dbLock2->stillLocked());
+ $result = $this->fetchLock();
+ $this->assertEquals('4', $result);
+
+
+ global $time;
+ $time = 5;
+ $this->memLock2 = new MemLock(
+ 'john',
+ $this->memCache
+ ); // simulate new lock/request
+ $this->memLock2->setLock();
+
+ $this->assertFalse($this->memLock->stillLocked());
+ $this->assertTrue($this->memLock2->stillLocked());
+ $result = $this->fetchLock();
+ $this->assertEquals('5', $result);
}
- private function fetchLocks() {
-// $stmt = $this->con->executeQuery("SELECT * FROM `*PREFIX*preferences` WHERE `appid`='ojsxc' AND `configkey`='longpolling'");
-//
-// $reuslt = [];
-//
-// while($row = $stmt->fetch()){
-// $result[] = $row;
-// }
-// return $result;
+ private function fetchLock() {
+ return $this->memCache->get('-john-ojxsc-lock');
}
} \ No newline at end of file