Skip to content

Commit 000cd74

Browse files
committed
PR feedback
1 parent 940ecd8 commit 000cd74

File tree

5 files changed

+56
-3
lines changed

5 files changed

+56
-3
lines changed

lambda/cleaner.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const extractDataFromInput = (event) => {
4646
lambdaARN: event.lambdaARN,
4747
powerValues: event.lambdaConfigurations.powerValues,
4848
onlyColdStarts: event.onlyColdStarts,
49-
num: parseInt(event.num, 10), // use the default in case it was not defined
49+
num: parseInt(event.num, 10), // parse as we do in the initializer
5050
};
5151
};
5252

lambda/initializer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ module.exports.handler = async(event, context) => {
2828
for (let powerValue of powerValues){
2929
const baseAlias = 'RAM' + powerValue;
3030
if (!onlyColdStarts){
31-
initConfigurations.push({powerValue: powerValue, alias: baseAlias, description: `${description} - ${baseAlias}`});
31+
initConfigurations.push({powerValue: powerValue, alias: baseAlias});
3232
} else {
3333
for (let n of utils.range(num)){
3434
let alias = utils.buildAliasString(baseAlias, onlyColdStarts, n);
35-
// here we inject a custom env variable to force the creation of a new version
35+
// here we inject a custom description to force the creation of a new version
3636
// even if the power is the same, which will force a cold start
3737
initConfigurations.push({powerValue: powerValue, alias: alias, description: `${description} - ${alias}`});
3838
}

lambda/utils.js

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ module.exports.createPowerConfiguration = async(lambdaARN, value, alias, descrip
110110
await utils.waitForFunctionUpdate(lambdaARN);
111111

112112
const {Version} = await utils.publishLambdaVersion(lambdaARN);
113+
// alias is not passed in when restoring to the original Lambda configuration
113114
if (typeof alias === 'undefined'){
114115
console.log('No alias defined');
115116
return;

test/unit/test-lambda.js

+36
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,42 @@ describe('Lambda Functions', async() => {
555555
});
556556
});
557557

558+
it('should clean the right aliases with onlyColdStarts=false', async() => {
559+
const cleanedAliases = [];
560+
const expectedAliases = ['RAM128', 'RAM256', 'RAM512'];
561+
deleteLambdaAliasStub && deleteLambdaAliasStub.restore();
562+
deleteLambdaAliasStub = sandBox.stub(utils, 'deleteLambdaAlias')
563+
.callsFake(async(lambdaARN, alias) => {
564+
cleanedAliases.push(alias);
565+
return 'OK';
566+
});
567+
await invokeForSuccess(handler, {
568+
num: 10,
569+
lambdaARN: 'arnOK',
570+
lambdaConfigurations: {powerValues: ['128', '256', '512']},
571+
onlyColdStarts: false,
572+
});
573+
expect(cleanedAliases).to.eql(expectedAliases);
574+
});
575+
576+
it('should clean the right aliases with onlyColdStarts=true', async() => {
577+
const cleanedAliases = [];
578+
const expectedAliases = ['RAM128-0', 'RAM128-1', 'RAM256-0', 'RAM256-1', 'RAM512-0', 'RAM512-1'];
579+
deleteLambdaAliasStub && deleteLambdaAliasStub.restore();
580+
deleteLambdaAliasStub = sandBox.stub(utils, 'deleteLambdaAlias')
581+
.callsFake(async(lambdaARN, alias) => {
582+
cleanedAliases.push(alias);
583+
return 'OK';
584+
});
585+
await invokeForSuccess(handler, {
586+
num: 2,
587+
lambdaARN: 'arnOK',
588+
lambdaConfigurations: {powerValues: ['128', '256', '512']},
589+
onlyColdStarts: true,
590+
});
591+
expect(cleanedAliases).to.eql(expectedAliases);
592+
});
593+
558594
});
559595

560596
describe('executor', () => {

test/unit/test-utils.js

+16
Original file line numberDiff line numberDiff line change
@@ -1250,4 +1250,20 @@ describe('Lambda Utils', () => {
12501250
isPayloadInConsoleLog: false,
12511251
}));
12521252
});
1253+
1254+
describe('buildAliasString', () => {
1255+
1256+
it('should return baseAlias if onlyColdStarts=false', async() => {
1257+
const value = utils.buildAliasString('RAM128', false, 0);
1258+
expect(value).to.be('RAM128');
1259+
});
1260+
it('should only require baseAlias', async() => {
1261+
const value = utils.buildAliasString('RAM128');
1262+
expect(value).to.be('RAM128');
1263+
});
1264+
it('should append index to baseAlias if onlyColdStarts=true', async() => {
1265+
const value = utils.buildAliasString('RAM128', true, 1);
1266+
expect(value).to.be('RAM128-1');
1267+
});
1268+
});
12531269
});

0 commit comments

Comments
 (0)