Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #184 from cjelger/Issue#183
Browse files Browse the repository at this point in the history
Remove default implicit configuration that sets the concurrency to 1 …
  • Loading branch information
jthomas authored Aug 28, 2019
2 parents 447d3fb + 6fdf39f commit ab66f1e
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
8 changes: 4 additions & 4 deletions compile/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class OpenWhiskCompileFunctions {
}

calculateMemorySize(functionObject) {
return functionObject.memory || this.serverless.service.provider.memory || 256;
return functionObject.memory || this.serverless.service.provider.memory;
}

calculateConcurrency(functionObject) {
return functionObject.concurrency || this.serverless.service.provider.concurrency || 1;
return functionObject.concurrency || this.serverless.service.provider.concurrency;
}

calculateTimeout(functionObject) {
return functionObject.timeout || this.serverless.service.provider.timeout || 60;
return functionObject.timeout || this.serverless.service.provider.timeout;
}

calculateOverwrite(functionObject) {
Expand All @@ -82,7 +82,7 @@ class OpenWhiskCompileFunctions {
action: {
exec: params.Exec,
limits: {
timeout: params.Timeout * 1000,
timeout: params.Timeout ? (params.Timeout * 1000) : undefined,
memory: params.MemorySize,
concurrency: params.Concurrency,
},
Expand Down
64 changes: 64 additions & 0 deletions compile/functions/tests/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,70 @@ describe('OpenWhiskCompileFunctions', () => {
});

describe('#compileFunctions()', () => {
it('should create action function with parsed parameters', () => {
let functionObject = {
handler: "foo.js",
name: "name",
namespace: "namespace",
overwrite: "overwrite",
memory: 123,
concurrency: 456,
timeout: 789,
parameters: {
hello: "world",
foo: "bar"
},
annotations: {
hello: "world",
foo: "bar"
}
};

openwhiskCompileFunctions.serverless.service.getAllFunctions = () => ['service_name'];
openwhiskCompileFunctions.serverless.service.getFunction = () => functionObject;
sandbox.stub(openwhiskCompileFunctions, 'runtimes', {
exec: () => Promise.resolve()
});

return openwhiskCompileFunctions.compileFunctions().then(functionActions => {
let functionAction = functionActions[0];
expect(functionAction.actionName).to.be.equal(functionObject.name);
expect(functionAction.namespace).to.be.equal(functionObject.namespace);
expect(functionAction.overwrite).to.be.equal(functionObject.overwrite);
expect(functionAction.action.limits.memory).to.be.equal(functionObject.memory);
expect(functionAction.action.limits.concurrency).to.be.equal(functionObject.concurrency);
expect(functionAction.action.limits.timeout).to.be.equal(functionObject.timeout * 1000);

let paramsAndAnnotations = [
{ key: 'hello', value: 'world' },
{ key: 'foo', value: 'bar' }
];
expect(functionAction.action.parameters).to.deep.equal(paramsAndAnnotations);
expect(functionAction.action.annotations).to.deep.equal(paramsAndAnnotations);
});
});

it('should not add implicit limits parameters', () => {
let functionObject = {
handler: "foo.js",
name: "name"
};

openwhiskCompileFunctions.serverless.service.getAllFunctions = () => ['service_name'];
openwhiskCompileFunctions.serverless.service.getFunction = () => functionObject;
sandbox.stub(openwhiskCompileFunctions, 'runtimes', {
exec: () => Promise.resolve()
});

return openwhiskCompileFunctions.compileFunctions().then(functionActions => {
let functionAction = functionActions[0];
expect(functionAction.actionName).to.be.equal(functionObject.name);
expect(functionAction.action.limits.memory).to.be.undefined;
expect(functionAction.action.limits.concurrency).to.be.undefined;
expect(functionAction.action.limits.timeout).to.be.undefined;
});
});

it('should throw an error if the resource section is not available', () => {
openwhiskCompileFunctions.serverless.service.actions = null;
expect(() => openwhiskCompileFunctions.compileFunctions())
Expand Down

0 comments on commit ab66f1e

Please sign in to comment.