1
0
Fork 0
mirror of synced 2024-06-14 00:34:51 +12:00

feat: fix tests

This commit is contained in:
Christy Jacob 2022-01-29 04:00:25 +04:00
parent 8d59a058a9
commit 220a166434
4 changed files with 57 additions and 26 deletions

View file

@ -962,8 +962,6 @@ App::delete('/v1/functions/:functionId')
->send();
}
Console::info("Deleting " . count($results) . " deployments");
// Delete the containers of all deployments
// TODO : @christy Delete all build containers as well. Not just the latest one,
global $register;
@ -1049,15 +1047,10 @@ App::delete('/v1/deployments/:deploymentId')
->action(function (string $deploymentId, string $projectId, Response $response, Database $dbForProject) use ($orchestrationPool) {
// Get deployment document
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
// Check if deployment exists
if ($deployment->isEmpty()) {
throw new Exception('Deployment not found', 404);
}
// $deployment = $dbForProject->getDocument('deployments', $deploymentId);
global $register;
go(function () use ($projectId, $orchestrationPool, $register, $deployment) {
go(function () use ($projectId, $orchestrationPool, $register, $deploymentId) {
try {
$db = $register->get('dbPool')->get();
$redis = $register->get('redisPool')->get();
@ -1069,19 +1062,20 @@ App::delete('/v1/deployments/:deploymentId')
$dbForProject->setNamespace('_project_' . $projectId);
// Remove any ongoing builds
if ($deployment->getAttribute('buildId')) {
$build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId'));
// TODO: Delete builds
// if ($deployment->getAttribute('buildId')) {
// $build = $dbForProject->getDocument('builds', $deployment->getAttribute('buildId'));
if ($build->getAttribute('status') == 'building') {
// Remove the build
$orchestration->remove('build-stage-' . $deployment->getAttribute('buildId'), true);
Console::info('Removed build for deployment ' . $deployment['$id']);
}
}
// if ($build->getAttribute('status') == 'building') {
// // Remove the build
// $orchestration->remove('build-stage-' . $deployment->getAttribute('buildId'), true);
// Console::info('Removed build for deployment ' . $deployment['$id']);
// }
// }
// Remove the container of the deployment
$orchestration->remove('appwrite-function-' . $deployment['$id'], true);
Console::info('Removed container for deployment ' . $deployment['$id']);
$orchestration->remove('appwrite-function-' . $deploymentId , true);
Console::info('Removed container for deployment ' . $deploymentId);
} catch (\Throwable $th) {
Console::error($th->getMessage());
} finally {

View file

@ -419,7 +419,7 @@ class DeletesV1 extends Worker
}
/**
* Delete Deployments
* Delete deployment files
*/
$storageFunctions = new Local(APP_STORAGE_FUNCTIONS . '/app-' . $projectId);
if ($storageFunctions->delete($document->getAttribute('path', ''), true)) {

View file

@ -117,14 +117,14 @@ class FunctionsCustomClientTest extends Scope
$this->assertEquals(201, $execution['headers']['status-code']);
$execution = $this->client->call(Client::METHOD_POST, '/functions/'.$function['body']['$id'].'/executions', array_merge([
// Cleanup : Delete function
$response = $this->client->call(Client::METHOD_DELETE, '/functions/'.$function['body']['$id'], [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
]), [
'async' => true,
]);
'x-appwrite-key' => $this->getProject()['apiKey'],
], []);
$this->assertEquals(401, $execution['headers']['status-code']);
$this->assertEquals(204, $response['headers']['status-code']);
return [];
}
@ -300,6 +300,16 @@ class FunctionsCustomClientTest extends Scope
'cursor' => $base['body']['executions'][1]['$id'],
'cursorDirection' => Database::CURSOR_BEFORE
]);
// Cleanup : Delete function
$response = $this->client->call(Client::METHOD_DELETE, '/functions/'. $functionId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], []);
$this->assertEquals(204, $response['headers']['status-code']);
}
public function testSynchronousExecution():array
@ -382,6 +392,15 @@ class FunctionsCustomClientTest extends Scope
$this->assertNotEmpty($output['APPWRITE_FUNCTION_JWT']);
$this->assertEquals($projectId, $output['APPWRITE_FUNCTION_PROJECT_ID']);
// Cleanup : Delete function
$response = $this->client->call(Client::METHOD_DELETE, '/functions/'. $functionId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], []);
$this->assertEquals(204, $response['headers']['status-code']);
return [];
}
}

View file

@ -660,7 +660,7 @@ class FunctionsCustomServerTest extends Scope
/**
* Test for SUCCESS
*/
$function = $this->client->call(Client::METHOD_DELETE, '/functions/'.$data['functionId'], array_merge([
$function = $this->client->call(Client::METHOD_DELETE, '/functions/'. $data['functionId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
@ -760,6 +760,15 @@ class FunctionsCustomServerTest extends Scope
$this->assertLessThan(3, $executions['body']['executions'][0]['time']);
$this->assertEquals($executions['body']['executions'][0]['stdout'], '');
$this->assertEquals($executions['body']['executions'][0]['stderr'], 'Execution timed out.');
// Cleanup : Delete function
$response = $this->client->call(Client::METHOD_DELETE, '/functions/'. $functionId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], []);
$this->assertEquals(204, $response['headers']['status-code']);
}
/**
@ -861,6 +870,15 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals($executions['body']['executions'][0]['$id'], $executionId);
$this->assertEquals($executions['body']['executions'][0]['trigger'], 'http');
$this->assertStringContainsString('foobar', $executions['body']['executions'][0]['stdout']);
// Cleanup : Delete function
$response = $this->client->call(Client::METHOD_DELETE, '/functions/'. $functionId, [
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
'x-appwrite-key' => $this->getProject()['apiKey'],
], []);
$this->assertEquals(204, $response['headers']['status-code']);
}
public function testGetRuntimes()