Skip to content

Commit 800424b

Browse files
author
Dmitry Balabanov
authored
fix(logger): enable sequential invocation in e2e test (#658)
* fix(logger): add invocation mode in e2e tests * fix(logger): enable cold start e2e test
1 parent f38a9fa commit 800424b

File tree

2 files changed

+25
-14
lines changed

2 files changed

+25
-14
lines changed

Diff for: packages/logger/tests/e2e/basicFeatures.middy.test.ts

+6-7
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe(`logger E2E tests basic functionalities (middy) for runtime: ${runtime}
7272
logGroupName = outputs[STACK_OUTPUT_LOG_GROUP];
7373

7474
// Invoke the function twice (one for cold start, another for warm start)
75-
invocationLogs = await invokeFunction(functionName, 2);
75+
invocationLogs = await invokeFunction(functionName, 2, 'SEQUENTIAL');
7676

7777
console.log('logGroupName', logGroupName);
7878

@@ -103,12 +103,11 @@ describe(`logger E2E tests basic functionalities (middy) for runtime: ${runtime}
103103
for (const message of coldStartLogMessages) {
104104
expect(message).toContain(`"cold_start":true`);
105105
}
106-
// TODO: There is an issue with the way in which functions are invoked that always forces a cold start. (#590)
107-
// Link to tracked issue: https://github.com/awslabs/aws-lambda-powertools-typescript/issues/590
108-
// const normalLogMessages = invocationLogs[1].getFunctionLogs(LEVEL.INFO);
109-
// for (const message of normalLogMessages) {
110-
// expect(message).not.toContain(`"cold_start":true`);
111-
// }
106+
107+
const normalLogMessages = invocationLogs[1].getFunctionLogs(LEVEL.INFO);
108+
for (const message of normalLogMessages) {
109+
expect(message).not.toContain(`"cold_start":true`);
110+
}
112111
}, TEST_CASE_TIMEOUT);
113112
});
114113

Diff for: packages/logger/tests/helpers/e2eUtils.ts

+19-7
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,10 @@ export const deployStack = async (stackArtifact: CloudFormationStackArtifact ):
6868
return result.outputs;
6969
};
7070

71-
export const invokeFunction = async (functionName: string, times: number = 1): Promise<InvocationLogs[]> => {
71+
export const invokeFunction = async (functionName: string, times: number = 1, invocationMode: 'PARALLEL' | 'SEQUENTIAL' = 'PARALLEL'): Promise<InvocationLogs[]> => {
7272
const invocationLogs: InvocationLogs[] = [];
73-
const promises = [];
74-
75-
for (let i = 0; i < times; i++) {
73+
74+
const promiseFactory = () : Promise<void> => {
7675
const invokePromise = lambdaClient
7776
.invoke({
7877
FunctionName: functionName,
@@ -86,9 +85,15 @@ export const invokeFunction = async (functionName: string, times: number = 1): P
8685
throw new Error('No LogResult field returned in the response of Lambda invocation. This should not happen.');
8786
}
8887
});
89-
promises.push(invokePromise);
90-
}
91-
await Promise.all(promises);
88+
89+
return invokePromise;
90+
};
91+
92+
const promiseFactories = Array.from({ length: times }, () => promiseFactory );
93+
const invocation = invocationMode == 'PARALLEL'
94+
? Promise.all(promiseFactories.map(factory => factory()))
95+
: chainPromises(promiseFactories);
96+
await invocation;
9297

9398
return invocationLogs;
9499
};
@@ -106,3 +111,10 @@ export const destroyStack = async (app: App, stack: Stack): Promise<void> => {
106111
quiet: true,
107112
});
108113
};
114+
115+
const chainPromises = async (promiseFactories: (() => Promise<void>)[]) : Promise<void> => {
116+
let chain = Promise.resolve();
117+
promiseFactories.forEach(factory => chain = chain.then(factory));
118+
119+
return chain;
120+
};

0 commit comments

Comments
 (0)