From 2cd451408607651a2c5a9105a875fd95def3d623 Mon Sep 17 00:00:00 2001 From: shimon Date: Wed, 11 Oct 2023 16:03:15 +0300 Subject: [PATCH] sync with main --- app/worker.php | 2 +- composer.json | 4 +- .../Utopia/Response/Model/Migration.php | 1 - src/Executor/Executor.php | 13 +- tests/e2e/Services/Avatars/AvatarsBase.php | 2 +- .../Functions/FunctionsCustomServerTest.php | 125 +------------- tests/e2e/Services/GraphQL/AvatarsTest.php | 2 +- .../Health/HealthCustomServerTest.php | 157 +++++------------- tests/e2e/Services/Users/UsersBase.php | 12 -- tests/resources/docker/docker-compose.yml | 2 - tests/resources/functions/php-event/index.php | 8 - 11 files changed, 56 insertions(+), 272 deletions(-) delete mode 100644 tests/resources/functions/php-event/index.php diff --git a/app/worker.php b/app/worker.php index 572d876d6f..7f8f138af7 100644 --- a/app/worker.php +++ b/app/worker.php @@ -224,7 +224,7 @@ if (isset($args[0])) { try { $platform->init(Service::TYPE_WORKER, [ - 'workersNum' => 1, + 'workersNum' => strtolower($workerName) === 'databases'? 1 :swoole_cpu_num() * intval(App::getEnv('_APP_WORKER_PER_CORE', 6)), 'connection' => $pools->get('queue')->pop()->getResource(), 'workerName' => strtolower($workerName) ?? null, ]); diff --git a/composer.json b/composer.json index f7e4e56e04..b5d2392406 100644 --- a/composer.json +++ b/composer.json @@ -56,7 +56,7 @@ "utopia-php/image": "0.5.*", "utopia-php/locale": "0.4.*", "utopia-php/logger": "0.3.*", - "utopia-php/messaging": "0.2.*", + "utopia-php/messaging": "0.1.*", "utopia-php/migration": "0.3.*", "utopia-php/orchestration": "0.9.*", "utopia-php/platform": "dev-integrate-workers as 0.3.3", @@ -64,7 +64,7 @@ "utopia-php/preloader": "0.2.*", "utopia-php/queue": "dev-feat-get-worker-start as 0.5.3", "utopia-php/registry": "0.5.*", - "utopia-php/storage": "0.17.*", + "utopia-php/storage": "0.14.*", "utopia-php/swoole": "0.5.*", "utopia-php/vcs": "0.5.*", "utopia-php/websocket": "0.1.*", diff --git a/src/Appwrite/Utopia/Response/Model/Migration.php b/src/Appwrite/Utopia/Response/Model/Migration.php index 5a54eef3ad..78e8658032 100644 --- a/src/Appwrite/Utopia/Response/Model/Migration.php +++ b/src/Appwrite/Utopia/Response/Model/Migration.php @@ -68,7 +68,6 @@ class Migration extends Model ->addRule('errors', [ 'type' => self::TYPE_STRING, 'description' => 'All errors that occurred during the migration process.', - 'array' => true, 'default' => [], 'example' => [], ]) diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index c7388069a1..36f6ad0dc5 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -70,7 +70,7 @@ class Executor array $variables = [], string $command = null, ) { - $runtimeId = "$projectId-$deploymentId-build"; + $runtimeId = "$projectId-$deploymentId"; $route = "/runtimes"; $params = [ 'runtimeId' => $runtimeId, @@ -113,7 +113,7 @@ class Executor ) { $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); - $runtimeId = "$projectId-$deploymentId-build"; + $runtimeId = "$projectId-$deploymentId"; $route = "/runtimes/{$runtimeId}/logs"; $params = [ 'timeout' => $timeout @@ -177,7 +177,6 @@ class Executor string $method, array $headers, string $runtimeEntrypoint = null, - int $requestTimeout = null ) { if (empty($headers['host'])) { $headers['host'] = App::getEnv('_APP_DOMAIN', ''); @@ -203,13 +202,9 @@ class Executor 'runtimeEntrypoint' => $runtimeEntrypoint, ]; - // Safety timeout. Executor has timeout, and open runtime has soft timeout. - // This one shouldn't really happen, but prevents from unexpected networking behaviours. - if ($requestTimeout == null) { - $requestTimeout = $timeout + 15; - } + $timeout = (int) App::getEnv('_APP_FUNCTIONS_BUILD_TIMEOUT', 900); - $response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $requestTimeout); + $response = $this->call(self::METHOD_POST, $route, [ 'x-opr-runtime-id' => $runtimeId ], $params, true, $timeout); $status = $response['headers']['status-code']; if ($status >= 400) { diff --git a/tests/e2e/Services/Avatars/AvatarsBase.php b/tests/e2e/Services/Avatars/AvatarsBase.php index ba66920ed6..b8581b952e 100644 --- a/tests/e2e/Services/Avatars/AvatarsBase.php +++ b/tests/e2e/Services/Avatars/AvatarsBase.php @@ -202,7 +202,7 @@ trait AvatarsBase $response = $this->client->call(Client::METHOD_GET, '/avatars/image', [ 'x-appwrite-project' => $this->getProject()['$id'], ], [ - 'url' => 'https://appwrite.io/images/open-graph/website.png', + 'url' => 'https://appwrite.io/images/apple.png', ]); $this->assertEquals(200, $response['headers']['status-code']); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index cdc9ec846f..60b7f7542e 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -32,8 +32,8 @@ class FunctionsCustomServerTest extends Scope 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ - 'buckets.*.create', - 'buckets.*.delete', + 'users.*.create', + 'users.*.delete', ], 'schedule' => '0 0 1 1 *', 'timeout' => 10, @@ -50,8 +50,8 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(true, $dateValidator->isValid($response1['body']['$updatedAt'])); $this->assertEquals('', $response1['body']['deployment']); $this->assertEquals([ - 'buckets.*.create', - 'buckets.*.delete', + 'users.*.create', + 'users.*.delete', ], $response1['body']['events']); $this->assertEquals('0 0 1 1 *', $response1['body']['schedule']); $this->assertEquals(10, $response1['body']['timeout']); @@ -191,8 +191,8 @@ class FunctionsCustomServerTest extends Scope 'runtime' => 'php-8.0', 'entrypoint' => 'index.php', 'events' => [ - 'buckets.*.create', - 'buckets.*.delete', + 'users.*.create', + 'users.*.delete', ], 'schedule' => '0 0 1 1 *', 'timeout' => 10, @@ -1231,117 +1231,4 @@ class FunctionsCustomServerTest extends Scope $this->assertArrayHasKey('base', $runtime); $this->assertArrayHasKey('supports', $runtime); } - - - public function testEventTrigger() - { - $timeout = 5; - $code = realpath(__DIR__ . '/../../../resources/functions') . "/php-event/code.tar.gz"; - $this->packageCode('php-event'); - - $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 Event executions', - 'runtime' => 'php-8.0', - 'entrypoint' => 'index.php', - 'events' => [ - 'users.*.create', - ], - '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']); - - // Poll until deployment is built - while (true) { - $deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/deployments/' . $deploymentId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ]); - - if ( - $deployment['headers']['status-code'] >= 400 - || \in_array($deployment['body']['status'], ['ready', 'failed']) - ) { - break; - } - - \sleep(1); - } - - $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); - - // Create user to trigger event - $user = $this->client->call(Client::METHOD_POST, '/users', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'userId' => 'unique()', - 'name' => 'Event User' - ]); - - $userId = $user['body']['$id']; - - $this->assertEquals(201, $user['headers']['status-code']); - - // Wait for execution to occur - 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())); - - $execution = $executions['body']['executions'][0]; - - $this->assertEquals(200, $executions['headers']['status-code']); - $this->assertEquals('completed', $execution['status']); - $this->assertEquals(204, $execution['responseStatusCode']); - $this->assertStringContainsString($userId, $execution['logs']); - $this->assertStringContainsString('Event User', $execution['logs']); - - // 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']); - - // Cleanup : Delete user - $response = $this->client->call(Client::METHOD_DELETE, '/users/' . $userId, [ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - 'x-appwrite-key' => $this->getProject()['apiKey'], - ], []); - - $this->assertEquals(204, $response['headers']['status-code']); - } } diff --git a/tests/e2e/Services/GraphQL/AvatarsTest.php b/tests/e2e/Services/GraphQL/AvatarsTest.php index b95e3b251f..cfb9061df3 100644 --- a/tests/e2e/Services/GraphQL/AvatarsTest.php +++ b/tests/e2e/Services/GraphQL/AvatarsTest.php @@ -155,7 +155,7 @@ class AvatarsTest extends Scope 'x-appwrite-project' => $projectId, ], $this->getHeaders()), $graphQLPayload); - $this->assertEquals(5041, \strlen($initials['body'])); + $this->assertEquals(4959, \strlen($initials['body'])); return $initials['body']; } diff --git a/tests/e2e/Services/Health/HealthCustomServerTest.php b/tests/e2e/Services/Health/HealthCustomServerTest.php index 4ac15bd95c..96c9bde5c7 100644 --- a/tests/e2e/Services/Health/HealthCustomServerTest.php +++ b/tests/e2e/Services/Health/HealthCustomServerTest.php @@ -29,6 +29,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['ping']); $this->assertLessThan(100, $response['body']['ping']); + /** + * Test for FAILURE + */ + return []; } @@ -47,6 +51,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['statuses'][0]['ping']); $this->assertLessThan(100, $response['body']['statuses'][0]['ping']); + /** + * Test for FAILURE + */ + return []; } @@ -65,6 +73,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['statuses'][0]['ping']); $this->assertLessThan(100, $response['body']['statuses'][0]['ping']); + /** + * Test for FAILURE + */ + return []; } @@ -83,6 +95,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['statuses'][0]['ping']); $this->assertLessThan(100, $response['body']['statuses'][0]['ping']); + /** + * Test for FAILURE + */ + return []; } @@ -101,6 +117,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['statuses'][0]['ping']); $this->assertLessThan(100, $response['body']['statuses'][0]['ping']); + /** + * Test for FAILURE + */ + return []; } @@ -121,6 +141,10 @@ class HealthCustomServerTest extends Scope $this->assertNotEmpty($response['body']['localTime']); $this->assertLessThan(10, $response['body']['diff']); + /** + * Test for FAILURE + */ + return []; } @@ -138,6 +162,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + return []; } @@ -155,6 +183,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); + /** + * Test for FAILURE + */ + return []; } @@ -172,124 +204,9 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['size']); $this->assertLessThan(100, $response['body']['size']); - return []; - } - - public function testFunctionsSuccess(): array - { /** - * Test for SUCCESS + * Test for FAILURE */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/functions', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); - - return []; - } - - public function testBuildsSuccess(): array - { - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/builds', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); - - return []; - } - - public function testDatabasesSuccess(): array - { - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/databases', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); - - return []; - } - - public function testDeletesSuccess(): array - { - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/deletes', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); - - return []; - } - - public function testMailsSuccess(): array - { - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/mails', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); - - return []; - } - - public function testMessagingSuccess(): array - { - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/messaging', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); - - return []; - } - - public function testMigrationsSuccess(): array - { - /** - * Test for SUCCESS - */ - $response = $this->client->call(Client::METHOD_GET, '/health/queue/migrations', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), []); - - $this->assertEquals(200, $response['headers']['status-code']); - $this->assertIsInt($response['body']['size']); - $this->assertLessThan(100, $response['body']['size']); return []; } @@ -309,6 +226,10 @@ class HealthCustomServerTest extends Scope $this->assertIsInt($response['body']['ping']); $this->assertLessThan(100, $response['body']['ping']); + /** + * Test for FAILURE + */ + return []; } @@ -327,6 +248,10 @@ class HealthCustomServerTest extends Scope $this->assertIsString($response['body']['status']); $this->assertIsString($response['body']['version']); + /** + * Test for FAILURE + */ + return []; } } diff --git a/tests/e2e/Services/Users/UsersBase.php b/tests/e2e/Services/Users/UsersBase.php index 3327bb7558..baf601789a 100644 --- a/tests/e2e/Services/Users/UsersBase.php +++ b/tests/e2e/Services/Users/UsersBase.php @@ -595,18 +595,6 @@ trait UsersBase $this->assertCount(1, $response['body']['users']); $this->assertEquals($response['body']['users'][0]['$id'], $data['userId']); - $response = $this->client->call(Client::METHOD_GET, '/users', array_merge([ - 'content-type' => 'application/json', - 'x-appwrite-project' => $this->getProject()['$id'], - ], $this->getHeaders()), [ - 'search' => '>', - ]); - - $this->assertEquals($response['headers']['status-code'], 200); - $this->assertNotEmpty($response['body']); - $this->assertEmpty($response['body']['users']); - $this->assertCount(0, $response['body']['users']); - /** * Test for FAILURE */ diff --git a/tests/resources/docker/docker-compose.yml b/tests/resources/docker/docker-compose.yml index bdb9bf49a4..3baae7316d 100644 --- a/tests/resources/docker/docker-compose.yml +++ b/tests/resources/docker/docker-compose.yml @@ -66,9 +66,7 @@ services: environment: - _APP_ENV - _APP_OPTIONS_ABUSE - - _APP_OPTIONS_ROUTER_PROTECTION - _APP_OPTIONS_FORCE_HTTPS - - _APP_OPTIONS_FUNCTIONS_FORCE_HTTPS - _APP_OPENSSL_KEY_V1 - _APP_DOMAIN - _APP_DOMAIN_FUNCTIONS diff --git a/tests/resources/functions/php-event/index.php b/tests/resources/functions/php-event/index.php deleted file mode 100644 index 550fd57729..0000000000 --- a/tests/resources/functions/php-event/index.php +++ /dev/null @@ -1,8 +0,0 @@ -log($context->req->body['$id']); - $context->log($context->req->body['name']); - - return $context->res->empty(); -};