diff options
author | Robin Appelman <robin@icewind.nl> | 2019-12-04 19:08:26 +0300 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2019-12-04 19:08:26 +0300 |
commit | 0ec2c3892f6e08dee8aadaf192a9cc72754425ff (patch) | |
tree | a39148e79e6aed076918f549da0e18983f8ecedc /tests | |
parent | 4d45bd38d7ea9dcffa084e9f5e7fcb7d0cfbb6f7 (diff) |
add database ipc backend fallback
Diffstat (limited to 'tests')
-rw-r--r-- | tests/IPC/BackendTest.php | 26 | ||||
-rw-r--r-- | tests/IPC/DatabaseIPCBackendTest.php | 49 |
2 files changed, 62 insertions, 13 deletions
diff --git a/tests/IPC/BackendTest.php b/tests/IPC/BackendTest.php index fe27dd9..409babb 100644 --- a/tests/IPC/BackendTest.php +++ b/tests/IPC/BackendTest.php @@ -25,7 +25,7 @@ use OCA\DocumentServer\IPC\IIPCBackend; use Test\TestCase; abstract class BackendTest extends TestCase { - protected function setUp() { + protected function setUp(): void { parent::setUp(); $this->setupBackend(); @@ -43,23 +43,23 @@ abstract class BackendTest extends TestCase { $backend2 = $this->getBackend(); $backend1->pushMessage("ch1", "foo"); - $this->assertEquals("foo", $backend2->popMessage("ch1")); + $this->assertEquals("foo", $backend2->popMessage("ch1", 1)); } public function testPopEmpty() { $backend = $this->getBackend(); - $this->assertEquals(null, $backend->popMessage("ch1")); + $this->assertEquals(null, $backend->popMessage("ch1", 1)); } public function testPushPopAfterEmpty() { $backend1 = $this->getBackend(); $backend2 = $this->getBackend(); - $this->assertEquals(null, $backend2->popMessage("ch1")); + $this->assertEquals(null, $backend2->popMessage("ch1", 1)); $backend1->pushMessage("ch1", "foo"); - $this->assertEquals("foo", $backend2->popMessage("ch1")); + $this->assertEquals("foo", $backend2->popMessage("ch1", 1)); } public function testPushPopMultiple() { @@ -69,10 +69,10 @@ abstract class BackendTest extends TestCase { $backend1->pushMessage("ch1", "foo"); $backend1->pushMessage("ch1", "bar"); $backend1->pushMessage("ch1", "asd"); - $this->assertEquals("foo", $backend2->popMessage("ch1")); - $this->assertEquals("bar", $backend2->popMessage("ch1")); - $this->assertEquals("asd", $backend2->popMessage("ch1")); - $this->assertEquals(null, $backend2->popMessage("ch1")); + $this->assertEquals("foo", $backend2->popMessage("ch1", 1)); + $this->assertEquals("bar", $backend2->popMessage("ch1", 1)); + $this->assertEquals("asd", $backend2->popMessage("ch1", 1)); + $this->assertEquals(null, $backend2->popMessage("ch1", 1)); } public function testPushPopSeparateChannels() { @@ -81,9 +81,9 @@ abstract class BackendTest extends TestCase { $backend1->pushMessage("ch1", "foo"); $backend1->pushMessage("ch2", "bar"); - $this->assertEquals("foo", $backend2->popMessage("ch1")); - $this->assertEquals(null, $backend2->popMessage("ch1")); - $this->assertEquals("bar", $backend2->popMessage("ch2")); - $this->assertEquals(null, $backend2->popMessage("ch2")); + $this->assertEquals("foo", $backend2->popMessage("ch1", 1)); + $this->assertEquals(null, $backend2->popMessage("ch1", 1)); + $this->assertEquals("bar", $backend2->popMessage("ch2", 1)); + $this->assertEquals(null, $backend2->popMessage("ch2", 1)); } } diff --git a/tests/IPC/DatabaseIPCBackendTest.php b/tests/IPC/DatabaseIPCBackendTest.php new file mode 100644 index 0000000..1f7a15a --- /dev/null +++ b/tests/IPC/DatabaseIPCBackendTest.php @@ -0,0 +1,49 @@ +<?php declare(strict_types=1); +/** + * @copyright Copyright (c) 2019 Robin Appelman <robin@icewind.nl> + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +namespace OCA\DocumentServer\Tests\IPC; + + +use OCA\DocumentServer\IPC\IIPCBackend; +use OCA\DocumentServer\IPC\DatabaseIPCBackend; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\IDBConnection; + +/** + * @group DB + */ +class DatabaseIPCBackendTest extends BackendTest { + /** @var IDBConnection */ + private $connection; + /** @var ITimeFactory */ + private $timeFactory; + + protected function setupBackend() { + $this->connection = \OC::$server->getDatabaseConnection(); + $this->timeFactory = $this->createMock(ITimeFactory::class); + $this->timeFactory->method('getTime') + ->willReturn(100); + } + + protected function getBackend(): IIPCBackend { + return new DatabaseIPCBackend($this->connection, $this->timeFactory); + } +} |