mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
test: remove standalone build timeout unit test
This commit is contained in:
1 parent
04f164f64c
commit
87feca2757
1 file changed
-68
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests\Unit\Deployment;
|
||||
|
||||
use Appwrite\Deployment\Deployments;
|
||||
use OpenRuntimes\Orchestrator\Jobs;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Http\Client\ClientInterface;
|
||||
use Psr\Http\Message\RequestInterface;
|
||||
use Utopia\Config\Config;
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Psr7\Response;
|
||||
use Utopia\Psr7\Stream;
|
||||
|
||||
final class BuildTimeoutTest extends TestCase
|
||||
{
|
||||
public static function budgets(): \Iterator
|
||||
{
|
||||
yield 'short operator budget' => [37];
|
||||
yield 'long operator budget' => [1823];
|
||||
}
|
||||
|
||||
#[DataProvider('budgets')]
|
||||
public function testSubmissionUsesConstructorBudget(int $configured): void
|
||||
{
|
||||
$previousKey = getenv('_APP_OPENSSL_KEY_V1');
|
||||
$previousTimeout = getenv('_APP_COMPUTE_BUILD_TIMEOUT');
|
||||
putenv('_APP_OPENSSL_KEY_V1=unit-test-key');
|
||||
putenv('_APP_COMPUTE_BUILD_TIMEOUT=' . $configured);
|
||||
try {
|
||||
$deployment = new Document(['$id' => 'deployment', '$sequence' => '1', 'type' => 'manual', 'buildCommands' => 'npm ci']);
|
||||
$database = $this->createStub(Database::class);
|
||||
$database->method('updateDocument')->willReturnCallback(static function (string $collection, string $id, Document $update) use ($deployment): Document {
|
||||
$deployment->setAttributes($update->getArrayCopy());
|
||||
return clone $deployment;
|
||||
});
|
||||
$database->method('updateDocuments')->willReturnCallback(static function (string $collection, Document $update) use ($deployment): int {
|
||||
$deployment->setAttributes($update->getArrayCopy());
|
||||
return 1;
|
||||
});
|
||||
$database->method('getDocument')->willReturnCallback(static fn () => clone $deployment);
|
||||
$requests = [];
|
||||
$client = $this->createStub(ClientInterface::class);
|
||||
$client->method('sendRequest')->willReturnCallback(static function (RequestInterface $request) use (&$requests): Response {
|
||||
$requests[] = json_decode((string) $request->getBody(), true, flags: JSON_THROW_ON_ERROR);
|
||||
return new Response(202, body: new Stream('{"id":"build","status":"accepted"}'));
|
||||
});
|
||||
$service = new Deployments(new Jobs($client), $database, new Document(['$id' => 'project', 'region' => 'default']), ['apiHostname' => 'localhost'], $configured);
|
||||
putenv('_APP_COMPUTE_BUILD_TIMEOUT=1');
|
||||
|
||||
$result = $service->createFromUpload(new Document([
|
||||
'$id' => 'function', '$collection' => 'functions',
|
||||
'runtime' => array_key_first(Config::getParam('runtimes-v2')),
|
||||
]), clone $deployment);
|
||||
|
||||
$this->assertSame('waiting', $result->getAttribute('status'));
|
||||
$this->assertCount(1, $requests);
|
||||
$this->assertSame($configured, $requests[0]['timeoutSeconds']);
|
||||
} finally {
|
||||
putenv($previousKey === false ? '_APP_OPENSSL_KEY_V1' : '_APP_OPENSSL_KEY_V1=' . $previousKey);
|
||||
putenv($previousTimeout === false ? '_APP_COMPUTE_BUILD_TIMEOUT' : '_APP_COMPUTE_BUILD_TIMEOUT=' . $previousTimeout);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user