From 6f38ef3a18da21fafb0402389c26ff96b6f969f4 Mon Sep 17 00:00:00 2001 From: loks0n <22452787+loks0n@users.noreply.github.com> Date: Thu, 13 Jun 2024 14:22:38 +0100 Subject: [PATCH] test: poll scheduled function --- .../Functions/FunctionsCustomClientTest.php | 23 ++++++++++++++----- 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index b72443ed6..0ca17e606 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -260,13 +260,24 @@ class FunctionsCustomClientTest extends Scope $executionId = $execution['body']['$id']; - \sleep(20); + while (true) { + + $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + 'x-appwrite-key' => $this->getProject()['apiKey'], + ]); + + if ( + $execution['headers']['status-code'] >= 400 + || \in_array($execution['body']['status'], ['completed', 'failed']) + ) { + break; + } + + \sleep(1); + } - $execution = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions/' . $executionId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]); $this->assertEquals('completed', $execution['body']['status'], \json_encode($execution['body'])); // Cleanup : Delete function