Skip to content

Commit e5630d4

Browse files
authored
chore(tests): change timeout reporting in idempotency e2e tests (#2074)
1 parent 921e7d0 commit e5630d4

File tree

5 files changed

+34
-14
lines changed

5 files changed

+34
-14
lines changed

packages/idempotency/tests/e2e/idempotentDecorator.test.FunctionCode.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ class DefaultLambda implements LambdaInterface {
8080
): Promise<string> {
8181
logger.addContext(context);
8282

83-
await new Promise((resolve) => setTimeout(resolve, 1500));
83+
await new Promise((resolve) =>
84+
setTimeout(resolve, context.getRemainingTimeInMillis())
85+
);
8486

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

packages/idempotency/tests/e2e/idempotentDecorator.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ describe('Idempotency e2e test decorator, default settings', () => {
7474
function: {
7575
entry: lambdaFunctionCodeFilePath,
7676
handler: 'handlerTimeout',
77-
timeout: Duration.seconds(2),
77+
timeout: Duration.seconds(3),
78+
memorySize: 512,
7879
},
7980
},
8081
{
@@ -284,10 +285,11 @@ describe('Idempotency e2e test decorator, default settings', () => {
284285
});
285286
expect(idempotencyRecord.Items?.[0].status).toEqual('COMPLETED');
286287

287-
// During the first invocation the handler should be called, so the logs should contain 1 log
288-
expect(functionLogs[0]).toHaveLength(2);
289-
expect(functionLogs[0][0]).toContain('Task timed out after');
288+
// 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
289+
expect(functionLogs[0]).toHaveLength(0);
290+
expect(logs[0].getReportLog()).toMatch(/Status: timeout$/);
290291

292+
// During the second invocation the handler should be called and complete, so the logs should contain 1 log
291293
expect(functionLogs[1]).toHaveLength(1);
292294
expect(TestInvocationLogs.parseFunctionLog(functionLogs[1][0])).toEqual(
293295
expect.objectContaining({

packages/idempotency/tests/e2e/makeHandlerIdempotent.test.FunctionCode.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ export const handlerTimeout = middy(
6565
logger.addContext(context);
6666

6767
if (event.invocation === 0) {
68-
await new Promise((resolve) => setTimeout(resolve, 4000));
68+
await new Promise((resolve) => {
69+
setTimeout(resolve, context.getRemainingTimeInMillis());
70+
});
6971
}
70-
71-
logger.info('Processed event', {
72-
details: event.foo,
73-
});
72+
logger.info('Processed event', { details: event.foo });
7473

7574
return {
7675
foo: event.foo,

packages/idempotency/tests/e2e/makeHandlerIdempotent.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ describe(`Idempotency E2E tests, middy middleware usage`, () => {
7474
function: {
7575
entry: lambdaFunctionCodeFilePath,
7676
handler: 'handlerTimeout',
77-
timeout: Duration.seconds(2),
77+
timeout: Duration.seconds(3),
78+
memorySize: 512,
7879
},
7980
},
8081
{
@@ -263,9 +264,9 @@ describe(`Idempotency E2E tests, middy middleware usage`, () => {
263264
});
264265
expect(idempotencyRecords.Items?.[0].status).toEqual('COMPLETED');
265266

266-
// During the first invocation the function should timeout so the logs should contain 2 logs
267-
expect(functionLogs[0]).toHaveLength(2);
268-
expect(functionLogs[0][0]).toContain('Task timed out after');
267+
// 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
268+
expect(functionLogs[0]).toHaveLength(0);
269+
expect(logs[0].getReportLog()).toMatch(/Status: timeout$/);
269270
// During the second invocation the handler should be called and complete, so the logs should
270271
// contain 1 log
271272
expect(functionLogs[1]).toHaveLength(1);

packages/testing/src/TestInvocationLogs.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ class TestInvocationLogs {
105105
return filteredLogs;
106106
}
107107

108+
/**
109+
* Return the log that contains the report of the function `REPORT RequestId`
110+
*/
111+
public getReportLog(): string {
112+
const endLogIndex = TestInvocationLogs.getReportLogIndex(this.logs);
113+
114+
return this.logs[endLogIndex];
115+
}
116+
117+
/**
118+
* The index of the log that contains the report of the function `REPORT RequestId`
119+
*/
120+
public static getReportLogIndex(logs: string[]): number {
121+
return logs.findIndex((log) => log.startsWith('REPORT RequestId'));
122+
}
123+
108124
public static getStartLogIndex(logs: string[]): number {
109125
return logs.findIndex((log) => log.startsWith('START RequestId'));
110126
}

0 commit comments

Comments
 (0)