Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mriccia committed May 23, 2024
1 parent 940ecd8 commit 000cd74
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lambda/cleaner.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const extractDataFromInput = (event) => {
lambdaARN: event.lambdaARN,
powerValues: event.lambdaConfigurations.powerValues,
onlyColdStarts: event.onlyColdStarts,
num: parseInt(event.num, 10), // use the default in case it was not defined
num: parseInt(event.num, 10), // parse as we do in the initializer
};
};

Expand Down
4 changes: 2 additions & 2 deletions lambda/initializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ module.exports.handler = async(event, context) => {
for (let powerValue of powerValues){
const baseAlias = 'RAM' + powerValue;
if (!onlyColdStarts){
initConfigurations.push({powerValue: powerValue, alias: baseAlias, description: `${description} - ${baseAlias}`});
initConfigurations.push({powerValue: powerValue, alias: baseAlias});
} else {
for (let n of utils.range(num)){
let alias = utils.buildAliasString(baseAlias, onlyColdStarts, n);
// here we inject a custom env variable to force the creation of a new version
// here we inject a custom description to force the creation of a new version
// even if the power is the same, which will force a cold start
initConfigurations.push({powerValue: powerValue, alias: alias, description: `${description} - ${alias}`});
}
Expand Down
1 change: 1 addition & 0 deletions lambda/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ module.exports.createPowerConfiguration = async(lambdaARN, value, alias, descrip
await utils.waitForFunctionUpdate(lambdaARN);

const {Version} = await utils.publishLambdaVersion(lambdaARN);
// alias is not passed in when restoring to the original Lambda configuration
if (typeof alias === 'undefined'){
console.log('No alias defined');
return;
Expand Down
36 changes: 36 additions & 0 deletions test/unit/test-lambda.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,42 @@ describe('Lambda Functions', async() => {
});
});

it('should clean the right aliases with onlyColdStarts=false', async() => {
const cleanedAliases = [];
const expectedAliases = ['RAM128', 'RAM256', 'RAM512'];
deleteLambdaAliasStub && deleteLambdaAliasStub.restore();
deleteLambdaAliasStub = sandBox.stub(utils, 'deleteLambdaAlias')
.callsFake(async(lambdaARN, alias) => {
cleanedAliases.push(alias);
return 'OK';
});
await invokeForSuccess(handler, {
num: 10,
lambdaARN: 'arnOK',
lambdaConfigurations: {powerValues: ['128', '256', '512']},
onlyColdStarts: false,
});
expect(cleanedAliases).to.eql(expectedAliases);
});

it('should clean the right aliases with onlyColdStarts=true', async() => {
const cleanedAliases = [];
const expectedAliases = ['RAM128-0', 'RAM128-1', 'RAM256-0', 'RAM256-1', 'RAM512-0', 'RAM512-1'];
deleteLambdaAliasStub && deleteLambdaAliasStub.restore();
deleteLambdaAliasStub = sandBox.stub(utils, 'deleteLambdaAlias')
.callsFake(async(lambdaARN, alias) => {
cleanedAliases.push(alias);
return 'OK';
});
await invokeForSuccess(handler, {
num: 2,
lambdaARN: 'arnOK',
lambdaConfigurations: {powerValues: ['128', '256', '512']},
onlyColdStarts: true,
});
expect(cleanedAliases).to.eql(expectedAliases);
});

});

describe('executor', () => {
Expand Down
16 changes: 16 additions & 0 deletions test/unit/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1250,4 +1250,20 @@ describe('Lambda Utils', () => {
isPayloadInConsoleLog: false,
}));
});

describe('buildAliasString', () => {

it('should return baseAlias if onlyColdStarts=false', async() => {
const value = utils.buildAliasString('RAM128', false, 0);
expect(value).to.be('RAM128');
});
it('should only require baseAlias', async() => {
const value = utils.buildAliasString('RAM128');
expect(value).to.be('RAM128');
});
it('should append index to baseAlias if onlyColdStarts=true', async() => {
const value = utils.buildAliasString('RAM128', true, 1);
expect(value).to.be('RAM128-1');
});
});
});

0 comments on commit 000cd74

Please sign in to comment.