1
0
Fork 0
mirror of synced 2024-09-12 23:53:15 +12:00

review: Delete execution

This commit is contained in:
Binyamin Yawitz 2024-06-27 12:36:24 -04:00
parent 9172ff6b14
commit 010f8d3fb8
No known key found for this signature in database
3 changed files with 84 additions and 55 deletions

View file

@ -568,7 +568,7 @@ return [
Exception::EXECUTION_IN_PROGRESS => [ Exception::EXECUTION_IN_PROGRESS => [
'name' => Exception::EXECUTION_IN_PROGRESS, 'name' => Exception::EXECUTION_IN_PROGRESS,
'description' => 'Can\'t delete ongoing execution. Please wait for execution to finish before you can retry.', 'description' => 'Can\'t delete ongoing execution. Please wait for execution to finish before deleting it.',
'code' => 400, 'code' => 400,
], ],

View file

@ -2044,7 +2044,7 @@ App::delete('/v1/functions/:functionId/executions/:executionId')
throw new Exception(Exception::EXECUTION_NOT_FOUND); throw new Exception(Exception::EXECUTION_NOT_FOUND);
} }
if (!in_array($execution->getAttribute('status'), ['completed', 'failed'])) { if (!in_array($execution->getAttribute('status'), ['completed', 'failed', 'scheduled'])) {
throw new Exception(Exception::EXECUTION_IN_PROGRESS); throw new Exception(Exception::EXECUTION_IN_PROGRESS);
} }

View file

