From 878f6c86df4b0f6796824ca5a76f8b2066d95738 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Wed, 26 Jun 2024 11:01:43 +0100 Subject: [PATCH] chore: matej review p1 --- .../Platform/Tasks/ScheduleExecutions.php | 2 ++ .../Functions/FunctionsCustomClientTest.php | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php index b0f03a35ea..ea1339511d 100644 --- a/src/Appwrite/Platform/Tasks/ScheduleExecutions.php +++ b/src/Appwrite/Platform/Tasks/ScheduleExecutions.php @@ -42,6 +42,8 @@ class ScheduleExecutions extends ScheduleBase $queueForFunctions ->setType('schedule') + // Set functionId rather than function as we don't have access to $dbForProject + // TODO: Refactor to use function instead of functionId ->setFunctionId($schedule['resource']['functionId']) ->setExecution($schedule['resource']) ->setProject($schedule['project']) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index a187ee43ae..0c06b42d2a 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -59,7 +59,6 @@ class FunctionsCustomClientTest extends Scope 'execute' => [Role::user($this->getUser()['$id'])->toString()], 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', - 'logging' => true, 'events' => [ 'users.*.create', 'users.*.delete', @@ -256,7 +255,7 @@ class FunctionsCustomClientTest extends Scope \sleep(1); } - $this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body'])); + $this->assertEquals('ready', $deployment['body']['status']); $function = $this->client->call(Client::METHOD_PATCH, '/functions/' . $function['body']['$id'] . '/deployments/' . $deploymentId, [ 'content-type' => 'application/json', @@ -278,7 +277,7 @@ class FunctionsCustomClientTest extends Scope ]); $this->assertEquals(202, $execution['headers']['status-code']); - $this->assertEquals('scheduled', $execution['body']['status'], \json_encode($execution['body'])); + $this->assertEquals('scheduled', $execution['body']['status']); $executionId = $execution['body']['$id']; @@ -291,7 +290,21 @@ class FunctionsCustomClientTest extends Scope ]); $this->assertEquals(200, $execution['headers']['status-code']); - $this->assertEquals('completed', $execution['body']['status'], \json_encode($execution['body'])); + $this->assertEquals('completed', $execution['body']['status']); + + /* Test for FAILURE */ + + // Schedule synchronous execution + + $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $function['body']['$id'] . '/executions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'async' => false, + 'scheduledAt' => $futureTime, + ]); + + $this->assertEquals(400, $execution['headers']['status-code']); // Cleanup : Delete function $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $function['body']['$id'], [