From 213e16050bd5cbd5021d40534c9b9dc2c930b99e Mon Sep 17 00:00:00 2001 From: Fabian Gruber Date: Wed, 5 Feb 2025 13:17:21 +0100 Subject: [PATCH] fix(test): use assertEventually instead of while(true) --- .../Services/GraphQL/FunctionsClientTest.php | 18 +++++------------- .../Services/GraphQL/FunctionsServerTest.php | 19 +++++-------------- 2 files changed, 10 insertions(+), 27 deletions(-) diff --git a/tests/e2e/Services/GraphQL/FunctionsClientTest.php b/tests/e2e/Services/GraphQL/FunctionsClientTest.php index e7e8421254..0b43ed5772 100644 --- a/tests/e2e/Services/GraphQL/FunctionsClientTest.php +++ b/tests/e2e/Services/GraphQL/FunctionsClientTest.php @@ -2,6 +2,7 @@ namespace Tests\E2E\Services\GraphQL; +use Appwrite\Tests\Async; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; @@ -14,6 +15,7 @@ class FunctionsClientTest extends Scope use ProjectCustom; use SideClient; use Base; + use Async; public function testCreateFunction(): array { @@ -119,7 +121,7 @@ class FunctionsClientTest extends Scope ] ]; - while (true) { + $this->assertEventually(function () use ($projectId, $gqlPayload, &$deployment) { $deployment = $this->client->call(Client::METHOD_POST, '/graphql', [ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, @@ -130,18 +132,8 @@ class FunctionsClientTest extends Scope $this->assertArrayNotHasKey('errors', $deployment['body']); $deployment = $deployment['body']['data']['functionsGetDeployment']; - - if ( - $deployment['status'] === 'ready' - || $deployment['status'] === 'failed' - ) { - break; - } - - \sleep(1); - } - - $this->assertEquals('ready', $deployment['status']); + $this->assertEquals('ready', $deployment['status']); + }); return $deployment; } diff --git a/tests/e2e/Services/GraphQL/FunctionsServerTest.php b/tests/e2e/Services/GraphQL/FunctionsServerTest.php index c3606244c4..e49ac43619 100644 --- a/tests/e2e/Services/GraphQL/FunctionsServerTest.php +++ b/tests/e2e/Services/GraphQL/FunctionsServerTest.php @@ -2,6 +2,7 @@ namespace Tests\E2E\Services\GraphQL; +use Appwrite\Tests\Async; use Tests\E2E\Client; use Tests\E2E\Scopes\ProjectCustom; use Tests\E2E\Scopes\Scope; @@ -14,6 +15,7 @@ class FunctionsServerTest extends Scope use ProjectCustom; use SideServer; use Base; + use Async; public function testCreateFunction(): array { @@ -117,7 +119,7 @@ class FunctionsServerTest extends Scope ] ]; - while (true) { + $this->assertEventually(function () use ($projectId, $gqlPayload, &$deployment) { $deployment = $this->client->call(Client::METHOD_POST, '/graphql', \array_merge([ 'content-type' => 'application/json', 'x-appwrite-project' => $projectId, @@ -127,19 +129,8 @@ class FunctionsServerTest extends Scope $this->assertArrayNotHasKey('errors', $deployment['body']); $deployment = $deployment['body']['data']['functionsGetDeployment']; - - if ( - $deployment['status'] === 'ready' - || $deployment['status'] === 'failed' - ) { - break; - } - - \sleep(1); - } - - $this->assertEquals('ready', $deployment['status']); - + $this->assertEquals('ready', $deployment['status']); + }); return $deployment; }