mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 09:28:40 +00:00
feat: fix tests
This commit is contained in:
parent
0de8ff6d41
commit
7d82c1006a
7 changed files with 26 additions and 38 deletions
|
|
@ -368,6 +368,7 @@ App::patch('/v1/functions/:functionId/deployment')
|
|||
|
||||
$function = $dbForProject->getDocument('functions', $functionId);
|
||||
$deployment = $dbForProject->getDocument('deployments', $deployment);
|
||||
var_dump($deployment);
|
||||
$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId', ''));
|
||||
|
||||
if ($function->isEmpty()) {
|
||||
|
|
@ -699,7 +700,7 @@ App::delete('/v1/functions/:functionId/deployments/:deploymentId')
|
|||
throw new Exception('Deployment not found', 404);
|
||||
}
|
||||
|
||||
if ($deployment->getAttribute('functionId') !== $function->getId()) {
|
||||
if ($deployment->getAttribute('resourceId') !== $function->getId()) {
|
||||
throw new Exception('Deployment not found', 404);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -408,7 +408,7 @@ function execute(string $trigger, string $projectId, string $executionId, string
|
|||
$buildId = $database->getId();
|
||||
$database->createDocument('builds', new Document([
|
||||
'$id' => $buildId,
|
||||
'$read' => ($userId !== '') ? ['user:' . $userId] : [],
|
||||
'$read' => [],
|
||||
'$write' => [],
|
||||
'startTime' => time(),
|
||||
'deploymentId' => $deployment->getId(),
|
||||
|
|
@ -685,9 +685,7 @@ function runBuildStage(string $buildId, string $deploymentId, string $projectID)
|
|||
|
||||
// Update deployment Status
|
||||
$build->setAttribute('status', 'building');
|
||||
$deployment->setAttribute('status', 'building');
|
||||
$database->updateDocument('builds', $buildId, $build);
|
||||
$database->updateDocument('deployments', $deploymentId, $deployment);
|
||||
|
||||
// Check if runtime is active
|
||||
$runtime = $runtimes[$build->getAttribute('runtime', '')] ?? null;
|
||||
|
|
@ -903,14 +901,11 @@ function runBuildStage(string $buildId, string $deploymentId, string $projectID)
|
|||
->setAttribute('stdout', \utf8_encode(\mb_substr($buildStdout, -4096)))
|
||||
->setAttribute('stderr', \utf8_encode(\mb_substr($e->getMessage(), -4096)))
|
||||
->setAttribute('startTime', $buildStart)
|
||||
->setAttribute('endTime', \microtime(true))
|
||||
->setAttribute('duration', \microtime(true) - $buildStart);
|
||||
->setAttribute('endTime', \time())
|
||||
->setAttribute('duration', \time() - $buildStart);
|
||||
|
||||
$build = $database->updateDocument('builds', $buildId, $build);
|
||||
|
||||
$deployment->setAttribute('status', 'failed');
|
||||
$database->updateDocument('deployments', $deploymentId, $deployment);
|
||||
|
||||
// also remove the container if it exists
|
||||
if (isset($id)) {
|
||||
$orchestration->remove($id, true);
|
||||
|
|
@ -971,6 +966,7 @@ App::delete('/v1/functions/:functionId')
|
|||
->send();
|
||||
}
|
||||
|
||||
Console::info('Deleting function: ' . $functionId);
|
||||
// Delete the containers of all deployments
|
||||
global $register;
|
||||
foreach ($results as $deployment) {
|
||||
|
|
@ -1052,7 +1048,7 @@ App::delete('/v1/deployments/:deploymentId')
|
|||
->inject('projectId')
|
||||
->inject('response')
|
||||
->action(function (string $deploymentId, string $projectId, Response $response) use ($orchestrationPool) {
|
||||
|
||||
Console::info('Deleting deployment: ' . $deploymentId);
|
||||
global $register;
|
||||
go(function () use ($projectId, $orchestrationPool, $register, $deploymentId) {
|
||||
try {
|
||||
|
|
@ -1154,12 +1150,10 @@ App::post('/v1/functions/:functionId/deployments/:deploymentId/builds/:buildId')
|
|||
|
||||
// Deploy Runtime Server
|
||||
try {
|
||||
Console::info("[ INFO ] Creating runtime server");
|
||||
Console::info("Creating runtime server");
|
||||
createRuntimeServer($functionId, $projectId, $deploymentId, $dbForProject);
|
||||
} catch (\Throwable $th) {
|
||||
Console::error($th->getMessage());
|
||||
$deployment->setAttribute('status', 'failed');
|
||||
$deployment = $dbForProject->updateDocument('deployments', $deploymentId, $deployment);
|
||||
throw $th;
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ class BuildsV1 extends Worker
|
|||
case BUILD_TYPE_DEPLOYMENT:
|
||||
$functionId = $this->args['functionId'] ?? '';
|
||||
$deploymentId = $this->args['deploymentId'] ?? '';
|
||||
Console::info("[ INFO ] Creating build for deployment: $deploymentId");
|
||||
Console::info("Creating build for deployment: $deploymentId");
|
||||
$this->buildDeployment($projectId, $functionId, $deploymentId);
|
||||
break;
|
||||
|
||||
|
|
@ -45,7 +45,7 @@ class BuildsV1 extends Worker
|
|||
$buildId = $this->args['buildId'] ?? '';
|
||||
$functionId = $this->args['functionId'] ?? '';
|
||||
$deploymentId = $this->args['deploymentId'] ?? '';
|
||||
Console::info("[ INFO ] Retrying build for id: $buildId");
|
||||
Console::info("Retrying build for id: $buildId");
|
||||
$this->createBuild($projectId, $functionId, $deploymentId, $buildId);
|
||||
break;
|
||||
|
||||
|
|
@ -113,29 +113,21 @@ class BuildsV1 extends Worker
|
|||
if (empty($buildId)) {
|
||||
try {
|
||||
$buildId = $dbForProject->getId();
|
||||
// TODO : There is no way to associate a build with a deployment. So we need to add a deploymentId attribute to the build document
|
||||
$dbForProject->createDocument('builds', new Document([
|
||||
'$id' => $buildId,
|
||||
'$read' => [],
|
||||
'$write' => [],
|
||||
'startTime' => time(),
|
||||
'deploymentId' => $deploymentId,
|
||||
'dateCreated' => time(),
|
||||
'status' => 'processing',
|
||||
'runtime' => $function->getAttribute('runtime'),
|
||||
'outputPath' => '',
|
||||
'runtime' => $function->getAttribute('runtime'),
|
||||
'source' => $deployment->getAttribute('path'),
|
||||
'sourceType' => Storage::DEVICE_LOCAL,
|
||||
'stdout' => '',
|
||||
'stderr' => '',
|
||||
'time' => 0,
|
||||
'vars' => [
|
||||
'ENTRYPOINT_NAME' => $deployment->getAttribute('entrypoint'),
|
||||
'APPWRITE_FUNCTION_ID' => $function->getId(),
|
||||
'APPWRITE_FUNCTION_NAME' => $function->getAttribute('name', ''),
|
||||
'APPWRITE_FUNCTION_RUNTIME_NAME' => $runtime['name'],
|
||||
'APPWRITE_FUNCTION_RUNTIME_VERSION' => $runtime['version'],
|
||||
'APPWRITE_FUNCTION_PROJECT_ID' => $projectId,
|
||||
]
|
||||
'endTime' => 0,
|
||||
'duration' => 0
|
||||
]));
|
||||
} catch (\Throwable $th) {
|
||||
$deployment->setAttribute('buildId', '');
|
||||
|
|
@ -155,7 +147,7 @@ class BuildsV1 extends Worker
|
|||
throw $th;
|
||||
}
|
||||
|
||||
Console::success("[ SUCCESS ] Build id: $buildId started");
|
||||
Console::success("Build id: $buildId started");
|
||||
}
|
||||
|
||||
public function shutdown(): void {}
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ class DeletesV1 extends Worker
|
|||
], $dbForProject, function (Document $document) use ($storageFunctions, &$deploymentIds) {
|
||||
$deploymentIds[] = $document->getId();
|
||||
if ($storageFunctions->delete($document->getAttribute('path', ''), true)) {
|
||||
Console::success('Delete deployment files: ' . $document->getAttribute('path', ''));
|
||||
Console::success('Deleted deployment files: ' . $document->getAttribute('path', ''));
|
||||
} else {
|
||||
Console::error('Failed to delete deployment files: ' . $document->getAttribute('path', ''));
|
||||
}
|
||||
|
|
@ -425,7 +425,7 @@ class DeletesV1 extends Worker
|
|||
*/
|
||||
$storageFunctions = new Local(APP_STORAGE_FUNCTIONS . '/app-' . $projectId);
|
||||
if ($storageFunctions->delete($document->getAttribute('path', ''), true)) {
|
||||
Console::success('Delete deployment files: ' . $document->getAttribute('path', ''));
|
||||
Console::success('Deleted deployment files: ' . $document->getAttribute('path', ''));
|
||||
} else {
|
||||
Console::error('Failed to delete deployment files: ' . $document->getAttribute('path', ''));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ class FunctionsCustomClientTest extends Scope
|
|||
$this->assertEquals(201, $deployment['headers']['status-code']);
|
||||
|
||||
// Wait for deployment to be built.
|
||||
sleep(5);
|
||||
sleep(10);
|
||||
|
||||
$function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$function['body']['$id'].'/deployment', [
|
||||
'content-type' => 'application/json',
|
||||
|
|
@ -97,6 +97,8 @@ class FunctionsCustomClientTest extends Scope
|
|||
'deployment' => $deploymentId,
|
||||
]);
|
||||
|
||||
// var_dump($function);
|
||||
|
||||
$this->assertEquals(200, $function['headers']['status-code']);
|
||||
|
||||
$execution = $this->client->call(Client::METHOD_POST, '/functions/'.$function['body']['$id'].'/executions', [
|
||||
|
|
@ -356,7 +358,7 @@ class FunctionsCustomClientTest extends Scope
|
|||
$this->assertEquals(201, $deployment['headers']['status-code']);
|
||||
|
||||
// Wait for deployment to be built.
|
||||
sleep(5);
|
||||
sleep(10);
|
||||
|
||||
$function = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', [
|
||||
'content-type' => 'application/json',
|
||||
|
|
|
|||
|
|
@ -291,10 +291,9 @@ class FunctionsCustomServerTest extends Scope
|
|||
$this->assertNotEmpty($deployment['body']['$id']);
|
||||
$this->assertIsInt($deployment['body']['dateCreated']);
|
||||
$this->assertEquals('index.php', $deployment['body']['entrypoint']);
|
||||
// $this->assertGreaterThan(10000, $deployment['body']['size']);
|
||||
|
||||
// Wait for deployment to build.
|
||||
sleep(5);
|
||||
sleep(15);
|
||||
|
||||
/**
|
||||
* Test for FAILURE
|
||||
|
|
@ -450,7 +449,7 @@ class FunctionsCustomServerTest extends Scope
|
|||
$this->assertEquals('', $execution['body']['stderr']);
|
||||
$this->assertEquals(0, $execution['body']['time']);
|
||||
|
||||
sleep(15);
|
||||
sleep(5);
|
||||
|
||||
$execution = $this->client->call(Client::METHOD_GET, '/functions/'.$data['functionId'].'/executions/'.$executionId, array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
|
@ -686,7 +685,7 @@ class FunctionsCustomServerTest extends Scope
|
|||
$this->assertEquals(201, $deployment['headers']['status-code']);
|
||||
|
||||
// Allow build step to run
|
||||
sleep(5);
|
||||
sleep(10);
|
||||
|
||||
$deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
|
@ -778,7 +777,7 @@ class FunctionsCustomServerTest extends Scope
|
|||
$this->assertEquals(201, $deployment['headers']['status-code']);
|
||||
|
||||
// Allow build step to run
|
||||
sleep(5);
|
||||
sleep(10);
|
||||
|
||||
$deployment = $this->client->call(Client::METHOD_PATCH, '/functions/'.$functionId.'/deployment', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class ComposeTest extends TestCase
|
|||
|
||||
public function testServices()
|
||||
{
|
||||
$this->assertCount(16, $this->object->getServices());
|
||||
$this->assertCount(17, $this->object->getServices());
|
||||
$this->assertEquals('appwrite-telegraf', $this->object->getService('telegraf')->getContainerName());
|
||||
$this->assertEquals('appwrite', $this->object->getService('appwrite')->getContainerName());
|
||||
$this->assertEquals('', $this->object->getService('appwrite')->getImageVersion());
|
||||
|
|
|
|||
Loading…
Reference in a new issue