tests fix
This commit is contained in:
parent
e2989afda8
commit
002fc19d60
12 changed files with 80 additions and 137 deletions
|
@ -1201,7 +1201,6 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/attributes/enum')
|
||||||
->inject('queueForDatabase')
|
->inject('queueForDatabase')
|
||||||
->inject('queueForEvents')
|
->inject('queueForEvents')
|
||||||
->action(function (string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents) {
|
->action(function (string $databaseId, string $collectionId, string $key, array $elements, ?bool $required, ?string $default, bool $array, Response $response, Database $dbForProject, EventDatabase $queueForDatabase, Event $queueForEvents) {
|
||||||
//var_dump($elements);
|
|
||||||
// use length of longest string as attribute size
|
// use length of longest string as attribute size
|
||||||
$size = 0;
|
$size = 0;
|
||||||
foreach ($elements as $element) {
|
foreach ($elements as $element) {
|
||||||
|
@ -2453,7 +2452,7 @@ App::post('/v1/databases/:databaseId/collections/:collectionId/indexes')
|
||||||
'orders' => $orders,
|
'orders' => $orders,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$validator = new IndexValidator($attributes, $dbForProject->getAdapter()->getMaxIndexLength());
|
$validator = new IndexValidator($dbForProject->getAdapter()->getMaxIndexLength());
|
||||||
if (!$validator->isValid($collection->setAttribute('indexes', $index, Document::SET_TYPE_APPEND))) {
|
if (!$validator->isValid($collection->setAttribute('indexes', $index, Document::SET_TYPE_APPEND))) {
|
||||||
throw new Exception(Exception::INDEX_INVALID, $validator->getDescription());
|
throw new Exception(Exception::INDEX_INVALID, $validator->getDescription());
|
||||||
}
|
}
|
||||||
|
|
|
@ -735,7 +735,7 @@ App::put('/v1/users/:userId/labels')
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('queueForEvents')
|
->inject('queueForEvents')
|
||||||
->action(function (string $userId, bool $emailVerification, Response $response, Database $dbForProject, Event $queueForEvents) {
|
->action(function (string $userId, array $labels, Response $response, Database $dbForProject, Event $queueForEvents) {
|
||||||
|
|
||||||
$user = $dbForProject->getDocument('users', $userId);
|
$user = $dbForProject->getDocument('users', $userId);
|
||||||
|
|
||||||
|
@ -1222,7 +1222,7 @@ App::get('/v1/users/usage')
|
||||||
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
->label('sdk.response.code', Response::STATUS_CODE_OK)
|
||||||
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
|
||||||
->label('sdk.response.model', Response::MODEL_USAGE_USERS)
|
->label('sdk.response.model', Response::MODEL_USAGE_USERS)
|
||||||
->param('range', '30d', new WhiteList(['24h', '7d', '30d', '90d'], true), 'Date range.', true)
|
->param('range', '30d', new WhiteList(['24h', '30d', '90d'], true), 'Date range.', true)
|
||||||
->inject('response')
|
->inject('response')
|
||||||
->inject('dbForProject')
|
->inject('dbForProject')
|
||||||
->inject('register')
|
->inject('register')
|
||||||
|
|
|
@ -224,7 +224,7 @@ if (isset($args[0])) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$platform->init(Service::TYPE_WORKER, [
|
$platform->init(Service::TYPE_WORKER, [
|
||||||
'workersNum' => swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6)),
|
'workersNum' => 1,
|
||||||
'connection' => $pools->get('queue')->pop()->getResource(),
|
'connection' => $pools->get('queue')->pop()->getResource(),
|
||||||
'workerName' => strtolower($workerName) ?? null,
|
'workerName' => strtolower($workerName) ?? null,
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -49,7 +49,7 @@
|
||||||
"utopia-php/cache": "0.8.*",
|
"utopia-php/cache": "0.8.*",
|
||||||
"utopia-php/cli": "0.15.*",
|
"utopia-php/cli": "0.15.*",
|
||||||
"utopia-php/config": "0.2.*",
|
"utopia-php/config": "0.2.*",
|
||||||
"utopia-php/database": "dev-fix-index-validation as 0.43.1",
|
"utopia-php/database": "0.43.*",
|
||||||
"utopia-php/domains": "0.3.*",
|
"utopia-php/domains": "0.3.*",
|
||||||
"utopia-php/dsn": "0.1.*",
|
"utopia-php/dsn": "0.1.*",
|
||||||
"utopia-php/framework": "0.31.0",
|
"utopia-php/framework": "0.31.0",
|
||||||
|
|
21
composer.lock
generated
21
composer.lock
generated
|
@ -4,7 +4,7 @@
|
||||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||||
"This file is @generated automatically"
|
"This file is @generated automatically"
|
||||||
],
|
],
|
||||||
"content-hash": "15224f89284384114e0eef2ae83f49ea",
|
"content-hash": "748f1a5e4fdf0a73ea26ddf0e7822f19",
|
||||||
"packages": [
|
"packages": [
|
||||||
{
|
{
|
||||||
"name": "adhocore/jwt",
|
"name": "adhocore/jwt",
|
||||||
|
@ -1433,16 +1433,16 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/database",
|
"name": "utopia-php/database",
|
||||||
"version": "dev-fix-index-validation",
|
"version": "0.43.5",
|
||||||
"source": {
|
"source": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/utopia-php/database.git",
|
"url": "https://github.com/utopia-php/database.git",
|
||||||
"reference": "67adc586318c35b34aaa9f1eed8f3751b6e8c324"
|
"reference": "5f7b05189cfbcc0506090498c580c5765375a00a"
|
||||||
},
|
},
|
||||||
"dist": {
|
"dist": {
|
||||||
"type": "zip",
|
"type": "zip",
|
||||||
"url": "https://api.github.com/repos/utopia-php/database/zipball/67adc586318c35b34aaa9f1eed8f3751b6e8c324",
|
"url": "https://api.github.com/repos/utopia-php/database/zipball/5f7b05189cfbcc0506090498c580c5765375a00a",
|
||||||
"reference": "67adc586318c35b34aaa9f1eed8f3751b6e8c324",
|
"reference": "5f7b05189cfbcc0506090498c580c5765375a00a",
|
||||||
"shasum": ""
|
"shasum": ""
|
||||||
},
|
},
|
||||||
"require": {
|
"require": {
|
||||||
|
@ -1483,9 +1483,9 @@
|
||||||
],
|
],
|
||||||
"support": {
|
"support": {
|
||||||
"issues": "https://github.com/utopia-php/database/issues",
|
"issues": "https://github.com/utopia-php/database/issues",
|
||||||
"source": "https://github.com/utopia-php/database/tree/fix-index-validation"
|
"source": "https://github.com/utopia-php/database/tree/0.43.5"
|
||||||
},
|
},
|
||||||
"time": "2023-10-09T02:11:28+00:00"
|
"time": "2023-10-06T06:49:47+00:00"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "utopia-php/domains",
|
"name": "utopia-php/domains",
|
||||||
|
@ -5275,12 +5275,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"aliases": [
|
"aliases": [
|
||||||
{
|
|
||||||
"package": "utopia-php/database",
|
|
||||||
"version": "dev-fix-index-validation",
|
|
||||||
"alias": "0.43.1",
|
|
||||||
"alias_normalized": "0.43.1.0"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"package": "utopia-php/platform",
|
"package": "utopia-php/platform",
|
||||||
"version": "dev-integrate-workers",
|
"version": "dev-integrate-workers",
|
||||||
|
@ -5296,7 +5290,6 @@
|
||||||
],
|
],
|
||||||
"minimum-stability": "stable",
|
"minimum-stability": "stable",
|
||||||
"stability-flags": {
|
"stability-flags": {
|
||||||
"utopia-php/database": 20,
|
|
||||||
"utopia-php/platform": 20,
|
"utopia-php/platform": 20,
|
||||||
"utopia-php/queue": 20
|
"utopia-php/queue": 20
|
||||||
},
|
},
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
convertNoticesToExceptions="true"
|
convertNoticesToExceptions="true"
|
||||||
convertWarningsToExceptions="true"
|
convertWarningsToExceptions="true"
|
||||||
processIsolation="false"
|
processIsolation="false"
|
||||||
stopOnFailure="true"
|
stopOnFailure="false"
|
||||||
>
|
>
|
||||||
<extensions>
|
<extensions>
|
||||||
<extension class="Appwrite\Tests\TestHook" />
|
<extension class="Appwrite\Tests\TestHook" />
|
||||||
|
|
|
@ -1057,7 +1057,6 @@ trait DatabasesBase
|
||||||
$this->assertEquals($releaseYearIndex['body']['key'], $movies['body']['indexes'][1]['key']);
|
$this->assertEquals($releaseYearIndex['body']['key'], $movies['body']['indexes'][1]['key']);
|
||||||
$this->assertEquals($releaseWithDate['body']['key'], $movies['body']['indexes'][2]['key']);
|
$this->assertEquals($releaseWithDate['body']['key'], $movies['body']['indexes'][2]['key']);
|
||||||
$this->assertEquals('available', $movies['body']['indexes'][0]['status']);
|
$this->assertEquals('available', $movies['body']['indexes'][0]['status']);
|
||||||
var_dump($movies['body']['indexes']);
|
|
||||||
$this->assertEquals('available', $movies['body']['indexes'][1]['status']);
|
$this->assertEquals('available', $movies['body']['indexes'][1]['status']);
|
||||||
$this->assertEquals('available', $movies['body']['indexes'][2]['status']);
|
$this->assertEquals('available', $movies['body']['indexes'][2]['status']);
|
||||||
|
|
||||||
|
|
|
@ -296,7 +296,7 @@ class DatabasesConsoleClientTest extends Scope
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'limit' => 1
|
'queries' => ['offset(1)', 'limit(1)'],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(200, $logs['headers']['status-code']);
|
$this->assertEquals(200, $logs['headers']['status-code']);
|
||||||
|
@ -308,7 +308,7 @@ class DatabasesConsoleClientTest extends Scope
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'offset' => 1
|
'queries' => ['offset(1)']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(200, $logs['headers']['status-code']);
|
$this->assertEquals(200, $logs['headers']['status-code']);
|
||||||
|
@ -319,8 +319,7 @@ class DatabasesConsoleClientTest extends Scope
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
'x-appwrite-project' => $this->getProject()['$id'],
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'offset' => 1,
|
'queries' => ['offset(1)', 'limit(1)'],
|
||||||
'limit' => 1
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals(200, $logs['headers']['status-code']);
|
$this->assertEquals(200, $logs['headers']['status-code']);
|
||||||
|
|
|
@ -234,7 +234,7 @@ trait TeamsBaseServer
|
||||||
/**
|
/**
|
||||||
* @depends testUpdateMembershipRoles
|
* @depends testUpdateMembershipRoles
|
||||||
*/
|
*/
|
||||||
public function testDeleteUserUpdatesTeamMembershipCount($data)
|
public function testDeleteUserUpdatesTeamMembershipCount($data): void
|
||||||
{
|
{
|
||||||
$teamUid = $data['teamUid'] ?? '';
|
$teamUid = $data['teamUid'] ?? '';
|
||||||
$userUid = $data['userUid'] ?? '';
|
$userUid = $data['userUid'] ?? '';
|
||||||
|
|
|
@ -23,17 +23,6 @@ class UsersConsoleClientTest extends Scope
|
||||||
'x-appwrite-project' => $this->getProject()['$id']
|
'x-appwrite-project' => $this->getProject()['$id']
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'range' => '32h',
|
'range' => '32h',
|
||||||
'provider' => 'email'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals($response['headers']['status-code'], 400);
|
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/users/usage', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id']
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'range' => '24h',
|
|
||||||
'provider' => 'some-random-provider'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals($response['headers']['status-code'], 400);
|
$this->assertEquals($response['headers']['status-code'], 400);
|
||||||
|
@ -46,38 +35,12 @@ class UsersConsoleClientTest extends Scope
|
||||||
'x-appwrite-project' => $this->getProject()['$id']
|
'x-appwrite-project' => $this->getProject()['$id']
|
||||||
], $this->getHeaders()), [
|
], $this->getHeaders()), [
|
||||||
'range' => '24h',
|
'range' => '24h',
|
||||||
'provider' => 'email'
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->assertEquals($response['headers']['status-code'], 200);
|
$this->assertEquals($response['headers']['status-code'], 200);
|
||||||
$this->assertEquals(count($response['body']), 9);
|
$this->assertEquals(count($response['body']), 3);
|
||||||
$this->assertEquals($response['body']['range'], '24h');
|
$this->assertEquals($response['body']['range'], '24h');
|
||||||
$this->assertIsArray($response['body']['usersCount']);
|
$this->assertIsArray($response['body']['usersTotal']);
|
||||||
$this->assertIsArray($response['body']['usersCreate']);
|
$this->assertIsArray($response['body']['sessionsTotal']);
|
||||||
$this->assertIsArray($response['body']['usersRead']);
|
|
||||||
$this->assertIsArray($response['body']['usersUpdate']);
|
|
||||||
$this->assertIsArray($response['body']['usersDelete']);
|
|
||||||
$this->assertIsArray($response['body']['sessionsCreate']);
|
|
||||||
$this->assertIsArray($response['body']['sessionsProviderCreate']);
|
|
||||||
$this->assertIsArray($response['body']['sessionsDelete']);
|
|
||||||
|
|
||||||
$response = $this->client->call(Client::METHOD_GET, '/users/usage', array_merge([
|
|
||||||
'content-type' => 'application/json',
|
|
||||||
'x-appwrite-project' => $this->getProject()['$id']
|
|
||||||
], $this->getHeaders()), [
|
|
||||||
'range' => '24h'
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->assertEquals($response['headers']['status-code'], 200);
|
|
||||||
$this->assertEquals(count($response['body']), 9);
|
|
||||||
$this->assertEquals($response['body']['range'], '24h');
|
|
||||||
$this->assertIsArray($response['body']['usersCount']);
|
|
||||||
$this->assertIsArray($response['body']['usersCreate']);
|
|
||||||
$this->assertIsArray($response['body']['usersRead']);
|
|
||||||
$this->assertIsArray($response['body']['usersUpdate']);
|
|
||||||
$this->assertIsArray($response['body']['usersDelete']);
|
|
||||||
$this->assertIsArray($response['body']['sessionsCreate']);
|
|
||||||
$this->assertIsArray($response['body']['sessionsProviderCreate']);
|
|
||||||
$this->assertIsArray($response['body']['sessionsDelete']);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,67 +3,74 @@
|
||||||
namespace Tests\Unit\Event;
|
namespace Tests\Unit\Event;
|
||||||
|
|
||||||
use Appwrite\Event\Event;
|
use Appwrite\Event\Event;
|
||||||
|
use Appwrite\URL\URL;
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
use Utopia\DSN\DSN;
|
||||||
|
use Utopia\Queue;
|
||||||
|
use Utopia\Queue\Client;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../../app/init.php';
|
||||||
|
|
||||||
class EventTest extends TestCase
|
class EventTest extends TestCase
|
||||||
{
|
{
|
||||||
|
|
||||||
protected ?Event $object = null;
|
protected ?Event $object = null;
|
||||||
protected string $queue = '';
|
protected string $queue = '';
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$redisHost = App::getEnv('_APP_REDIS_HOST', '');
|
$fallbackForRedis = URL::unparse([
|
||||||
$redisPort = App::getEnv('_APP_REDIS_PORT', '');
|
'scheme' => 'redis',
|
||||||
\Resque::setBackend($redisHost . ':' . $redisPort);
|
'host' => App::getEnv('_APP_REDIS_HOST', 'redis'),
|
||||||
|
'port' => App::getEnv('_APP_REDIS_PORT', '6379'),
|
||||||
|
'user' => App::getEnv('_APP_REDIS_USER', ''),
|
||||||
|
'pass' => App::getEnv('_APP_REDIS_PASS', ''),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dsn = App::getEnv('_APP_CONNECTIONS_QUEUE', $fallbackForRedis);
|
||||||
|
$dsn = explode('=', $dsn);
|
||||||
|
$dsn = $dsn[0] ?? '';
|
||||||
|
$dsn = new DSN($dsn);
|
||||||
|
$connection = new Queue\Connection\Redis($dsn->getHost(), $dsn->getPort());
|
||||||
$this->queue = 'v1-tests' . uniqid();
|
$this->queue = 'v1-tests' . uniqid();
|
||||||
$this->object = new Event($this->queue, 'TestsV1');
|
$this->object = new Event($connection);
|
||||||
|
$this->object->setClass('TestsV1');
|
||||||
|
$this->object->setQueue($this->queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testQueue(): void
|
public function testQueue(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals($this->queue, $this->object->getQueue());
|
$this->assertEquals($this->queue, $this->object->getQueue());
|
||||||
|
|
||||||
$this->object->setQueue('demo');
|
$this->object->setQueue('demo');
|
||||||
|
|
||||||
$this->assertEquals('demo', $this->object->getQueue());
|
$this->assertEquals('demo', $this->object->getQueue());
|
||||||
|
|
||||||
$this->object->setQueue($this->queue);
|
$this->object->setQueue($this->queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testClass(): void
|
public function testClass(): void
|
||||||
{
|
{
|
||||||
$this->assertEquals('TestsV1', $this->object->getClass());
|
$this->assertEquals('TestsV1', $this->object->getClass());
|
||||||
|
|
||||||
$this->object->setClass('TestsV2');
|
$this->object->setClass('TestsV2');
|
||||||
|
|
||||||
$this->assertEquals('TestsV2', $this->object->getClass());
|
$this->assertEquals('TestsV2', $this->object->getClass());
|
||||||
|
|
||||||
$this->object->setClass('TestsV1');
|
$this->object->setClass('TestsV1');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testParams(): void
|
public function testParams(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->object
|
$this->object
|
||||||
->setParam('eventKey1', 'eventValue1')
|
->setParam('eventKey1', 'eventValue1')
|
||||||
->setParam('eventKey2', 'eventValue2');
|
->setParam('eventKey2', 'eventValue2');
|
||||||
|
|
||||||
$this->object->trigger();
|
$this->object->trigger();
|
||||||
|
|
||||||
$this->assertEquals('eventValue1', $this->object->getParam('eventKey1'));
|
$this->assertEquals('eventValue1', $this->object->getParam('eventKey1'));
|
||||||
$this->assertEquals('eventValue2', $this->object->getParam('eventKey2'));
|
$this->assertEquals('eventValue2', $this->object->getParam('eventKey2'));
|
||||||
$this->assertEquals(null, $this->object->getParam('eventKey3'));
|
$this->assertEquals(null, $this->object->getParam('eventKey3'));
|
||||||
$this->assertEquals(\Resque::size($this->queue), 1);
|
global $register;
|
||||||
}
|
$pools = $register->get('pools');
|
||||||
|
$client = new Client($this->object->getQueue(), $pools->get('queue')->pop()->getResource());
|
||||||
public function testPause(): void
|
$this->assertEquals($client->getQueueSize(), 1);
|
||||||
{
|
|
||||||
$this->object->setPaused(true);
|
|
||||||
$this->assertTrue($this->object->isPaused());
|
|
||||||
$this->object->setPaused(false);
|
|
||||||
$this->assertNotTrue($this->object->isPaused());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReset(): void
|
public function testReset(): void
|
||||||
|
|
|
@ -2,70 +2,53 @@
|
||||||
|
|
||||||
namespace Tests\Unit\Usage;
|
namespace Tests\Unit\Usage;
|
||||||
|
|
||||||
use Appwrite\Usage\Stats;
|
use Appwrite\URL\URL as AppwriteURL;
|
||||||
use PHPUnit\Framework\TestCase;
|
use PHPUnit\Framework\TestCase;
|
||||||
use Utopia\App;
|
use Utopia\App;
|
||||||
|
use Utopia\DSN\DSN;
|
||||||
|
use Utopia\Queue;
|
||||||
|
use Utopia\Queue\Client;
|
||||||
|
use Utopia\Queue\Connection;
|
||||||
|
|
||||||
class StatsTest extends TestCase
|
class StatsTest extends TestCase
|
||||||
{
|
{
|
||||||
/**
|
protected ?Connection $connection = null;
|
||||||
* @var Stats
|
protected ?Client $client = null;
|
||||||
*/
|
|
||||||
protected $object = null;
|
protected const QUEUE_NAME = 'usage-test-q';
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
$host = App::getEnv('_APP_STATSD_HOST', 'telegraf');
|
$env = App::getEnv('_APP_CONNECTIONS_QUEUE', AppwriteURL::unparse([
|
||||||
$port = App::getEnv('_APP_STATSD_PORT', 8125);
|
'scheme' => 'redis',
|
||||||
|
'host' => App::getEnv('_APP_REDIS_HOST', 'redis'),
|
||||||
|
'port' => App::getEnv('_APP_REDIS_PORT', '6379'),
|
||||||
|
'user' => App::getEnv('_APP_REDIS_USER', ''),
|
||||||
|
'pass' => App::getEnv('_APP_REDIS_PASS', ''),
|
||||||
|
]));
|
||||||
|
|
||||||
$connection = new \Domnikl\Statsd\Connection\UdpSocket($host, $port);
|
$dsn = explode('=', $env);
|
||||||
$statsd = new \Domnikl\Statsd\Client($connection);
|
$dsn = count($dsn) > 1 ? $dsn[1] : $dsn[0];
|
||||||
|
$dsn = new DSN($dsn);
|
||||||
$this->object = new Stats($statsd);
|
$this->connection = new Queue\Connection\Redis($dsn->getHost(), $dsn->getPort());
|
||||||
|
$this->client = new Client(self::QUEUE_NAME, $this->connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function tearDown(): void
|
public function tearDown(): void
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testNamespace(): void
|
public function testSamePayload(): void
|
||||||
{
|
{
|
||||||
$this->object->setNamespace('appwritetest.usage');
|
$inToQueue = [
|
||||||
$this->assertEquals('appwritetest.usage', $this->object->getNamespace());
|
'key_1' => 'value_1',
|
||||||
}
|
'key_2' => 'value_2',
|
||||||
|
];
|
||||||
|
|
||||||
public function testParams(): void
|
$result = $this->client->enqueue($inToQueue);
|
||||||
{
|
$this->assertTrue($result);
|
||||||
$this->object
|
$outFromQueue = $this->connection->leftPopArray('utopia-queue.queue.' . self::QUEUE_NAME, 0)['payload'];
|
||||||
->setParam('projectId', 'appwrite_test')
|
$this->assertNotEmpty($outFromQueue);
|
||||||
->setParam('projectInternalId', 1)
|
$this->assertSame($inToQueue, $outFromQueue);
|
||||||
->setParam('networkRequestSize', 100)
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->assertEquals('appwrite_test', $this->object->getParam('projectId'));
|
|
||||||
$this->assertEquals(1, $this->object->getParam('projectInternalId'));
|
|
||||||
$this->assertEquals(100, $this->object->getParam('networkRequestSize'));
|
|
||||||
|
|
||||||
$this->object->submit();
|
|
||||||
|
|
||||||
$this->assertEquals(null, $this->object->getParam('projectId'));
|
|
||||||
$this->assertEquals(null, $this->object->getParam('networkRequestSize'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testReset(): void
|
|
||||||
{
|
|
||||||
$this->object
|
|
||||||
->setParam('projectId', 'appwrite_test')
|
|
||||||
->setParam('networkRequestSize', 100)
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->assertEquals('appwrite_test', $this->object->getParam('projectId'));
|
|
||||||
$this->assertEquals(100, $this->object->getParam('networkRequestSize'));
|
|
||||||
|
|
||||||
$this->object->reset();
|
|
||||||
|
|
||||||
$this->assertEquals(null, $this->object->getParam('projectId'));
|
|
||||||
$this->assertEquals(null, $this->object->getParam('networkRequestSize'));
|
|
||||||
$this->assertEquals('appwrite.usage', $this->object->getNamespace());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue