Skip to content

Commit

Permalink
Test for logs of failed executions
Browse files Browse the repository at this point in the history
  • Loading branch information
vermakhushboo committed Jun 24, 2024
1 parent 6dbb179 commit 4c44ad5
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
22 changes: 18 additions & 4 deletions tests/ExecutorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,27 @@ public function provideScenarios(): array
// $this->assertEquals(200, $response['headers']['status-code']);

// },
// ]
// ],
[
'image' => 'openruntimes/node:v4-21.0',
'entrypoint' => 'index.js',
'folder' => 'node-logs-fail',
'version' => 'v4',
'startCommand' => 'cp /tmp/code.tar.gz /mnt/code/code.tar.gz && nohup helpers/start.sh "pm2 start src/server.js --no-daemon"',
'buildCommand' => 'tar -zxf /tmp/code.tar.gz -C /mnt/code && helpers/build.sh "npm i"',
'assertions' => function ($response) {
$this->assertEquals(200, $response['headers']['status-code']);
$this->assertEquals(500, $response['body']['statusCode']);
$this->assertGreaterThan(5 * 1024, strlen($response['body']['logs']));
$this->assertGreaterThan(0, strlen($response['body']['errors']));
},
'body' => function () {
return 1;
},
],
];
}

// test streamed response
// logs for failed executions

/**
* @param string $image
* @param string $entrypoint
Expand Down
16 changes: 16 additions & 0 deletions tests/resources/functions/node-logs-fail/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = async (context) => {
let log1kb = '';

for(let i = 0; i < 1024; i++) {
log1kb += "A";
}

//1MB log
for(let i = 0; i < 1024 * (+context.req.bodyText); i++) {
context.log(log1kb);
}

throw new Error('This is an error message');

return context.res.send('OK');
}
12 changes: 12 additions & 0 deletions tests/resources/functions/node-logs-fail/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "logs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}

0 comments on commit 4c44ad5

Please sign in to comment.