From acb9548e856febd9e0b651e93cfe0221571dca32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Thu, 13 Mar 2025 10:33:28 +0100 Subject: [PATCH] Fix preview deicison-maker; speed-up tests --- app/controllers/general.php | 2 +- .../Modules/Functions/Workers/Builds.php | 3 +- src/Appwrite/Platform/Tasks/Screenshot.php | 2 ++ .../Services/Sites/SitesCustomServerTest.php | 30 ++++++------------- 4 files changed, 14 insertions(+), 23 deletions(-) diff --git a/app/controllers/general.php b/app/controllers/general.php index d8e7bc12dd..596d7dd4aa 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -151,7 +151,7 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw Authorization::skip(fn () => $dbForProject->getDocument('functions', $deployment->getAttribute('resourceId', ''))) : Authorization::skip(fn () => $dbForProject->getDocument('sites', $deployment->getAttribute('resourceId', ''))); - $isPreview = $type === 'function' ? false : ($rule->getAttribute('deploymentId', '') !== $resource->getAttribute('deploymentId', '')); + $isPreview = $type === 'function' ? false : ($rule->getAttribute('trigger', '') !== 'manual'); $path = ($swooleRequest->server['request_uri'] ?? '/'); $query = ($swooleRequest->server['query_string'] ?? ''); diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index 408de4eaab..ea54abfcf7 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -794,9 +794,10 @@ class Builds extends Action $config['sleep'] = 3000; // 3 seconds + // Makes tests much faster $isDevelopment = System::getEnv('_APP_ENV', 'development') === 'development'; if ($isDevelopment) { - $config['timeout'] = 10000; // 10 seconds + $config['sleep'] = 0; // Override this when running Screenshot.php task } $response = $client->fetch( diff --git a/src/Appwrite/Platform/Tasks/Screenshot.php b/src/Appwrite/Platform/Tasks/Screenshot.php index 918ce60e11..29a3d7647e 100644 --- a/src/Appwrite/Platform/Tasks/Screenshot.php +++ b/src/Appwrite/Platform/Tasks/Screenshot.php @@ -37,6 +37,8 @@ class Screenshot extends Action throw new \Exception("Template {$templateId} not found. Find correct ID in app/config/templates/site.php"); } + Console::warning('Make sure to override $config[\'sleep\'] in Builds.php worker to high number, like 10000 (10 seconds)'); + Console::info("Found: " . $template['name']); $client = new Client(); diff --git a/tests/e2e/Services/Sites/SitesCustomServerTest.php b/tests/e2e/Services/Sites/SitesCustomServerTest.php index aaec1fc450..eada127d6c 100644 --- a/tests/e2e/Services/Sites/SitesCustomServerTest.php +++ b/tests/e2e/Services/Sites/SitesCustomServerTest.php @@ -1659,20 +1659,14 @@ class SitesCustomServerTest extends Scope ]); $this->assertNotEmpty($deploymentId); - $oldDeploymentDomain = $this->getDeploymentDomain($deploymentId); - $this->assertNotEmpty($oldDeploymentDomain); + $siteDomain = $this->setupSiteDomain($siteId); + $this->assertNotEmpty($siteDomain); - $deploymentId = $this->setupDeployment($siteId, [ - 'code' => $this->packageSite('static'), - 'activate' => 'true' - ]); - $this->assertNotEmpty($deploymentId); - - $newDeploymentDomain = $this->getDeploymentDomain($deploymentId); - $this->assertNotEmpty($newDeploymentDomain); + $delpoymentDomain = $this->getDeploymentDomain($deploymentId); + $this->assertNotEmpty($delpoymentDomain); $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $newDeploymentDomain); + $proxyClient->setEndpoint('http://' . $siteDomain); $response = $proxyClient->call(Client::METHOD_GET, '/'); $this->assertEquals(200, $response['headers']['status-code']); $this->assertStringContainsString("Hello Appwrite", $response['body']); @@ -1680,7 +1674,7 @@ class SitesCustomServerTest extends Scope $contentLength = $response['headers']['content-length']; $proxyClient = new Client(); - $proxyClient->setEndpoint('http://' . $oldDeploymentDomain); + $proxyClient->setEndpoint('http://' . $delpoymentDomain); $response = $proxyClient->call(Client::METHOD_GET, '/', followRedirects: false); $this->assertEquals(301, $response['headers']['status-code']); $this->assertStringContainsString('/console/auth/preview', $response['headers']['location']); @@ -2069,13 +2063,6 @@ class SitesCustomServerTest extends Scope $domain = $this->getDeploymentDomain($deploymentId); $this->assertNotEmpty($domain); - // Create second deployment to make first one a preview - $deploymentId = $this->setupDeployment($siteId, [ - 'code' => $this->packageSite('static'), - 'activate' => true - ]); - $this->assertNotEmpty($deploymentId); - $proxyClient = new Client(); $proxyClient->setEndpoint('http://' . $domain); @@ -2177,13 +2164,14 @@ class SitesCustomServerTest extends Scope $this->assertStringContainsString('/console/auth/preview', $response['headers']['location']); // Failure: Membership missing + $email = \uniqid() . 'newuser@appwrite.io'; $user = $this->client->call(Client::METHOD_POST, '/account', [ 'origin' => 'http://localhost', 'content-type' => 'application/json', 'x-appwrite-project' => 'console', ], [ 'userId' => ID::unique(), - 'email' => 'newuser@appwrite.io', + 'email' => $email, 'password' => 'password' ]); $this->assertEquals(201, $user['headers']['status-code']); @@ -2193,7 +2181,7 @@ class SitesCustomServerTest extends Scope 'content-type' => 'application/json', 'x-appwrite-project' => 'console', ], [ - 'email' => 'newuser@appwrite.io', + 'email' => $email, 'password' => 'password', ]); $this->assertEquals(201, $session['headers']['status-code']);