Merge pull request #8164 from appwrite/feat-add-schedule-function-tests
Add tests for scheduled functions
This commit is contained in:
commit
c45823a05d
2 changed files with 39 additions and 1 deletions
|
@ -61,7 +61,7 @@ class FunctionsCustomClientTest extends Scope
|
|||
'users.*.create',
|
||||
'users.*.delete',
|
||||
],
|
||||
'schedule' => '0 0 1 1 *',
|
||||
'schedule' => '* * * * *', // execute every minute
|
||||
'timeout' => 10,
|
||||
]);
|
||||
|
||||
|
@ -163,6 +163,24 @@ class FunctionsCustomClientTest extends Scope
|
|||
|
||||
$this->assertEquals(202, $execution['headers']['status-code']);
|
||||
|
||||
// Wait for the first scheduled execution to be created
|
||||
sleep(65);
|
||||
|
||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $function['body']['$id'] . '/executions', [
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'x-appwrite-key' => $this->getProject()['apiKey'],
|
||||
]);
|
||||
|
||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
||||
$this->assertCount(2, $executions['body']['executions']);
|
||||
$this->assertIsArray($executions['body']['executions']);
|
||||
$this->assertEquals($executions['body']['executions'][1]['trigger'], 'schedule');
|
||||
$this->assertEquals($executions['body']['executions'][1]['status'], 'completed');
|
||||
$this->assertEquals($executions['body']['executions'][1]['responseStatusCode'], 200);
|
||||
$this->assertEquals($executions['body']['executions'][1]['responseBody'], '');
|
||||
$this->assertEquals($executions['body']['executions'][1]['logs'], '');
|
||||
|
||||
// Cleanup : Delete function
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $function['body']['$id'], [
|
||||
'content-type' => 'application/json',
|
||||
|
|
|
@ -914,12 +914,14 @@ class FunctionsCustomServerTest extends Scope
|
|||
'runtime' => $name,
|
||||
'entrypoint' => $entrypoint,
|
||||
'events' => [],
|
||||
'schedule' => '* * * * *', // execute every minute
|
||||
'timeout' => $timeout,
|
||||
]);
|
||||
|
||||
$functionId = $function['body']['$id'] ?? '';
|
||||
|
||||
$this->assertEquals(201, $function['headers']['status-code']);
|
||||
$this->assertEquals('* * * * *', $function['body']['schedule']);
|
||||
|
||||
$deployment = $this->client->call(Client::METHOD_POST, '/functions/' . $functionId . '/deployments', array_merge([
|
||||
'content-type' => 'multipart/form-data',
|
||||
|
@ -986,6 +988,24 @@ class FunctionsCustomServerTest extends Scope
|
|||
$this->assertEquals($executions['body']['executions'][0]['logs'], '');
|
||||
$this->assertStringContainsString('timed out', $executions['body']['executions'][0]['errors']);
|
||||
|
||||
sleep(70); //wait for scheduled execution to be created and time out
|
||||
|
||||
$executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(200, $executions['headers']['status-code']);
|
||||
$this->assertCount(2, $executions['body']['executions']);
|
||||
$this->assertIsArray($executions['body']['executions']);
|
||||
$this->assertEquals($executions['body']['executions'][1]['trigger'], 'schedule');
|
||||
$this->assertEquals($executions['body']['executions'][1]['status'], 'failed');
|
||||
$this->assertEquals($executions['body']['executions'][1]['responseStatusCode'], 500);
|
||||
$this->assertLessThan(20, $executions['body']['executions'][1]['duration']);
|
||||
$this->assertEquals($executions['body']['executions'][1]['responseBody'], '');
|
||||
$this->assertEquals($executions['body']['executions'][1]['logs'], '');
|
||||
$this->assertStringContainsString('timed out', $executions['body']['executions'][1]['errors']);
|
||||
|
||||
// Cleanup : Delete function
|
||||
$response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [
|
||||
'content-type' => 'application/json',
|
||||
|
|
Loading…
Reference in a new issue