From ff78bf86851b5b7090bc650f7057b7e6b9591ec8 Mon Sep 17 00:00:00 2001 From: shimon Date: Thu, 2 Feb 2023 15:43:19 +0200 Subject: [PATCH] addressing comments --- app/console | 2 +- tests/e2e/General/UsageTest.php | 21 +++++++-------- .../Functions/FunctionsCustomServerTest.php | 3 ++- .../Realtime/RealtimeCustomClientTest.php | 26 ++++++++++++++++--- 4 files changed, 36 insertions(+), 16 deletions(-) diff --git a/app/console b/app/console index b1a81a390a..fae048b917 160000 --- a/app/console +++ b/app/console @@ -1 +1 @@ -Subproject commit b1a81a390a05746701651fca49e0d853f430677c +Subproject commit fae048b91787d0b372c13caf27f14fc8b780ef60 diff --git a/tests/e2e/General/UsageTest.php b/tests/e2e/General/UsageTest.php index 711c9bf017..e21164804a 100644 --- a/tests/e2e/General/UsageTest.php +++ b/tests/e2e/General/UsageTest.php @@ -111,14 +111,12 @@ class UsageTest extends Scope $this->validateDates($res['users']); $this->assertEquals($requestsCount, $res['requests'][array_key_last($res['requests'])]['value']); $this->validateDates($res['requests']); - $requestsCount++; $res = $this->client->call(Client::METHOD_GET, '/users/usage?range=30d', array_merge($headers, [ 'x-appwrite-project' => $projectId, 'x-appwrite-mode' => 'admin' ])); - $requestsCount++; $res = $res['body']; @@ -270,7 +268,7 @@ class UsageTest extends Scope $filesCreate = $data['filesCreate']; $filesDelete = $data['filesDelete']; - sleep(30); + sleep(20); // console request $headers = [ @@ -390,7 +388,7 @@ class UsageTest extends Scope for ($i = 0; $i < 10; $i++) { $name = uniqid() . ' collection'; - $res = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', array_merge($headers, ['content-type' => 'multipart/form-data']), [ + $res = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections', $headers, [ 'collectionId' => 'unique()', 'name' => $name, 'documentSecurity' => false, @@ -423,11 +421,12 @@ class UsageTest extends Scope } } - $res = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes' . '/string', array_merge($headers, ['content-type' => 'multipart/form-data']), [ + $res = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/attributes' . '/string', $headers, [ 'key' => 'name', 'size' => 255, 'required' => true, ]); + $this->assertEquals('name', $res['body']['key']); $collectionsUpdate++; $requestsCount++; @@ -436,7 +435,7 @@ class UsageTest extends Scope for ($i = 0; $i < 10; $i++) { $name = uniqid() . ' collection'; - $res = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', array_merge($headers, ['content-type' => 'multipart/form-data']), [ + $res = $this->client->call(Client::METHOD_POST, '/databases/' . $databaseId . '/collections/' . $collectionId . '/documents', $headers, [ 'documentId' => 'unique()', 'data' => ['name' => $name] ]); @@ -514,7 +513,7 @@ class UsageTest extends Scope $documentsRead = $data['documentsRead']; $documentsDelete = $data['documentsDelete']; - sleep(30); + sleep(20); // check datbase stats $headers = [ @@ -628,7 +627,7 @@ class UsageTest extends Scope $executions = 0; $failures = 0; - $response1 = $this->client->call(Client::METHOD_POST, '/functions', array_merge($headers, ['content-type' => 'multipart/form-data']), [ + $response1 = $this->client->call(Client::METHOD_POST, '/functions', $headers, [ 'functionId' => 'unique()', 'name' => 'Test', 'runtime' => 'php-8.0', @@ -653,7 +652,7 @@ class UsageTest extends Scope $code = realpath(__DIR__ . '/../../resources/functions') . "/php/code.tar.gz"; $this->packageCode('php'); - $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge($headers, ['content-type' => 'multipart/form-data',]), [ + $deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', $headers, [ 'entrypoint' => 'index.php', 'code' => new CURLFile($code, 'application/x-gzip', \basename($code)), 'activate' => true @@ -677,7 +676,7 @@ class UsageTest extends Scope $this->assertEquals(true, DateTime::isValid($response['body']['$updatedAt'])); $this->assertEquals($deploymentId, $response['body']['deployment']); - $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', array_merge($headers, ['content-type' => 'multipart/form-data']), [ + $execution = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/executions', $headers, [ 'async' => false, ]); @@ -744,7 +743,7 @@ class UsageTest extends Scope $executions = $data['executions']; $failures = $data['failures']; - sleep(30); + sleep(20); $response = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/usage', $headers, [ 'range' => '30d' diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index e97c1412b6..03cf910dda 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -635,7 +635,7 @@ class FunctionsCustomServerTest extends Scope $this->assertStringContainsString('8.0', $execution['body']['response']); $this->assertStringContainsString('êä', $execution['body']['response']); // tests unknown utf-8 chars $this->assertEquals('', $execution['body']['stderr']); - $this->assertLessThan(3, $execution['body']['duration']); + $this->assertLessThan(1.500, $execution['body']['duration']); /** * Test for FAILURE @@ -915,6 +915,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals($executions['body']['executions'][0]['statusCode'], 500); $this->assertGreaterThan(2, $executions['body']['executions'][0]['duration']); $this->assertLessThan(6, $executions['body']['executions'][0]['duration']); + $this->assertLessThan(4, $executions['body']['executions'][0]['duration']); $this->assertEquals($executions['body']['executions'][0]['response'], ''); $this->assertEquals($executions['body']['executions'][0]['stderr'], 'An internal curl error has occurred within the executor! Error Msg: Operation timed out'); diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index be8f81f445..86832f99e1 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -211,6 +211,26 @@ class RealtimeCustomClientTest extends Scope $this->assertEquals(1003, $response['data']['code']); $this->assertEquals('Message format is not valid.', $response['data']['message']); + + + $client->close(); + } + + public function testConnectionPlatform() + { + /** + * Test for FAILURE + */ + $client = $this->getWebsocket(['documents'], ['origin' => 'http://appwrite.unknown']); + $payload = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $payload); + $this->assertArrayHasKey('data', $payload); + $this->assertEquals('error', $payload['type']); + $this->assertEquals(1008, $payload['data']['code']); + $this->assertEquals('Invalid Origin. Register your new client (appwrite.unknown) as a new Web platform on your project console dashboard', $payload['data']['message']); + \usleep(250000); // 250ms + $this->expectException(ConnectionException::class); // Check if server disconnnected client $client->close(); } @@ -440,8 +460,8 @@ class RealtimeCustomClientTest extends Scope $this->assertNotEmpty($response['data']['payload']); /** -// * Test Account Session Create -// */ + * Test Account Session Create + */ $response = $this->client->call(Client::METHOD_POST, '/account/sessions/email', array_merge([ 'origin' => 'http://localhost', 'content-type' => 'application/json', @@ -1229,7 +1249,7 @@ class RealtimeCustomClientTest extends Scope $this->assertNotEmpty($deployment['body']['$id']); // Wait for deployment to be built. - sleep(10); + sleep(5); $response = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId, array_merge([ 'content-type' => 'application/json',