Added timeput tests
This commit is contained in:
parent
4f2a4f84a9
commit
26394ea4cf
|
@ -480,19 +480,21 @@ class FunctionsCustomServerTest extends Scope
|
||||||
* bash tests/resources/functions/package-*.sh
|
* bash tests/resources/functions/package-*.sh
|
||||||
*/
|
*/
|
||||||
$envs = [
|
$envs = [
|
||||||
[
|
|
||||||
'language' => 'PHP',
|
|
||||||
'version' => '8.0',
|
|
||||||
'name' => 'php-8.0',
|
|
||||||
'code' => $functions.'/php.tar.gz',
|
|
||||||
'command' => 'php index.php',
|
|
||||||
],
|
|
||||||
[
|
[
|
||||||
'language' => 'PHP',
|
'language' => 'PHP',
|
||||||
'version' => '7.4',
|
'version' => '7.4',
|
||||||
'name' => 'php-7.4',
|
'name' => 'php-7.4',
|
||||||
'code' => $functions.'/php.tar.gz',
|
'code' => $functions.'/php.tar.gz',
|
||||||
'command' => 'php index.php',
|
'command' => 'php index.php',
|
||||||
|
'timeout' => 15,
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'language' => 'PHP',
|
||||||
|
'version' => '8.0',
|
||||||
|
'name' => 'php-8.0',
|
||||||
|
'code' => $functions.'/php.tar.gz',
|
||||||
|
'command' => 'php index.php',
|
||||||
|
'timeout' => 15,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'language' => 'Python',
|
'language' => 'Python',
|
||||||
|
@ -500,6 +502,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
'name' => 'python-3.8',
|
'name' => 'python-3.8',
|
||||||
'code' => $functions.'/python.tar.gz',
|
'code' => $functions.'/python.tar.gz',
|
||||||
'command' => 'python main.py',
|
'command' => 'python main.py',
|
||||||
|
'timeout' => 15,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'language' => 'Node.js',
|
'language' => 'Node.js',
|
||||||
|
@ -507,6 +510,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
'name' => 'node-14',
|
'name' => 'node-14',
|
||||||
'code' => $functions.'/node.tar.gz',
|
'code' => $functions.'/node.tar.gz',
|
||||||
'command' => 'node index.js',
|
'command' => 'node index.js',
|
||||||
|
'timeout' => 15,
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'language' => 'Ruby',
|
'language' => 'Ruby',
|
||||||
|
@ -514,6 +518,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
'name' => 'ruby-2.7',
|
'name' => 'ruby-2.7',
|
||||||
'code' => $functions.'/ruby.tar.gz',
|
'code' => $functions.'/ruby.tar.gz',
|
||||||
'command' => 'ruby app.rb',
|
'command' => 'ruby app.rb',
|
||||||
|
'timeout' => 15,
|
||||||
],
|
],
|
||||||
// [
|
// [
|
||||||
// 'language' => 'Deno',
|
// 'language' => 'Deno',
|
||||||
|
@ -521,6 +526,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
// 'name' => 'deno-1.5',
|
// 'name' => 'deno-1.5',
|
||||||
// 'code' => $functions.'/deno.tar.gz',
|
// 'code' => $functions.'/deno.tar.gz',
|
||||||
// 'command' => 'deno run --allow-env index.ts',
|
// 'command' => 'deno run --allow-env index.ts',
|
||||||
|
// 'timeout' => 15,
|
||||||
// ],
|
// ],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -530,6 +536,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
$name = $env['name'] ?? '';
|
$name = $env['name'] ?? '';
|
||||||
$code = $env['code'] ?? '';
|
$code = $env['code'] ?? '';
|
||||||
$command = $env['command'] ?? '';
|
$command = $env['command'] ?? '';
|
||||||
|
$timeout = $env['timeout'] ?? 15;
|
||||||
|
|
||||||
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -545,7 +552,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
],
|
],
|
||||||
'events' => [],
|
'events' => [],
|
||||||
'schedule' => '',
|
'schedule' => '',
|
||||||
'timeout' => 15,
|
'timeout' => $timeout,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// var_dump('http://'.gethostbyname(trim(`hostname`)).'/v1');
|
// var_dump('http://'.gethostbyname(trim(`hostname`)).'/v1');
|
||||||
|
@ -584,7 +591,7 @@ class FunctionsCustomServerTest extends Scope
|
||||||
$executionId = $execution['body']['$id'] ?? '';
|
$executionId = $execution['body']['$id'] ?? '';
|
||||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||||
|
|
||||||
sleep(25);
|
sleep(15);
|
||||||
|
|
||||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions', array_merge([
|
$executions = $this->client->call(Client::METHOD_GET, '/functions/'.$functionId.'/executions', array_merge([
|
||||||
'content-type' => 'application/json',
|
'content-type' => 'application/json',
|
||||||
|
@ -619,4 +626,82 @@ class FunctionsCustomServerTest extends Scope
|
||||||
'functionId' => $functionId,
|
'functionId' => $functionId,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @depends testENVS
|
||||||
|
*/
|
||||||
|
public function testTimeout()
|
||||||
|
{
|
||||||
|
$language = 'PHP';
|
||||||
|
$version = '8.0';
|
||||||
|
$name = 'php-8.0';
|
||||||
|
$code = realpath(__DIR__ . '/../../../resources/functions').'/timeout.tar.gz';
|
||||||
|
$command = 'php index.php';
|
||||||
|
$timeout = 2;
|
||||||
|
|
||||||
|
$function = $this->client->call(Client::METHOD_POST, '/functions', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'name' => 'Test '.$name,
|
||||||
|
'env' => $name,
|
||||||
|
'vars' => [],
|
||||||
|
'events' => [],
|
||||||
|
'schedule' => '',
|
||||||
|
'timeout' => $timeout,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$functionId = $function['body']['$id'] ?? '';
|
||||||
|
|
||||||
|
$this->assertEquals(201, $function['headers']['status-code']);
|
||||||
|
|
||||||
|
$tag = $this->client->call(Client::METHOD_POST, '/functions/'.$functionId.'/tags', array_merge([
|
||||||
|
'content-type' => 'multipart/form-data',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'command' => $command,
|
||||||
|
'code' => new CURLFile($code, 'application/x-gzip', basename($code)),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tagId = $tag['body']['$id'] ?? '';
|
||||||
|
$this->assertEquals(201, $tag['headers']['status-code']);
|
||||||
|
|
||||||
|
$tag = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/tag', array_merge([
|
||||||
|
'content-type' => 'application/json',
|
||||||
|
'x-appwrite-project' => $this->getProject()['$id'],
|
||||||
|
], $this->getHeaders()), [
|
||||||
|
'tag' => $tagId,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$this->assertEquals(200, $tag['headers']['status-code']);
|
||||||
|
|
||||||
|
$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' => 1,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$executionId = $execution['body']['$id'] ?? '';
|
||||||
|
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||||
|
|
||||||
|
sleep(15);
|
||||||
|
|
||||||
|
$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->assertEquals($executions['body']['executions'][0]['status'], 'failed');
|
||||||
|
$this->assertEquals($executions['body']['executions'][0]['exitCode'], 1);
|
||||||
|
$this->assertGreaterThan(2, $executions['body']['executions'][0]['time']);
|
||||||
|
$this->assertLessThan(3, $executions['body']['executions'][0]['time']);
|
||||||
|
$this->assertEquals($executions['body']['executions'][0]['stdout'], '');
|
||||||
|
$this->assertEquals($executions['body']['executions'][0]['stderr'], '');
|
||||||
|
}
|
||||||
}
|
}
|
|
@ -3,8 +3,6 @@ echo 'PHP Packaging...'
|
||||||
|
|
||||||
cp -r $(pwd)/tests/resources/functions/php $(pwd)/tests/resources/functions/packages/php
|
cp -r $(pwd)/tests/resources/functions/php $(pwd)/tests/resources/functions/packages/php
|
||||||
|
|
||||||
ls -ll $(pwd)/tests/resources/functions/packages/php
|
|
||||||
|
|
||||||
docker run --rm -v $(pwd)/tests/resources/functions/packages/php:/app -w /app composer:2.0 composer install --ignore-platform-reqs
|
docker run --rm -v $(pwd)/tests/resources/functions/packages/php:/app -w /app composer:2.0 composer install --ignore-platform-reqs
|
||||||
|
|
||||||
docker run --rm -v $(pwd)/tests/resources/functions/packages/php:/app -w /app appwrite/env-php-8.0:1.0.0 tar -zcvf code.tar.gz .
|
docker run --rm -v $(pwd)/tests/resources/functions/packages/php:/app -w /app appwrite/env-php-8.0:1.0.0 tar -zcvf code.tar.gz .
|
||||||
|
|
10
tests/resources/functions/package-timeout.sh
Normal file
10
tests/resources/functions/package-timeout.sh
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
|
||||||
|
echo 'Timeout Packaging...'
|
||||||
|
|
||||||
|
cp -r $(pwd)/tests/resources/functions/timeout $(pwd)/tests/resources/functions/packages/timeout
|
||||||
|
|
||||||
|
docker run --rm -v $(pwd)/tests/resources/functions/packages/timeout:/app -w /app appwrite/env-php-8.0:1.0.0 tar -zcvf code.tar.gz .
|
||||||
|
|
||||||
|
mv $(pwd)/tests/resources/functions/packages/timeout/code.tar.gz $(pwd)/tests/resources/functions/timeout.tar.gz
|
||||||
|
|
||||||
|
rm -r $(pwd)/tests/resources/functions/packages/timeout
|
BIN
tests/resources/functions/timeout.tar.gz
Normal file
BIN
tests/resources/functions/timeout.tar.gz
Normal file
Binary file not shown.
3
tests/resources/functions/timeout/index.php
Normal file
3
tests/resources/functions/timeout/index.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
sleep(10);
|
Loading…
Reference in a new issue