From 4ef42c9cf87f3306b56e003977d9a584e822080c Mon Sep 17 00:00:00 2001 From: Khushboo Verma <43381712+vermakhushboo@users.noreply.github.com> Date: Wed, 3 Jul 2024 18:05:08 +0530 Subject: [PATCH] Fix execution duration and add test --- src/Executor/Executor.php | 4 ++-- tests/e2e/Services/Functions/FunctionsCustomClientTest.php | 4 ++++ tests/e2e/Services/Functions/FunctionsCustomServerTest.php | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Executor/Executor.php b/src/Executor/Executor.php index 34cdae38d2..29ed756932 100644 --- a/src/Executor/Executor.php +++ b/src/Executor/Executor.php @@ -225,8 +225,8 @@ class Executor $response['body']['headers'] = \json_decode($response['body']['headers'] ?? '{}', true); $response['body']['statusCode'] = \intval($response['body']['statusCode'] ?? 500); - $response['body']['duration'] = \intval($response['body']['duration'] ?? 0); - $response['body']['startTime'] = \intval($response['body']['startTime'] ?? \microtime(true)); + $response['body']['duration'] = \floatval($response['body']['duration'] ?? 0); + $response['body']['startTime'] = \floatval($response['body']['startTime'] ?? \microtime(true)); return $response['body']; } diff --git a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php index 9a42d54434..5ac7a73c78 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomClientTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomClientTest.php @@ -182,6 +182,7 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals($executions['body']['executions'][1]['responseStatusCode'], 200); $this->assertEquals($executions['body']['executions'][1]['responseBody'], ''); $this->assertEquals($executions['body']['executions'][1]['logs'], ''); + $this->assertGreaterThan(0, $executions['body']['executions'][1]['duration']); // Cleanup : Delete function $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $function['body']['$id'], [ @@ -285,6 +286,7 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals(202, $execution['headers']['status-code']); $this->assertEquals('scheduled', $execution['body']['status']); + $this->assertGreaterThan(0, $execution['body']['duration']); $executionId = $execution['body']['$id']; @@ -301,6 +303,7 @@ class FunctionsCustomClientTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals('/custom', $execution['body']['requestPath']); $this->assertEquals('GET', $execution['body']['requestMethod']); + $this->assertGreaterThan(0, $execution['body']['duration']); /* Test for FAILURE */ @@ -438,6 +441,7 @@ class FunctionsCustomClientTest extends Scope $output = json_decode($execution['body']['responseBody'], true); $this->assertEquals(201, $execution['headers']['status-code']); $this->assertEquals(200, $execution['body']['responseStatusCode']); + $this->assertGreaterThan(0, $execution['body']['duration']); $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals($functionId, $output['APPWRITE_FUNCTION_ID']); $this->assertEquals('Test', $output['APPWRITE_FUNCTION_NAME']); diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index 00ba91aec9..c9f9e4443f 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1693,6 +1693,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertNotEmpty($execution['body']['responseBody']); + $this->assertGreaterThan(0, $execution['body']['duration']); // Cleanup : Delete function $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [ @@ -1781,6 +1782,7 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals('completed', $execution['body']['status']); $this->assertEquals(200, $execution['body']['responseStatusCode']); $this->assertEquals($cookie, $execution['body']['responseBody']); + $this->assertGreaterThan(0, $execution['body']['duration']); // Cleanup : Delete function $response = $this->client->call(Client::METHOD_DELETE, '/functions/' . $functionId, [