Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vermakhushboo committed Jun 26, 2024
1 parent 245dd99 commit 2f24f89
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
14 changes: 10 additions & 4 deletions app/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr
if ($logDevice->exists($logFile)) {
if ($logDevice->getFileSize($logFile) > MAX_TO_READ) {
$maxToRead = MAX_TO_READ;
$logs = $logDevice->read($logFile, 0, $maxToRead - 50);
$logs = $logDevice->read($logFile, 0, $maxToRead);
$logs .= "\nLog file has been truncated to 5 MBs.";
} else {
$logs = $logDevice->read($logFile);
Expand All @@ -1062,7 +1062,7 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr
if ($logDevice->exists($errorFile)) {
if ($logDevice->getFileSize($errorFile) > MAX_TO_READ) {
$maxToRead = MAX_TO_READ;
$errors = $logDevice->read($errorFile, 0, $maxToRead - 50);
$errors = $logDevice->read($errorFile, 0, $maxToRead);
$errors .= "\nError file has been truncated to 5 MBs.";
} else {
$errors = $logDevice->read($errorFile);
Expand Down Expand Up @@ -1163,12 +1163,18 @@ function (string $runtimeId, ?string $payload, string $path, string $method, arr
$duration = $endTime - $startTime;

$header['x-open-runtimes-body-encoding'] = 'original';

if ($version === 'v2') {
$logs = \mb_strcut($logs, 0, MAX_TO_READ);
$errors = \mb_strcut($errors, 0, MAX_TO_READ);
}

$execution = [
'statusCode' => $statusCode,
'headers' => $headers,
'body' => $body,
'logs' => \mb_strcut($logs, 0, MAX_TO_READ),
'errors' => \mb_strcut($errors, 0, MAX_TO_READ),
'logs' => $logs,
'errors' => $errors,
'duration' => $duration,
'startTime' => $startTime,
];
Expand Down
7 changes: 4 additions & 3 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public function provideScenarios(): array
'assertions' => function ($response) {
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals("OK", $response['body']['body']);
$this->assertLessThanOrEqual(5 * 1024 * 1024, strlen($response['body']['logs']));
$this->assertEquals(1 * 1024 * 1024, strlen($response['body']['logs']));
$this->assertLessThanOrEqual(5 * 1024 * 1024, strlen($response['body']['errors']));
},
'body' => function () {
Expand All @@ -355,7 +355,7 @@ public function provideScenarios(): array
'assertions' => function ($response) {
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals("OK", $response['body']['body']);
$this->assertLessThanOrEqual(5 * 1024 * 1024, strlen($response['body']['logs']));
$this->assertEquals(5 * 1024 * 1024, strlen($response['body']['logs']));
$this->assertLessThanOrEqual(5 * 1024 * 1024, strlen($response['body']['errors']));
},
'body' => function () {
Expand All @@ -372,7 +372,8 @@ public function provideScenarios(): array
'assertions' => function ($response) {
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals("OK", $response['body']['body']);
$this->assertLessThanOrEqual(5 * 1024 * 1024, strlen($response['body']['logs']));
$this->assertGreaterThanOrEqual(5 * 1024 * 1024, strlen($response['body']['logs']));
$this->assertLessThan(6 * 1024 * 1024, strlen($response['body']['logs']));
$this->assertLessThanOrEqual(5 * 1024 * 1024, strlen($response['body']['errors']));
$this->assertStringContainsString('Log file has been truncated to 5 MBs', $response['body']['logs']);
},
Expand Down
2 changes: 1 addition & 1 deletion tests/resources/functions/node-logs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = async (context) => {
let log1kb = '';

for(let i = 0; i < 1024; i++) {
for(let i = 0; i < 1023; i++) { // context.log adds a new line character
log1kb += "A";
}

Expand Down

0 comments on commit 2f24f89

Please sign in to comment.