You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by al...@apache.org on 2020/04/14 07:53:39 UTC
[openwhisk-wskdebug] 09/09: performance: do not delete backup and
helper actions on exit by default
This is an automated email from the ASF dual-hosted git repository.
alexkli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git
commit fa5b0b48fa7e3bad922b94ee80e5ff6f70800ded
Author: Alexander Klimetschek <ak...@adobe.com>
AuthorDate: Tue Apr 14 00:41:38 2020 -0700
performance: do not delete backup and helper actions on exit by default
add --cleanup option to do so and warn user about the behavior
---
index.js | 5 ++
src/agentmgr.js | 25 +++++++---
test/agentmgr.test.js | 127 ++++++++++++++++++++++++++++++++++++++------------
test/ngrok.test.js | 1 -
test/test.js | 1 -
5 files changed, 121 insertions(+), 38 deletions(-)
diff --git a/index.js b/index.js
index 18d13ff..6724d6a 100644
--- a/index.js
+++ b/index.js
@@ -192,6 +192,11 @@ function yargsOptions(yargs) {
group: "Agent options:",
describe: "Ngrok region to use. Defaults to 'us'."
});
+ yargs.option("cleanup", {
+ type: "boolean",
+ group: "Agent options:",
+ describe: "Remove backup and any helper actions on exit. Makes shutdown slower."
+ });
// nodejs options
yargs.option("inspect", {
diff --git a/src/agentmgr.js b/src/agentmgr.js
index e12e9f7..3275b72 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -199,7 +199,7 @@ class AgentMgr {
agentCode = await this.getConcurrencyAgent();
} else {
- console.log("This OpenWhisk does not support action concurrency. Debugging will be a bit slower. Consider using '--ngrok' which might be a faster option.");
+ console.warn("This OpenWhisk does not support action concurrency. Debugging will be a bit slower. Consider using '--ngrok' which might be a faster option.");
agentName = "polling activation db";
agentCode = await this.getPollingActivationDbAgent();
@@ -454,13 +454,24 @@ class AgentMgr {
});
debug("restore: restored original action");
- // remove the backup
- await this.wsk.actions.delete(copy);
- debug("restore: deleted backup copy");
+ if (this.argv.cleanup) {
+ console.log("Removing extra actions due to --cleanup...");
+ // remove the backup
+ await this.wsk.actions.delete(copy);
+ debug("restore: deleted backup copy");
- // remove any helpers if they exist
- await deleteActionIfExists(this.wsk, `${this.actionName}_wskdebug_invoked`);
- await deleteActionIfExists(this.wsk, `${this.actionName}_wskdebug_completed`);
+ // remove any helpers if they exist
+ await deleteActionIfExists(this.wsk, `${this.actionName}_wskdebug_invoked`);
+ await deleteActionIfExists(this.wsk, `${this.actionName}_wskdebug_completed`);
+
+ } else {
+ console.warn(`Skipping removal of extra actions. Remove using --cleanup if desired:`);
+ console.warn(`- ${copy}`);
+ if (!this.concurrency) {
+ console.warn(`- ${this.actionName}_wskdebug_invoked`);
+ console.warn(`- ${this.actionName}_wskdebug_completed`);
+ }
+ }
return original;
diff --git a/test/agentmgr.test.js b/test/agentmgr.test.js
index b7fae8d..77a2d66 100644
--- a/test/agentmgr.test.js
+++ b/test/agentmgr.test.js
@@ -39,10 +39,7 @@ describe('agentmgr', function() {
test.afterEach();
});
- it("should use non-concurrrent agent if openwhisk does not support concurrency", async function() {
- const action = "myaction";
- const code = `const main = () => ({ msg: 'WRONG' });`;
-
+ function mockActivationDbAgent(action, code) {
test.mockAction(action, code);
test.mockCreateBackupAction(action);
@@ -78,7 +75,6 @@ describe('agentmgr', function() {
.matchHeader("authorization", test.openwhiskApiAuthHeader())
.reply(200, test.nodejsActionDescription(action));
-
// invocation
test.openwhiskNock()
.get(`${test.openwhiskApiUrl()}/activations`)
@@ -123,31 +119,17 @@ describe('agentmgr', function() {
// shutdown/restore process
test.mockRestoreAction(action, code);
- test.mockRemoveBackupAction(action);
- test.openwhiskNock()
- .get(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_invoked?code=false`)
- .matchHeader("authorization", test.openwhiskApiAuthHeader())
- .reply(200, {});
- test.openwhiskNock()
- .delete(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_invoked`)
- .matchHeader("authorization", test.openwhiskApiAuthHeader())
- .reply(200, {});
- test.openwhiskNock()
- .get(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_completed?code=false`)
- .matchHeader("authorization", test.openwhiskApiAuthHeader())
- .reply(200, {});
- test.openwhiskNock()
- .delete(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_completed`)
- .matchHeader("authorization", test.openwhiskApiAuthHeader())
- .reply(200, {});
+ }
+ it("should use non-concurrent agent if openwhisk does not support concurrency", async function() {
+ const action = "myaction";
+ const code = `const main = () => ({ msg: 'CORRECT' });`;
+
+ mockActivationDbAgent(action, code);
- process.chdir("test/nodejs/plain-flat");
const argv = {
port: test.port,
- action: "myaction",
- sourcePath: `${process.cwd()}/action.js`,
- invokeParams: '{ "key": "invocationOnSourceModification" }'
+ action: "myaction"
};
const dbgr = new Debugger(argv);
@@ -212,8 +194,6 @@ describe('agentmgr', function() {
.matchHeader("authorization", test.openwhiskApiAuthHeader())
.reply(200, agentDescriptionWithoutCode);
- test.mockRemoveBackupAction(action);
-
// 4. install agent
test.openwhiskNock()
.put(
@@ -234,7 +214,6 @@ describe('agentmgr', function() {
// 6. restore
test.mockRestoreAction(action, actionCode);
- test.mockRemoveBackupAction(action);
// -----------------
@@ -242,4 +221,94 @@ describe('agentmgr', function() {
test.assertAllNocksInvoked();
});
+
+ it("should remove backup action if --cleanup is set", async function() {
+ const action = "myaction";
+ const code = `const main = () => ({ msg: 'CORRECT' });`;
+
+ test.mockActionAndInvocation(
+ action,
+ code,
+ {},
+ { msg: "CORRECT" }
+ );
+
+ test.mockRemoveBackupAction(action);
+ test.openwhiskNock()
+ .get(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_invoked?code=false`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+ test.openwhiskNock()
+ .delete(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_invoked`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+ test.openwhiskNock()
+ .get(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_completed?code=false`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+ test.openwhiskNock()
+ .delete(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_completed`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+
+ const argv = {
+ port: test.port,
+ action: "myaction",
+ cleanup: true
+ };
+
+ const dbgr = new Debugger(argv);
+ await dbgr.start();
+ dbgr.run();
+
+ // wait a bit
+ await test.sleep(500);
+
+ await dbgr.stop();
+
+ test.assertAllNocksInvoked();
+ });
+
+ it("should remove helper actions if --cleanup is set and activation db agent is used", async function() {
+ const action = "myaction";
+ const code = `const main = () => ({ msg: 'CORRECT' });`;
+
+ mockActivationDbAgent(action, code);
+
+ test.mockRemoveBackupAction(action);
+ test.openwhiskNock()
+ .get(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_invoked?code=false`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+ test.openwhiskNock()
+ .delete(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_invoked`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+ test.openwhiskNock()
+ .get(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_completed?code=false`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+ test.openwhiskNock()
+ .delete(`${test.openwhiskApiUrlActions()}/${action}_wskdebug_completed`)
+ .matchHeader("authorization", test.openwhiskApiAuthHeader())
+ .reply(200, {});
+
+ const argv = {
+ port: test.port,
+ action: "myaction",
+ cleanup: true
+ };
+
+ const dbgr = new Debugger(argv);
+ await dbgr.start();
+ dbgr.run();
+
+ // wait a bit
+ await test.sleep(500);
+
+ await dbgr.stop();
+
+ test.assertAllNocksInvoked();
+ });
+
});
diff --git a/test/ngrok.test.js b/test/ngrok.test.js
index b9485e6..88e2c4b 100644
--- a/test/ngrok.test.js
+++ b/test/ngrok.test.js
@@ -156,7 +156,6 @@ describe('ngrok', function() {
.reply(200, test.nodejsActionDescription(actionName));
test.mockRestoreAction(actionName, code);
- test.mockRemoveBackupAction(actionName);
// wskdebug myaction action.js --ngrok -p ${test.port}
const argv = {
diff --git a/test/test.js b/test/test.js
index d59e77e..d81bee1 100644
--- a/test/test.js
+++ b/test/test.js
@@ -192,7 +192,6 @@ function expectAgent(name, code, binary=false) {
// shutdown/restore process
mockRestoreAction(name, code, binary);
- mockRemoveBackupAction(name);
}
function nockActivation(name, bodyFn) {