From f407598f266551a794c6c541f3fa78f93eded58f Mon Sep 17 00:00:00 2001 From: Christophe Jelger Date: Mon, 26 Aug 2019 10:02:16 +0200 Subject: [PATCH 1/2] Remove default implicit configuration that sets the concurrency to 1 #183 - remove implicit configurtion values for memory, concurrency, and timeout --- compile/functions/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/compile/functions/index.js b/compile/functions/index.js index a68b692..7d6b87b 100644 --- a/compile/functions/index.js +++ b/compile/functions/index.js @@ -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) { From 6fdf39fd3376f10cf97ca42232b1d7c95ac0d717 Mon Sep 17 00:00:00 2001 From: Christophe Jelger Date: Mon, 26 Aug 2019 11:15:04 +0200 Subject: [PATCH 2/2] Remove default implicit configuration that sets the concurrency to 1 #183 - added unit tests --- compile/functions/index.js | 2 +- compile/functions/tests/index.js | 64 ++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/compile/functions/index.js b/compile/functions/index.js index 7d6b87b..7adeacb 100644 --- a/compile/functions/index.js +++ b/compile/functions/index.js @@ -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, }, diff --git a/compile/functions/tests/index.js b/compile/functions/tests/index.js index df42d2b..1e8bf08 100644 --- a/compile/functions/tests/index.js +++ b/compile/functions/tests/index.js @@ -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())