Skip to content

chore(tests): change timeout reporting in idempotency e2e tests #2074

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 16, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ class DefaultLambda implements LambdaInterface {
): Promise<string> {
logger.addContext(context);

await new Promise((resolve) => setTimeout(resolve, 1500));
await new Promise((resolve) =>
setTimeout(resolve, context.getRemainingTimeInMillis())
);

logger.info('Processed event', { details: event.foo });

Expand Down
10 changes: 6 additions & 4 deletions packages/idempotency/tests/e2e/idempotentDecorator.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
function: {
entry: lambdaFunctionCodeFilePath,
handler: 'handlerTimeout',
timeout: Duration.seconds(2),
timeout: Duration.seconds(3),
memorySize: 512,
},
},
{
Expand Down Expand Up @@ -284,10 +285,11 @@ describe('Idempotency e2e test decorator, default settings', () => {
});
expect(idempotencyRecord.Items?.[0].status).toEqual('COMPLETED');

// During the first invocation the handler should be called, so the logs should contain 1 log
expect(functionLogs[0]).toHaveLength(2);
expect(functionLogs[0][0]).toContain('Task timed out after');
// During the first invocation the function should timeout so the logs should not contain any log and the report log should contain a timeout message
expect(functionLogs[0]).toHaveLength(0);
expect(logs[0].getReportLog()).toMatch(/Status: timeout$/);

// During the second invocation the handler should be called and complete, so the logs should contain 1 log
expect(functionLogs[1]).toHaveLength(1);
expect(TestInvocationLogs.parseFunctionLog(functionLogs[1][0])).toEqual(
expect.objectContaining({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ export const handlerTimeout = middy(
logger.addContext(context);

if (event.invocation === 0) {
await new Promise((resolve) => setTimeout(resolve, 4000));
await new Promise((resolve) => {
setTimeout(resolve, context.getRemainingTimeInMillis());
});
}

logger.info('Processed event', {
details: event.foo,
});
logger.info('Processed event', { details: event.foo });

return {
foo: event.foo,
Expand Down
9 changes: 5 additions & 4 deletions packages/idempotency/tests/e2e/makeHandlerIdempotent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ describe(`Idempotency E2E tests, middy middleware usage`, () => {
function: {
entry: lambdaFunctionCodeFilePath,
handler: 'handlerTimeout',
timeout: Duration.seconds(2),
timeout: Duration.seconds(3),
memorySize: 512,
},
},
{
Expand Down Expand Up @@ -263,9 +264,9 @@ describe(`Idempotency E2E tests, middy middleware usage`, () => {
});
expect(idempotencyRecords.Items?.[0].status).toEqual('COMPLETED');

// During the first invocation the function should timeout so the logs should contain 2 logs
expect(functionLogs[0]).toHaveLength(2);
expect(functionLogs[0][0]).toContain('Task timed out after');
// During the first invocation the function should timeout so the logs should not contain any log and the report log should contain a timeout message
expect(functionLogs[0]).toHaveLength(0);
expect(logs[0].getReportLog()).toMatch(/Status: timeout$/);
// During the second invocation the handler should be called and complete, so the logs should
// contain 1 log
expect(functionLogs[1]).toHaveLength(1);
Expand Down
16 changes: 16 additions & 0 deletions packages/testing/src/TestInvocationLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,22 @@ class TestInvocationLogs {
return filteredLogs;
}

/**
* Return the log that contains the report of the function `REPORT RequestId`
*/
public getReportLog(): string {
const endLogIndex = TestInvocationLogs.getReportLogIndex(this.logs);

return this.logs[endLogIndex];
}

/**
* The index of the log that contains the report of the function `REPORT RequestId`
*/
public static getReportLogIndex(logs: string[]): number {
return logs.findIndex((log) => log.startsWith('REPORT RequestId'));
}

public static getStartLogIndex(logs: string[]): number {
return logs.findIndex((log) => log.startsWith('START RequestId'));
}
Expand Down