mirror of
https://github.com/appwrite/appwrite
synced 2026-05-23 08:58:35 +00:00
refactor and new endpoint test
This commit is contained in:
parent
9c6a6c265a
commit
28aa4e8a8d
4 changed files with 32 additions and 10 deletions
|
|
@ -10,17 +10,11 @@ abstract class Base extends Action
|
|||
{
|
||||
use HTTP;
|
||||
|
||||
protected function assertQueueThreshold(int $size, int $threshold): void
|
||||
protected function assertQueueThreshold(int $size, int $threshold, bool $failed = false): void
|
||||
{
|
||||
if ($size >= $threshold) {
|
||||
throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue size threshold hit. Current size is {$size} and threshold is {$threshold}.");
|
||||
}
|
||||
}
|
||||
|
||||
protected function assertFailedQueueThreshold(int $failed, int $threshold): void
|
||||
{
|
||||
if ($failed >= $threshold) {
|
||||
throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue failed jobs threshold hit. Current size is {$failed} and threshold is {$threshold}.");
|
||||
$context = $failed ? 'failed jobs' : 'jobs';
|
||||
throw new Exception(Exception::HEALTH_QUEUE_SIZE_EXCEEDED, "Queue {$context} threshold hit. Current value is {$size} and threshold is {$threshold}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class Get extends Base
|
|||
};
|
||||
$failed = $queue->getSize(failed: true);
|
||||
|
||||
$this->assertFailedQueueThreshold($failed, $threshold);
|
||||
$this->assertQueueThreshold($failed, $threshold, true);
|
||||
|
||||
$response->dynamic(new Document(['size' => $failed]), Response::MODEL_HEALTH_QUEUE);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use Appwrite\Platform\Modules\Health\Http\Health\Certificate\Get as GetCertifica
|
|||
use Appwrite\Platform\Modules\Health\Http\Health\DB\Get as GetDB;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Get as GetHealth;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\PubSub\Get as GetPubSub;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Audits\Get as GetQueueAudits;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Builds\Get as GetQueueBuilds;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Certificates\Get as GetQueueCertificates;
|
||||
use Appwrite\Platform\Modules\Health\Http\Health\Queue\Databases\Get as GetQueueDatabases;
|
||||
|
|
@ -45,6 +46,7 @@ class Http extends Service
|
|||
$this->addAction(GetStorage::getName(), new GetStorage());
|
||||
$this->addAction(GetAntivirus::getName(), new GetAntivirus());
|
||||
|
||||
$this->addAction(GetQueueAudits::getName(), new GetQueueAudits());
|
||||
$this->addAction(GetQueueWebhooks::getName(), new GetQueueWebhooks());
|
||||
$this->addAction(GetQueueLogs::getName(), new GetQueueLogs());
|
||||
$this->addAction(GetQueueCertificates::getName(), new GetQueueCertificates());
|
||||
|
|
|
|||
|
|
@ -370,6 +370,32 @@ class HealthCustomServerTest extends Scope
|
|||
return [];
|
||||
}
|
||||
|
||||
public function testAuditsSuccess(): array
|
||||
{
|
||||
/**
|
||||
* Test for SUCCESS
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health/queue/audits', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), []);
|
||||
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertIsInt($response['body']['size']);
|
||||
$this->assertLessThan(100, $response['body']['size']);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
*/
|
||||
$response = $this->client->call(Client::METHOD_GET, '/health/queue/audits?threshold=0', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()), []);
|
||||
$this->assertEquals(503, $response['headers']['status-code']);
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
public function testStorageLocalSuccess(): array
|
||||
{
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in a new issue