diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 12dd7cda59..119c1a2223 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -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', diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 1b9edc4f02..7d68f7562f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -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',