Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,8 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st
'INERNAL_EXECUTOR_HOSTNAME' => System::getHostname()
]);

$coldStartTime = 0;

// Prepare runtime
if (!$activeRuntimes->exists($activeRuntimeId)) {
if (empty($image) || empty($source) || empty($entrypoint)) {
Expand Down Expand Up @@ -602,6 +604,10 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st
$body = \json_decode($error, true);
throw new Exception('An internal curl error has occurred while starting runtime! Error Msg: ' . ($body['message'] ?? $error), 500);
}

$body = \json_decode($executorResponse, true);

$coldStartTime = \floatval($body['duration']);
break;
}

Expand Down Expand Up @@ -745,7 +751,7 @@ function (string $runtimeId, string $payload, array $variables, int $timeout, st
'response' => \mb_strcut($res, 0, 1000000), // Limit to 1MB
'stdout' => \mb_strcut($stdout, 0, 1000000), // Limit to 1MB
'stderr' => \mb_strcut($stderr, 0, 1000000), // Limit to 1MB
'duration' => $executionTime,
'duration' => $executionTime + $coldStartTime,
];

// Update swoole table
Expand Down
5 changes: 3 additions & 2 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ public function testExecute(array $data): void
{
// TODO: @Meldiron test timeout execution. Timeout build too?

/** Execute on running runtime */
$params = [
'runtimeId' => 'test-exec',
'source' => $data['path'],
Expand All @@ -171,7 +170,7 @@ public function testExecute(array $data): void
$this->assertLessThan(0.5, $response['body']['duration']);
$this->assertEquals('{"payload":"","variable":"","unicode":"Unicode magic: êä"}', $response['body']['response']);

/** Execute witn data and variables */
/** Execute on cold-started runtime */
$response = $this->client->call(Client::METHOD_POST, '/runtimes/test-exec/execution', [], [
'payload' => 'test payload',
'variables' => [
Expand All @@ -194,6 +193,8 @@ public function testExecute(array $data): void
]);

$this->assertEquals(200, $response['headers']['status-code']);
$this->assertLessThan(10, $response['body']['duration']);
$this->assertGreaterThan(0.5, $response['body']['duration']);

/** Delete runtime */
$response = $this->client->call(Client::METHOD_DELETE, '/runtimes/test-exec-coldstart', [], []);
Expand Down