Add async exec doc test

This commit is contained in:
Matej Bačo
2024-10-14 13:06:08 +00:00
parent 16a8fdce4e
commit 408dcbc263
4 changed files with 15 additions and 2 deletions
+1 -1
View File
@@ -369,7 +369,7 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo
;
$queueForFunctions
->setType('delayed_execution_write')
->setType(Func::TYPE_ASYNC_WRITE)
->setExecution($execution)
->setProject($project)
->trigger();
+2
View File
@@ -8,6 +8,8 @@ use Utopia\Queue\Connection;
class Func extends Event
{
public const TYPE_ASYNC_WRITE = 'async_write';
protected string $jwt = '';
protected string $type = '';
protected string $body = '';
+1 -1
View File
@@ -74,7 +74,7 @@ class Functions extends Action
$type = $payload['type'] ?? '';
// Short-term solution to offhand write operation from API contianer
if ($type === 'delayed_execution_write') {
if ($type === Func::TYPE_ASYNC_WRITE) {
$execution = new Document($payload['execution'] ?? []);
$execution = $dbForProject->createDocument('executions', $execution);
return;
@@ -1675,6 +1675,17 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals($cookie, $response['body']);
// Async execution document creation
$this->assertEventually(function () use ($functionId) {
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), []);
$this->assertEquals(200, $executions['headers']['status-code']);
$this->assertEquals(1, count($executions['body']['executions']));
});
// Await Aggregation
sleep(System::getEnv('_APP_USAGE_AGGREGATION_INTERVAL', 30));