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

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

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

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

// 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 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 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,11 +65,12 @@ export const handlerTimeout = middy(
logger.addContext(context);

if (event.invocation === 0) {
await new Promise((resolve) => {
setTimeout(resolve, context.getRemainingTimeInMillis());
});
await new Promise((resolve) => setTimeout(resolve, 4000));
}
logger.info('Processed event', { details: event.foo });

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

return {
foo: event.foo,
Expand Down
9 changes: 4 additions & 5 deletions packages/idempotency/tests/e2e/makeHandlerIdempotent.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ describe(`Idempotency E2E tests, middy middleware usage`, () => {
function: {
entry: lambdaFunctionCodeFilePath,
handler: 'handlerTimeout',
timeout: Duration.seconds(3),
memorySize: 512,
timeout: Duration.seconds(2),
},
},
{
Expand Down Expand Up @@ -264,9 +263,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 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 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 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: 0 additions & 16 deletions packages/testing/src/TestInvocationLogs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,6 @@ 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