Skip to content

Commit

Permalink
fix: Fix handling of maxInstances setting (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
holmerjohn authored Feb 27, 2020
1 parent 3229c49 commit 4ea8418
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
4 changes: 3 additions & 1 deletion package/lib/compileFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ module.exports = {
});
}

funcTemplate.properties.maxInstances = funcObject.maxInstances;
if (funcObject.maxInstances) {
funcTemplate.properties.maxInstances = funcObject.maxInstances;
}

if (!_.size(funcTemplate.properties.environmentVariables)) {
delete funcTemplate.properties.environmentVariables;
Expand Down
65 changes: 65 additions & 0 deletions package/lib/compileFunctions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -683,5 +683,70 @@ describe('CompileFunctions', () => {
).toEqual(compiledResources);
});
});

it('should not require max instances on each function configuration', () => {
googlePackage.serverless.service.functions = {
func1: {
handler: 'func1',
memorySize: 128,
runtime: 'nodejs8',
vpc: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
events: [{ http: 'foo' }],
},
func2: {
handler: 'func2',
memorySize: 128,
runtime: 'nodejs8',
maxInstances: 10,
vpc: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
events: [{ http: 'bar' }],
},
};

const compiledResources = [
{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func1',
properties: {
location: 'us-central1',
runtime: 'nodejs8',
function: 'func1',
availableMemoryMb: 128,
timeout: '60s',
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'foo',
},
labels: {},
vpcConnector: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
},
},
{
type: 'cloudfunctions.v1beta2.function',
name: 'my-service-dev-func2',
properties: {
location: 'us-central1',
runtime: 'nodejs8',
function: 'func2',
availableMemoryMb: 128,
timeout: '60s',
maxInstances: 10,
sourceArchiveUrl: 'gs://sls-my-service-dev-12345678/some-path/artifact.zip',
httpsTrigger: {
url: 'bar',
},
labels: {},
vpcConnector: 'projects/pg-us-n-app-123456/locations/us-central1/connectors/my-vpc',
},
},
];

return googlePackage.compileFunctions().then(() => {
expect(consoleLogStub.called).toEqual(true);
expect(
googlePackage.serverless.service.provider.compiledConfigurationTemplate.resources
).toEqual(compiledResources);
});
});
});
});

0 comments on commit 4ea8418

Please sign in to comment.