From 1334cf116bd3d50fe75e27e551c474a152889a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 12 Aug 2024 07:26:20 +0000 Subject: [PATCH] Speed up new test --- .../Functions/FunctionsCustomServerTest.php | 84 ++++--------------- tests/resources/functions/php-4xx/index.php | 5 -- tests/resources/functions/php/index.php | 4 +- 3 files changed, 20 insertions(+), 73 deletions(-) delete mode 100644 tests/resources/functions/php-4xx/index.php diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 30f7c54df7..0b6bf985c1 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -802,6 +802,23 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('', $execution['body']['logs']); $this->assertLessThan(10, $execution['body']['duration']); + $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/executions', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'async' => false, + 'path' => '/?code=400' + ]); + $this->assertEquals(201, $execution['headers']['status-code']); + $this->assertEquals('completed', $execution['body']['status']); + $this->assertEquals(400, $execution['body']['responseStatusCode']); + + $execution = $this->client->call(Client::METHOD_DELETE, '/functions/' . $data['functionId'] . '/executions/' . $execution['body']['$id'], array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), []); + $this->assertEquals(204, $execution['headers']['status-code']); + return array_merge($data, ['executionId' => $executionId]); } @@ -1659,73 +1676,6 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } - public function text4xxExecution() - { - $timeout = 15; - $code = realpath(__DIR__ . '/../../../resources/functions') . "/php-4xx/code.tar.gz"; - $this->packageCode('php-4xx'); - - $function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'functionId' => ID::unique(), - 'name' => 'Test PHP 4XX executions', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'timeout' => $timeout, - ]); - - $functionId = $function['body']['$id'] ?? ''; - - $this->assertEquals(201, $function['headers']['status-code']); - - $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([ - 'content-type' => 'multipart/form-data', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'entrypoint' => 'index.php', - 'code' => new CURLFile($code, 'application/x-gzip', basename($code)), - 'activate' => true - ]); - - $deploymentId = $deployment['body']['$id'] ?? ''; - $this->assertEquals(202, $deployment['headers']['status-code']); - - $this->awaitDeploymentIsBuilt($function['body']['$id'], $deploymentId, checkForSuccess: false); - - $deployment = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId, array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $deployment['headers']['status-code']); - - // Wait a little for activation to finish - sleep(5); - - $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'async' => false - ]); - - $this->assertEquals(201, $execution['headers']['status-code']); - $this->assertEquals('completed', $execution['body']['status']); - $this->assertEquals(400, $execution['body']['responseStatusCode']); - $this->assertEquals('Invalid input.', $execution['body']['responseBody']); - - // Cleanup : Delete function - $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], []); - - $this->assertEquals(204, $response['headers']['status-code']); - } - public function testFunctionsDomain() { $timeout = 15; diff --git a/tests/resources/functions/php-4xx/index.php b/tests/resources/functions/php-4xx/index.php deleted file mode 100644 index 92f0bf28fe..0000000000 --- a/tests/resources/functions/php-4xx/index.php +++ /dev/null @@ -1,5 +0,0 @@ -res->text('Invalid input.', 400); -}; diff --git a/tests/resources/functions/php/index.php b/tests/resources/functions/php/index.php index d5328c40e1..e8e5eb67d5 100644 --- a/tests/resources/functions/php/index.php +++ b/tests/resources/functions/php/index.php @@ -1,6 +1,8 @@ req->query['code'] ?? '200'; + return $context->res->json([ 'APPWRITE_FUNCTION_ID' => \getenv('APPWRITE_FUNCTION_ID') ?: '', 'APPWRITE_FUNCTION_NAME' => \getenv('APPWRITE_FUNCTION_NAME') ?: '', @@ -11,5 +13,5 @@ return function ($context) { 'APPWRITE_REGION' => \getenv('APPWRITE_REGION') ?: '', 'UNICODE_TEST' => "êä", 'GLOBAL_VARIABLE' => \getenv('GLOBAL_VARIABLE') ?: '' - ]); + ], \intval($statusCode)); };