chore: updated to use assertEventually

This commit is contained in:
Chirag Aggarwal
2025-03-03 16:07:33 +00:00
parent e865ca74d7
commit fc05a4f1e3
2 changed files with 11 additions and 36 deletions
@@ -1311,29 +1311,16 @@ class RealtimeCustomClientTest extends Scope
$this->assertEquals($deployment['headers']['status-code'], 202);
$this->assertNotEmpty($deployment['body']['$id']);
$maxTimeSeconds = 10;
$startTime = time();
// Poll until deployment is built
while (true) {
$this->assertEventually(function () use ($function, $deploymentId) {
$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;
}
if (time() - $startTime >= $maxTimeSeconds) {
throw new \Exception('Deployment timed out after ' . $maxTimeSeconds . ' seconds');
}
\sleep(1);
}
$this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body']));
});
$response = $this->client->call(Client::METHOD_PATCH, '/functions/' . $functionId . '/deployments/' . $deploymentId, array_merge([
'content-type' => 'application/json',
+8 -20
View File
@@ -2,6 +2,7 @@
namespace Tests\E2E\Services\Webhooks;
use Appwrite\Tests\Async;
use Appwrite\Tests\Retry;
use CURLFile;
use Tests\E2E\Client;
@@ -12,35 +13,22 @@ use Utopia\Database\Validator\Datetime as DatetimeValidator;
trait WebhooksBase
{
use Async;
protected function awaitDeploymentIsBuilt($functionId, $deploymentId, $checkForSuccess = true): void
{
$maxTimeSeconds = 10;
$startTime = time();
while (true) {
$this->assertEventually(function () use ($functionId, $deploymentId, $checkForSuccess) {
$deployment = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/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;
if ($checkForSuccess) {
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body']));
}
if (time() - $startTime >= $maxTimeSeconds) {
throw new \Exception('Deployment timed out after ' . $maxTimeSeconds . ' seconds');
}
\sleep(1);
}
if ($checkForSuccess) {
$this->assertEquals(200, $deployment['headers']['status-code']);
$this->assertEquals('ready', $deployment['body']['status'], \json_encode($deployment['body']));
}
});
}
public static function getWebhookSignature(array $webhook, string $signatureKey): string