From b4b3b91c0b14944550dba65b4568ecee016f7ad9 Mon Sep 17 00:00:00 2001 From: Christy Jacob Date: Sat, 19 Feb 2022 21:33:27 +0400 Subject: [PATCH] feat: improve functions tests --- app/workers/builds.php | 2 +- src/Executor/Executor.php | 2 +- .../Functions/FunctionsCustomServerTest.php | 105 ------------------ tests/resources/functions/deno/mod.ts | 30 ----- 4 files changed, 2 insertions(+), 137 deletions(-) delete mode 100644 tests/resources/functions/deno/mod.ts diff --git a/app/workers/builds.php b/app/workers/builds.php index e8a283fdbb..516825dd37 100644 --- a/app/workers/builds.php +++ b/app/workers/builds.php @@ -126,7 +126,7 @@ class BuildsV1 extends Worker commands: [ 'sh', '-c', 'tar -zxf /tmp/code.tar.gz -C /usr/code && \ - cd /usr/local/src && ./build.sh' + cd /usr/local/src/ && ./build.sh' ] ); diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index e68e67c83b..d8da13e902 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -65,7 +65,7 @@ class Executor 'commands' => $commands ]; - $response = $this->call(self::METHOD_POST, $route, $headers, $params, true, 30); + $response = $this->call(self::METHOD_POST, $route, $headers, $params, true, App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)); $status = $response['headers']['status-code']; if ($status >= 400) { diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 06765086cc..f9c7f2a3e8 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -949,113 +949,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(204, $response['headers']['status-code']); } - // public function testCreateCustomDenoExecution() - // { - // $name = 'deno-1.14'; - // $folder = 'deno'; - // $code = realpath(__DIR__ . '/../../../resources/functions'). "/$folder/code.tar.gz"; - // $this->packageCode($folder); - // $entrypoint = 'mod.ts'; - // $timeout = 2; - - // $function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'functionId' => 'unique()', - // 'name' => 'Test '.$name, - // 'runtime' => $name, - // 'vars' => [ - // 'CUSTOM_VARIABLE' => 'variable', - // ], - // 'events' => [], - // 'schedule' => '', - // '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' => $entrypoint, - // 'code' => new CURLFile($code, 'application/x-gzip', basename($code)), - // 'activate' => true, - // ]); - - // $deploymentId = $deployment['body']['$id'] ?? ''; - // $this->assertEquals(201, $deployment['headers']['status-code']); - - // // Allow build step to run - // sleep(10); - - // $execution = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/executions', array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders()), [ - // 'data' => 'foobar', - // ]); - - // $executionId = $execution['body']['$id'] ?? ''; - - // $this->assertEquals(201, $execution['headers']['status-code']); - - // $executionId = $execution['body']['$id'] ?? ''; - - // sleep(10); - - // $executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions/'.$executionId, array_merge([ - // 'content-type' => 'application/json', - // 'x-appwrite-project' => $this->getProject()['$id'], - // ], $this->getHeaders())); - - // $output = json_decode($executions['body']['stdout'], true); - - // $this->assertEquals(200, $executions['headers']['status-code']); - // $this->assertEquals('completed', $executions['body']['status']); - // $this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']); - // $this->assertEquals('Test '.$name, $output['APPWRITE_FUNCTION_NAME']); - // $this->assertEquals($deploymentId, $output['APPWRITE_FUNCTION_DEPLOYMENT']); - // $this->assertEquals('http', $output['APPWRITE_FUNCTION_TRIGGER']); - // $this->assertEquals('Node.js', $output['APPWRITE_FUNCTION_RUNTIME_NAME']); - // $this->assertEquals('17.0', $output['APPWRITE_FUNCTION_RUNTIME_VERSION']); - // $this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT']); - // $this->assertEquals('', $output['APPWRITE_FUNCTION_EVENT_DATA']); - // $this->assertEquals('foobar', $output['APPWRITE_FUNCTION_DATA']); - // $this->assertEquals('variable', $output['CUSTOM_VARIABLE']); - // $this->assertEquals('', $output['APPWRITE_FUNCTION_USER_ID']); - // $this->assertEmpty($output['APPWRITE_FUNCTION_JWT']); - // $this->assertEquals($this->getProject()['$id'], $output['APPWRITE_FUNCTION_PROJECT_ID']); - - // $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($executions['headers']['status-code'], 200); - // $this->assertEquals($executions['body']['sum'], 1); - // $this->assertIsArray($executions['body']['executions']); - // $this->assertCount(1, $executions['body']['executions']); - // $this->assertEquals($executions['body']['executions'][0]['$id'], $executionId); - // $this->assertEquals($executions['body']['executions'][0]['trigger'], 'http'); - // $this->assertStringContainsString('foobar', $executions['body']['executions'][0]['stdout']); - - // // 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 testGetRuntimes() { - $runtimes = $this->client->call(Client::METHOD_GET, '/functions/runtimes', array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $this->getProject()['$id'], diff --git a/tests/resources/functions/deno/mod.ts b/tests/resources/functions/deno/mod.ts deleted file mode 100644 index 041f83ac97..0000000000 --- a/tests/resources/functions/deno/mod.ts +++ /dev/null @@ -1,30 +0,0 @@ - -/* - 'req' variable has: - 'headers' - object with request headers - 'payload' - object with request body data - 'env' - object with environment variables - 'res' variable has: - 'send(text, status)' - function to return text response. Status code defaults to 200 - 'json(obj, status)' - function to return JSON response. Status code defaults to 200 - - If an error is thrown, a response with code 500 will be returned. -*/ - -export default async function(req: any, res: any) { - res.json({ - 'APPWRITE_FUNCTION_ID' : req.env.APPWRITE_FUNCTION_ID, - 'APPWRITE_FUNCTION_NAME' : req.env.APPWRITE_FUNCTION_NAME, - 'APPWRITE_FUNCTION_DEPLOYMENT' : req.env.APPWRITE_FUNCTION_DEPLOYMENT, - 'APPWRITE_FUNCTION_TRIGGER' : req.env.APPWRITE_FUNCTION_TRIGGER, - 'APPWRITE_FUNCTION_RUNTIME_NAME' : req.env.APPWRITE_FUNCTION_RUNTIME_NAME, - 'APPWRITE_FUNCTION_RUNTIME_VERSION' : req.env.APPWRITE_FUNCTION_RUNTIME_VERSION, - 'APPWRITE_FUNCTION_EVENT' : req.env.APPWRITE_FUNCTION_EVENT, - 'APPWRITE_FUNCTION_EVENT_DATA' : req.env.APPWRITE_FUNCTION_EVENT_DATA, - 'APPWRITE_FUNCTION_DATA' : req.env.APPWRITE_FUNCTION_DATA, - 'APPWRITE_FUNCTION_USER_ID' : req.env.APPWRITE_FUNCTION_USER_ID, - 'APPWRITE_FUNCTION_JWT' : req.env.APPWRITE_FUNCTION_JWT, - 'APPWRITE_FUNCTION_PROJECT_ID' : req.env.APPWRITE_FUNCTION_PROJECT_ID, - 'CUSTOM_VARIABLE' : req.env.CUSTOM_VARIABLE - }); -} \ No newline at end of file