@ -454,7 +454,6 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(200, $functionDetails['headers']['status-code']); $this->assertEquals(200, $functionDetails['headers']['status-code']);
$this->assertEquals('cli', $functionDetails['body']['type']); $this->assertEquals('cli', $functionDetails['body']['type']);
} }
/** /**
@ -671,12 +670,16 @@ class FunctionsCustomServerTest extends Scope
/** /**
* Test search queries * Test search queries
*/ */
$function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', array_merge([ $function = $this->client->call(
'content-type' => 'application/json', Client::METHOD_GET,
'x-appwrite-project' => $this->getProject()['$id'], '/functions/' . $data['functionId'] . '/deployments',
], $this->getHeaders(), [ array_merge([
'search' => $data['functionId'] 'content-type' => 'application/json',
])); 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(), [
'search' => $data['functionId']
])
);
$this->assertEquals($function['headers']['status-code'], 200); $this->assertEquals($function['headers']['status-code'], 200);
$this->assertEquals(3, $function['body']['total']); $this->assertEquals(3, $function['body']['total']);
@ -732,12 +735,16 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals($function['headers']['status-code'], 200); $this->assertEquals($function['headers']['status-code'], 200);
$this->assertCount(0, $function['body']['deployments']); $this->assertCount(0, $function['body']['deployments']);
$function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', array_merge([ $function = $this->client->call(
'content-type' => 'application/json', Client::METHOD_GET,
'x-appwrite-project' => $this->getProject()['$id'], '/functions/' . $data['functionId'] . '/deployments',
], $this->getHeaders(), [ array_merge([
'search' => 'Test' 'content-type' => 'application/json',
])); 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(), [
'search' => 'Test'
])
);
$this->assertEquals($function['headers']['status-code'], 200); $this->assertEquals($function['headers']['status-code'], 200);
$this->assertEquals(3, $function['body']['total']); $this->assertEquals(3, $function['body']['total']);
@ -745,12 +752,16 @@ class FunctionsCustomServerTest extends Scope
$this->assertCount(3, $function['body']['deployments']); $this->assertCount(3, $function['body']['deployments']);
$this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']); $this->assertEquals($function['body']['deployments'][0]['$id'], $data['deploymentId']);
$function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments', array_merge([ $function = $this->client->call(
'content-type' => 'application/json', Client::METHOD_GET,
'x-appwrite-project' => $this->getProject()['$id'], '/functions/' . $data['functionId'] . '/deployments',
], $this->getHeaders(), [ array_merge([
'search' => 'php-8.0' 'content-type' => 'application/json',
])); 'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders(), [
'search' => 'php-8.0'
])
);
$this->assertEquals($function['headers']['status-code'], 200); $this->assertEquals($function['headers']['status-code'], 200);
$this->assertEquals(3, $function['body']['total']); $this->assertEquals(3, $function['body']['total']);
@ -977,35 +988,6 @@ class FunctionsCustomServerTest extends Scope
return $data; return $data;
} }
/**
* @depends testGetExecution
*/
public function testDeleteDeployment($data): array
{
/**
* Test for SUCCESS
*/
$function = $this->client->call(Client::METHOD_DELETE, '/functions/' . $data['functionId'] . '/deployments/' . $data['deploymentId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(204, $function['headers']['status-code']);
$this->assertEmpty($function['body']);
$function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments/' . $data['deploymentId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(404, $function['headers']['status-code']);
/**
* Test for FAILURE
*/
return $data;
}
/** /**
* @depends testGetExecution * @depends testGetExecution
@ -1031,6 +1013,53 @@ class FunctionsCustomServerTest extends Scope
$this->assertEquals(404, $execution['headers']['status-code']); $this->assertEquals(404, $execution['headers']['status-code']);
$this->assertStringContainsString('Execution with the requested ID could not be found', $execution['body']['message']); $this->assertStringContainsString('Execution with the requested ID could not be found', $execution['body']['message']);
/**
* Test for FAILURE
*/
$execution = $this->client->call(Client::METHOD_POST, '/functions/' . $data['functionId'] . '/executions', array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'async' => true,
]);
$executionId = $execution['body']['$id'] ?? '';
$this->assertEquals(202, $execution['headers']['status-code']);
$execution = $this->client->call(Client::METHOD_DELETE, '/functions/' . $data['functionId'] . '/executions/' . $executionId, array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(400, $execution['headers']['status-code']);
$this->assertStringContainsString('execution_in_progress', $execution['body']['type']);
$this->assertStringContainsString('Can\'t delete ongoing execution.', $execution['body']['message']);
return $data;
}
/**
* @depends testGetExecution
*/
public function testDeleteDeployment($data): array
{
/**
* Test for SUCCESS
*/
$function = $this->client->call(Client::METHOD_DELETE, '/functions/' . $data['functionId'] . '/deployments/' . $data['deploymentId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(204, $function['headers']['status-code']);
$this->assertEmpty($function['body']);
$function = $this->client->call(Client::METHOD_GET, '/functions/' . $data['functionId'] . '/deployments/' . $data['deploymentId'], array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()));
$this->assertEquals(404, $function['headers']['status-code']);
/** /**
* Test for FAILURE * Test for FAILURE
@ -1190,10 +1219,10 @@ class FunctionsCustomServerTest extends Scope
public function provideCustomExecutions(): array public function provideCustomExecutions(): array
{ {
return [ return [
[ 'folder' => 'php-fn', 'name' => 'php-8.0', 'entrypoint' => 'index.php', 'runtimeName' => 'PHP', 'runtimeVersion' => '8.0' ], ['folder' => 'php-fn', 'name' => 'php-8.0', 'entrypoint' => 'index.php', 'runtimeName' => 'PHP', 'runtimeVersion' => '8.0'],
[ 'folder' => 'node', 'name' => 'node-18.0', 'entrypoint' => 'index.js', 'runtimeName' => 'Node.js', 'runtimeVersion' => '18.0' ], ['folder' => 'node', 'name' => 'node-18.0', 'entrypoint' => 'index.js', 'runtimeName' => 'Node.js', 'runtimeVersion' => '18.0'],
[ 'folder' => 'python', 'name' => 'python-3.9', 'entrypoint' => 'main.py', 'runtimeName' => 'Python', 'runtimeVersion' => '3.9' ], ['folder' => 'python', 'name' => 'python-3.9', 'entrypoint' => 'main.py', 'runtimeName' => 'Python', 'runtimeVersion' => '3.9'],
[ 'folder' => 'ruby', 'name' => 'ruby-3.1', 'entrypoint' => 'main.rb', 'runtimeName' => 'Ruby', 'runtimeVersion' => '3.1' ], ['folder' => 'ruby', 'name' => 'ruby-3.1', 'entrypoint' => 'main.rb', 'runtimeName' => 'Ruby', 'runtimeVersion' => '3.1'],
// Swift and Dart disabled as it's very slow. // Swift and Dart disabled as it's very slow.
// [ 'folder' => 'dart', 'name' => 'dart-2.15', 'entrypoint' => 'main.dart', 'runtimeName' => 'Dart', 'runtimeVersion' => '2.15' ], // [ 'folder' => 'dart', 'name' => 'dart-2.15', 'entrypoint' => 'main.dart', 'runtimeName' => 'Dart', 'runtimeVersion' => '2.15' ],
// [ 'folder' => 'swift', 'name' => 'swift-5.5', 'entrypoint' => 'index.swift', 'runtimeName' => 'Swift', 'runtimeVersion' => '5.5' ], // [ 'folder' => 'swift', 'name' => 'swift-5.5', 'entrypoint' => 'index.swift', 'runtimeName' => 'Swift', 'runtimeVersion' => '5.5' ],
@ -1206,7 +1235,7 @@ class FunctionsCustomServerTest extends Scope
* @param string $entrypoint * @param string $entrypoint
* *
* @dataProvider provideCustomExecutions * @dataProvider provideCustomExecutions
* @depends testTimeout * @depends testTimeout
*/ */
public function testCreateCustomExecution(string $folder, string $name, string $entrypoint, string $runtimeName, string $runtimeVersion) public function testCreateCustomExecution(string $folder, string $name, string $entrypoint, string $runtimeName, string $runtimeVersion)
{ {