[openwhisk-wskdebug] branch refactor updated (8c6a120 -> b8d3b3e)

2020-03-31 Thread alexkli
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a change to branch refactor
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git.


from 8c6a120  quick fix for ngrok agent requiring access to invoker
 add b8d3b3e  fix duplicated shutdown() issue on CTRL+C

No new revisions were added by this update.

Summary of changes:
 src/agentmgr.js |  2 --
 src/debugger.js | 11 +--
 2 files changed, 9 insertions(+), 4 deletions(-)



[openwhisk-wskdebug] branch concurrency-not-supported created (now c24b163)

2020-03-31 Thread alexkli
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a change to branch concurrency-not-supported
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git.


  at c24b163  Concurrency error when using wskdebug with IBM Cloud 
Functions #7

This branch includes the following new commits:

 new c24b163  Concurrency error when using wskdebug with IBM Cloud 
Functions #7

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[openwhisk-wskdebug] 01/01: Concurrency error when using wskdebug with IBM Cloud Functions #7

2020-03-31 Thread alexkli
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a commit to branch concurrency-not-supported
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git

commit c24b163a4f0158317f83a07f2afa89a9d586b4a6
Author: Alexander Klimetschek 
AuthorDate: Tue Mar 31 01:19:41 2020 -0700

Concurrency error when using wskdebug with IBM Cloud Functions #7

if concurrency > 1 is not supported, fallback to activation db agent
---
 src/agentmgr.js   |  21 ++-
 test/agentmgr.test.js | 164 ++
 test/test.js  |   5 ++
 3 files changed, 187 insertions(+), 3 deletions(-)

diff --git a/src/agentmgr.js b/src/agentmgr.js
index 8b59f28..15ea202 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -158,7 +158,7 @@ class AgentMgr {
 console.log("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.getPollingActivationRecordAgent();
+agentCode = await this.getPollingActivationDbAgent();
 }
 }
 
@@ -185,7 +185,17 @@ class AgentMgr {
 });
 }
 
-await this.pushAgent(action, agentCode, backupName);
+try {
+await this.pushAgent(action, agentCode, backupName);
+} catch (e) {
+// openwhisk does not support concurrent nodejs actions, try with 
another
+if (e.statusCode === 400 && e.error && typeof e.error.error === 
"string" && e.error.error.includes("concurrency")) {
+console.log(`The Openwhisk server does not support concurrent 
actions, using alternative agent. Consider using --ngrok for a possibly faster 
agent.`);
+this.concurrency = false;
+agentCode = await this.getPollingActivationDbAgent();
+await this.pushAgent(action, agentCode, backupName);
+}
+}
 
 if (this.argv.verbose) {
 console.log(`Agent installed.`);
@@ -259,6 +269,11 @@ class AgentMgr {
 const a = activations[0];
 if (a.response && a.response.result && 
!this.activationsSeen[a.activationId]) {
 activation = a;
+if (!activation.response.success) {
+throw {
+error: activation
+};
+}
 break;
 }
 }
@@ -389,7 +404,7 @@ class AgentMgr {
 return fs.readFileSync(`${__dirname}/../agent/agent-concurrency.js`, 
{encoding: 'utf8'});
 }
 
-async getPollingActivationRecordAgent() {
+async getPollingActivationDbAgent() {
 // this needs 2 helper actions in addition to the agent in place of 
the action
 await this.createHelperAction(`${this.actionName}_wskdebug_invoked`,   
`${__dirname}/../agent/echo.js`);
 await this.createHelperAction(`${this.actionName}_wskdebug_completed`, 
`${__dirname}/../agent/echo.js`);
diff --git a/test/agentmgr.test.js b/test/agentmgr.test.js
new file mode 100644
index 000..cf069b7
--- /dev/null
+++ b/test/agentmgr.test.js
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* eslint-env mocha */
+
+'use strict';
+
+const Debugger = require("../src/debugger");
+
+const test = require('./test');
+
+describe('agentmgr',  function() {
+this.timeout(3);
+
+before(function() {
+test.isDockerInstalled();
+});
+
+beforeEach(async function() {
+await test.beforeEach();
+});
+
+afterEach(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' });`;
+
+test.mockAction(action, code);
+
+test.mockCreateBackupAction(action);
+

[openwhisk-wskdebug] 01/01: remove node 8 in travis as we don't really support it and it keeps failing fsevents tests

2020-03-31 Thread alexkli
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a commit to branch remove-node-8
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git

commit 2cdb19c391c45897f16416fb466461b9f493d1f6
Author: Alexander Klimetschek 
AuthorDate: Tue Mar 31 01:28:09 2020 -0700

remove node 8 in travis as we don't really support it and it keeps failing 
fsevents tests
---
 .travis.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 39259be..b40fadb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,7 +17,6 @@
 
 language: node_js
 node_js:
-  - 8
   - 10
   - 12
   - 13



[openwhisk-wskdebug] branch remove-node-8 created (now 2cdb19c)

2020-03-31 Thread alexkli
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a change to branch remove-node-8
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git.


  at 2cdb19c  remove node 8 in travis as we don't really support it and it 
keeps failing fsevents tests

This branch includes the following new commits:

 new 2cdb19c  remove node 8 in travis as we don't really support it and it 
keeps failing fsevents tests

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.




[openwhisk-wskdebug] branch master updated: remove node 8 in travis as we don't really support it and it keeps failing fsevents tests (#33)

2020-03-31 Thread rabbah
This is an automated email from the ASF dual-hosted git repository.

rabbah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git


The following commit(s) were added to refs/heads/master by this push:
 new 35cbe91  remove node 8 in travis as we don't really support it and it 
keeps failing fsevents tests (#33)
35cbe91 is described below

commit 35cbe91ded991b467765bd39aa5faaec90450e34
Author: Alexander Klimetschek 
AuthorDate: Tue Mar 31 04:49:04 2020 -0700

remove node 8 in travis as we don't really support it and it keeps failing 
fsevents tests (#33)
---
 .travis.yml | 1 -
 1 file changed, 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index 39259be..b40fadb 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,7 +17,6 @@
 
 language: node_js
 node_js:
-  - 8
   - 10
   - 12
   - 13



[openwhisk-wskdebug] 03/07: guard this.* access in Debugger.shutdown()/stop()/kill()

2020-03-31 Thread alexkli
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 cd50058d8b5e946aa64e4407dc57666b0283a94c
Author: Alexander Klimetschek 
AuthorDate: Sat Mar 28 23:53:31 2020 -0700

guard this.* access in Debugger.shutdown()/stop()/kill()
---
 src/debugger.js | 20 +++-
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/src/debugger.js b/src/debugger.js
index e43c8e8..fc24b11 100644
--- a/src/debugger.js
+++ b/src/debugger.js
@@ -161,7 +161,9 @@ class Debugger {
 
 async stop() {
 this.running = false;
-this.agentMgr.stop();
+if (this.agentMgr) {
+this.agentMgr.stop();
+}
 
 if (this.runPromise) {
 // wait for the main loop to gracefully end, which will call 
shutdown()
@@ -174,7 +176,9 @@ class Debugger {
 
 async kill() {
 this.running = false;
-this.agentMgr.stop();
+if (this.agentMgr) {
+this.agentMgr.stop();
+}
 
 await this.shutdown();
 }
@@ -189,9 +193,15 @@ class Debugger {
 
 // need to shutdown everything even if some fail, hence tryCatch() for 
each
 
-await this.tryCatch(this.agentMgr.shutdown());
-await this.tryCatch(this.invoker.stop());
-await this.tryCatch(this.watcher.stop());
+if (this.agentMgr) {
+await this.tryCatch(this.agentMgr.shutdown());
+}
+if (this.invoker) {
+await this.tryCatch(this.invoker.stop());
+}
+if (this.watcher) {
+await this.tryCatch(this.watcher.stop());
+}
 
 // only log this if we started properly
 if (this.ready) {



[openwhisk-wskdebug] 02/07: add missing EOL

2020-03-31 Thread alexkli
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 7290fc63e19c81dc073c0f84b947d4943a7a3106
Author: Alexander Klimetschek 
AuthorDate: Sat Mar 28 23:51:43 2020 -0700

add missing EOL
---
 src/agentmgr.js | 2 +-
 src/ngrok.js| 2 +-
 src/watcher.js  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/agentmgr.js b/src/agentmgr.js
index cb0e5a9..3264cc1 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -502,4 +502,4 @@ class AgentMgr {
 }
 }
 
-module.exports = AgentMgr;
\ No newline at end of file
+module.exports = AgentMgr;
diff --git a/src/ngrok.js b/src/ngrok.js
index afa01d7..4551ef9 100644
--- a/src/ngrok.js
+++ b/src/ngrok.js
@@ -136,4 +136,4 @@ class NgrokAgent {
 }
 }
 
-module.exports = NgrokAgent;
\ No newline at end of file
+module.exports = NgrokAgent;
diff --git a/src/watcher.js b/src/watcher.js
index d69b554..8488ffa 100644
--- a/src/watcher.js
+++ b/src/watcher.js
@@ -120,4 +120,4 @@ class Watcher {
 }
 }
 
-module.exports = Watcher;
\ No newline at end of file
+module.exports = Watcher;



[openwhisk-wskdebug] 07/07: fix duplicated shutdown() issue on CTRL+C

2020-03-31 Thread alexkli
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 397aa85b1c1465116b9edcd0c791610c2f19fa39
Author: Alexander Klimetschek 
AuthorDate: Tue Mar 31 00:33:36 2020 -0700

fix duplicated shutdown() issue on CTRL+C
---
 src/agentmgr.js |  2 --
 src/debugger.js | 11 +--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/src/agentmgr.js b/src/agentmgr.js
index 8753f41..8b59f28 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -72,8 +72,6 @@ async function deleteActionIfExists(wsk, name) {
 }
 
 
-// TODO: test wskdebug manually
-// TODO: openwhiskSupports() into separate shared class
 class AgentMgr {
 
 constructor(argv, wsk, actionName) {
diff --git a/src/debugger.js b/src/debugger.js
index 415bde9..8cf08fb 100644
--- a/src/debugger.js
+++ b/src/debugger.js
@@ -116,6 +116,7 @@ class Debugger {
 async _run() {
 try {
 this.running = true;
+this.shuttingDown = false;
 
 // main blocking loop
 // abort if this.running is set to false
@@ -132,7 +133,6 @@ class Debugger {
 // wait for activation, run it, complete, repeat
 const activation = await 
this.agentMgr.waitForActivations();
 if (!activation) {
-// this.running = false;
 return;
 }
 
@@ -149,7 +149,6 @@ class Debugger {
 
 // pass on the local result to the agent in openwhisk
 if (!await this.agentMgr.completeActivation(id, result, 
duration)) {
-// this.running = false;
 return;
 }
 }
@@ -159,6 +158,7 @@ class Debugger {
 }
 }
 
+// normal graceful stop() initiated by a client
 async stop() {
 this.running = false;
 if (this.agentMgr) {
@@ -174,6 +174,7 @@ class Debugger {
 }
 }
 
+// fastest way to end, triggered by CTRL+C
 async kill() {
 this.running = false;
 if (this.agentMgr) {
@@ -184,6 +185,12 @@ class Debugger {
 }
 
 async shutdown() {
+// avoid duplicate shutdown on CTRL+C
+if (this.shuttingDown) {
+return;
+}
+this.shuttingDown = true;
+
 // only log this if we started properly
 if (this.ready) {
 console.log();



[openwhisk-wskdebug] 06/07: quick fix for ngrok agent requiring access to invoker

2020-03-31 Thread alexkli
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 2da4644191a176d1abe4253f880d3599876e3048
Author: Alexander Klimetschek 
AuthorDate: Mon Mar 30 22:47:58 2020 -0700

quick fix for ngrok agent requiring access to invoker
---
 src/agentmgr.js |  4 ++--
 src/agents/ngrok.js |  3 ++-
 src/debugger.js |  2 +-
 test/ngrok.test.js  | 20 
 4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/agentmgr.js b/src/agentmgr.js
index c1aa673..8753f41 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -133,7 +133,7 @@ class AgentMgr {
 return {action, agentAlreadyInstalled };
 }
 
-async installAgent(action) {
+async installAgent(action, invoker) {
 this.agentInstalled = true;
 
 let agentName;
@@ -143,7 +143,7 @@ class AgentMgr {
 if (this.argv.ngrok) {
 // user manually requested ngrok
 
-this.ngrokAgent = new NgrokAgent(this.argv);
+this.ngrokAgent = new NgrokAgent(this.argv, invoker);
 
 // agent using ngrok for forwarding
 agentName = "ngrok";
diff --git a/src/agents/ngrok.js b/src/agents/ngrok.js
index d778b57..1ee2a45 100644
--- a/src/agents/ngrok.js
+++ b/src/agents/ngrok.js
@@ -25,8 +25,9 @@ const util = require('util');
 const crypto = require("crypto");
 
 class NgrokAgent {
-constructor(argv) {
+constructor(argv, invoker) {
 this.argv = argv;
+this.invoker = invoker;
 }
 
 async getAgent(action) {
diff --git a/src/debugger.js b/src/debugger.js
index fc24b11..415bde9 100644
--- a/src/debugger.js
+++ b/src/debugger.js
@@ -82,7 +82,7 @@ class Debugger {
 await this.agentMgr.restoreAction();
 }
 
-await this.agentMgr.installAgent(action);
+await this.agentMgr.installAgent(action, this.invoker);
 
 if (this.argv.onStart) {
 console.log("On start:", this.argv.onStart);
diff --git a/test/ngrok.test.js b/test/ngrok.test.js
index 0ae21b3..a095659 100644
--- a/test/ngrok.test.js
+++ b/test/ngrok.test.js
@@ -126,20 +126,19 @@ describe('ngrok',  function() {
 
 it("should handle action invocation using ngrok", async function() {
 const actionName = "myaction";
+// should not use this code if we specify local sources which return 
CORRECT
+const code = `const main = () => ({ msg: 'WRONG' });`;
 
 // port of the local server started by wskdebug to be expecting calls 
from ngrok
 // which we will do in this test
-let ngrokServerPort;
+let ngrokServerPort, ngrokKillInvoked, ngrokAuth;
 mockNgrokLibrary(function(opts) {
 ngrokServerPort = opts.addr;
 return "https://UNIT_TEST.ngrok.io";;
+}, function() {
+ngrokKillInvoked = true;
 });
 
-// should not use this code if we specify local sources which return 
CORRECT
-const code = `const main = () => ({ msg: 'WRONG' });`;
-
-let ngrokAuth;
-
 test.mockAction(actionName, code);
 test.mockCreateBackupAction(actionName);
 
@@ -156,8 +155,11 @@ describe('ngrok',  function() {
 .matchHeader("authorization", test.openwhiskApiAuthHeader())
 .reply(200, test.nodejsActionDescription(actionName));
 
+test.mockReadBackupAction(actionName);
+test.mockRestoreAction(actionName);
+test.mockRemoveBackupAction(actionName);
 
-// wskdebug myaction --ngrok -p ${test.port}
+// wskdebug myaction action.js --ngrok -p ${test.port}
 const argv = {
 port: test.port,
 action: actionName,
@@ -174,7 +176,7 @@ describe('ngrok',  function() {
 await test.sleep(10);
 
 try {
-
+// simulate invocation coming in via ngrok forwarding
 const response = await 
fetch(`http://127.0.0.1:${ngrokServerPort}`, {
 method: "POST",
 headers: {
@@ -185,6 +187,7 @@ describe('ngrok',  function() {
 })
 });
 
+// ensure correct result
 assert.strictEqual(response.status, 200);
 const result = await response.json();
 assert.strictEqual(result.msg, "CORRECT");
@@ -193,6 +196,7 @@ describe('ngrok',  function() {
 await dbgr.stop();
 }
 
+assert(ngrokKillInvoked);
 assert(nock.isDone(), "Expected these HTTP requests: " + 
nock.pendingMocks().join());
 });
 });



[openwhisk-wskdebug] 04/07: ensure latest yargs 15.3.0 is used as #17 depends on it

2020-03-31 Thread alexkli
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 c07093d40b9312fa2c9273c9f6ea45630e1994e7
Author: Alexander Klimetschek 
AuthorDate: Sun Mar 29 00:19:10 2020 -0700

ensure latest yargs 15.3.0 is used as #17 depends on it
---
 package-lock.json | 14 +++---
 package.json  |  2 +-
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index 83451a2..f2f7890 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -3524,9 +3524,9 @@
 "integrity": 
"sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w=="
 },
 "yargs": {
-"version": "15.1.0",
-"resolved": "https://registry.npmjs.org/yargs/-/yargs-15.1.0.tgz";,
-"integrity": 
"sha512-T39FNN1b6hCW4SOIk1XyTOWxtXdcen0t+XYrysQmChzSipvhBO8Bj0nK1ozAasdk24dNWuMZvr4k24nz+8HHLg==",
+"version": "15.3.1",
+"resolved": "https://registry.npmjs.org/yargs/-/yargs-15.3.1.tgz";,
+"integrity": 
"sha512-92O1HWEjw27sBfgmXiixJWT5hRBp2eobqXicLtPBIDBhYB+1HpwZlXmbW2luivBJHBzki+7VyCLRtAkScbTBQA==",
 "requires": {
 "cliui": "^6.0.0",
 "decamelize": "^1.2.0",
@@ -3538,7 +3538,7 @@
 "string-width": "^4.2.0",
 "which-module": "^2.0.0",
 "y18n": "^4.0.0",
-"yargs-parser": "^16.1.0"
+"yargs-parser": "^18.1.1"
 },
 "dependencies": {
 "emoji-regex": {
@@ -3592,9 +3592,9 @@
 }
 },
 "yargs-parser": {
-"version": "16.1.0",
-"resolved": 
"https://registry.npmjs.org/yargs-parser/-/yargs-parser-16.1.0.tgz";,
-"integrity": 
"sha512-H/V41UNZQPkUMIT5h5hiwg4QKIY1RPvoBV4XcjUbRM8Bk2oKqqyZ0DIEbTFZB0XjbtSPG8SAa/0DxCQmiRgzKg==",
+"version": "18.1.2",
+"resolved": 
"https://registry.npmjs.org/yargs-parser/-/yargs-parser-18.1.2.tgz";,
+"integrity": 
"sha512-hlIPNR3IzC1YuL1c2UwwDKpXlNFBqD1Fswwh1khz5+d8Cq/8yc/Mn0i+rQXduu8hcrFKvO7Eryk+09NecTQAAQ==",
 "requires": {
 "camelcase": "^5.0.0",
 "decamelize": "^1.2.0"
diff --git a/package.json b/package.json
index 1149666..4e43645 100644
--- a/package.json
+++ b/package.json
@@ -48,7 +48,7 @@
 "manakin": "^0.5.2",
 "ngrok": "^3.2.7",
 "openwhisk": "^3.21.1",
-"yargs": "^15.1.0"
+"yargs": "^15.3.1"
 },
 "devDependencies": {
 "chmodr": "^1.2.0",



[openwhisk-wskdebug] 05/07: add complete invocation test for ngrok (failing for now)

2020-03-31 Thread alexkli
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 8eebc66262db5fed8c7387391c670adf61c9d646
Author: Alexander Klimetschek 
AuthorDate: Mon Mar 30 22:35:24 2020 -0700

add complete invocation test for ngrok (failing for now)
---
 package-lock.json |  33 
 package.json  |   1 +
 src/agentmgr.js   |   2 +-
 src/{ => agents}/ngrok.js |   2 +-
 test/ngrok.test.js| 129 --
 test/test.js  |  85 ++
 6 files changed, 225 insertions(+), 27 deletions(-)

diff --git a/package-lock.json b/package-lock.json
index f2f7890..64dbc66 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -,6 +,33 @@
 }
 }
 },
+"mock-require": {
+"version": "3.0.3",
+"resolved": 
"https://registry.npmjs.org/mock-require/-/mock-require-3.0.3.tgz";,
+"integrity": 
"sha512-lLzfLHcyc10MKQnNUCv7dMcoY/2Qxd6wJfbqCcVk3LDb8An4hF6ohk5AztrvgKhJCqj36uyzi/p5se+tvyD+Wg==",
+"dev": true,
+"requires": {
+"get-caller-file": "^1.0.2",
+"normalize-path": "^2.1.1"
+},
+"dependencies": {
+"get-caller-file": {
+"version": "1.0.3",
+"resolved": 
"https://registry.npmjs.org/get-caller-file/-/get-caller-file-1.0.3.tgz";,
+"integrity": 
"sha512-3t6rVToeoZfYSGd8YoLFR2DJkiQrIiUrGcjvFX2mDw3bn6k2OtwHN0TNCLbBO+w8qTvimhDkv+LSscbJY1vE6w==",
+"dev": true
+},
+"normalize-path": {
+"version": "2.1.1",
+"resolved": 
"https://registry.npmjs.org/normalize-path/-/normalize-path-2.1.1.tgz";,
+"integrity": "sha1-GrKLVW4Zg2Oowab35vogE3/mrtk=",
+"dev": true,
+"requires": {
+"remove-trailing-separator": "^1.0.1"
+}
+}
+}
+},
 "ms": {
 "version": "2.1.2",
 "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz";,
@@ -2833,6 +2860,12 @@
 "es6-error": "^4.0.1"
 }
 },
+"remove-trailing-separator": {
+"version": "1.1.0",
+"resolved": 
"https://registry.npmjs.org/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz";,
+"integrity": "sha1-wkvOKig62tW8P1jg1IJJuSN52O8=",
+"dev": true
+},
 "request": {
 "version": "2.88.2",
 "resolved": 
"https://registry.npmjs.org/request/-/request-2.88.2.tgz";,
diff --git a/package.json b/package.json
index 4e43645..801767f 100644
--- a/package.json
+++ b/package.json
@@ -60,6 +60,7 @@
 "get-port": "^5.1.1",
 "mocha": "^7.1.0",
 "mocha-multi-reporters": "^1.1.7",
+"mock-require": "^3.0.3",
 "nock": "^12.0.2",
 "nyc": "^15.0.0",
 "strip-ansi": "^6.0.0",
diff --git a/src/agentmgr.js b/src/agentmgr.js
index 3264cc1..c1aa673 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -17,7 +17,7 @@
 
 'use strict';
 
-const NgrokAgent = require('./ngrok');
+const NgrokAgent = require('./agents/ngrok');
 const fs = require('fs-extra');
 const sleep = require('util').promisify(setTimeout);
 
diff --git a/src/ngrok.js b/src/agents/ngrok.js
similarity index 98%
rename from src/ngrok.js
rename to src/agents/ngrok.js
index 4551ef9..d778b57 100644
--- a/src/ngrok.js
+++ b/src/agents/ngrok.js
@@ -63,7 +63,7 @@ class NgrokAgent {
 
 console.log(`Ngrok forwarding: ${ngrokUrl} => 
http://localhost:${this.ngrokServerPort} (auth: ${this.ngrokAuth})`);
 
-return fs.readFileSync(`${__dirname}/../agent/agent-ngrok.js`, 
{encoding: 'utf8'});
+return fs.readFileSync(`${__dirname}/../../agent/agent-ngrok.js`, 
{encoding: 'utf8'});
 }
 
 async stop() {
diff --git a/test/ngrok.test.js b/test/ngrok.test.js
index fc4a033..0ae21b3 100644
--- a/test/ngrok.test.js
+++ b/test/ngrok.test.js
@@ -19,11 +19,30 @@
 
 'use strict';
 
-const Debugger = require("../src/debugger");
-
 const test = require('./test');
+let Debugger = require("../src/debugger");
+
 const assert = require('assert');
 const nock = require('nock');
+const fetch = require('isomorphic-fetch');
+const mockRequire = require('mock-require');
+
+function mockNgrokLibrary(connect, kill) {
+mockRequire("ngrok", {
+connect: connect || function() {
+console.log('ngrok.connect called');
+},
+kill: kill || function() {
+console.log('ngrok.kill called');
+}
+});
+// the modules have been loaded from another test file before,
+// so we need to re-require them in the reve

[openwhisk-wskdebug] 01/07: refactor huge debugger.js into separate files & classes

2020-03-31 Thread alexkli
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 0097ab1b6a297179921c9b4d0d543aba5ab52c3c
Author: Alexander Klimetschek 
AuthorDate: Sat Mar 28 23:49:00 2020 -0700

refactor huge debugger.js into separate files & classes
---
 .eslintignore   |   1 +
 src/agentmgr.js | 505 +
 src/debugger.js | 692 +++-
 src/ngrok.js| 139 
 src/watcher.js  | 123 ++
 5 files changed, 800 insertions(+), 660 deletions(-)

diff --git a/.eslintignore b/.eslintignore
new file mode 100644
index 000..c795b05
--- /dev/null
+++ b/.eslintignore
@@ -0,0 +1 @@
+build
\ No newline at end of file
diff --git a/src/agentmgr.js b/src/agentmgr.js
new file mode 100644
index 000..cb0e5a9
--- /dev/null
+++ b/src/agentmgr.js
@@ -0,0 +1,505 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+'use strict';
+
+const NgrokAgent = require('./ngrok');
+const fs = require('fs-extra');
+const sleep = require('util').promisify(setTimeout);
+
+function getAnnotation(action, key) {
+const a = action.annotations.find(a => a.key === key);
+if (a) {
+return a.value;
+}
+}
+
+function getActionCopyName(name) {
+return `${name}_wskdebug_original`;
+}
+
+function isAgent(action) {
+return getAnnotation(action, "wskdebug") ||
+   (getAnnotation(action, "description") || "").startsWith("wskdebug 
agent.");
+}
+
+function getActivationError(e) {
+if (e.error && e.error.response && e.error.response.result && 
e.error.response.result.error) {
+return e.error.response.result.error;
+}
+return {};
+}
+
+async function getWskActionWithoutCode(wsk, actionName) {
+try {
+return await wsk.actions.get({name: actionName, code:false});
+} catch (e) {
+if (e.statusCode === 404) {
+return null;
+} else {
+throw e;
+}
+}
+}
+
+async function actionExists(wsk, name) {
+try {
+await wsk.actions.get({name: name, code: false});
+return true;
+} catch (e) {
+return false;
+}
+}
+
+async function deleteActionIfExists(wsk, name) {
+if (await actionExists(wsk, name)) {
+await wsk.actions.delete(name);
+}
+}
+
+
+// TODO: test wskdebug manually
+// TODO: openwhiskSupports() into separate shared class
+class AgentMgr {
+
+constructor(argv, wsk, actionName) {
+this.argv = argv;
+this.wsk = wsk;
+this.actionName = actionName;
+this.polling = true;
+}
+
+async readAction() {
+if (this.argv.verbose) {
+console.log(`Getting action metadata from OpenWhisk: 
${this.actionName}`);
+}
+let action = await getWskActionWithoutCode(this.wsk, this.actionName);
+if (action === null) {
+throw new Error(`Action not found: ${this.actionName}`);
+}
+
+let agentAlreadyInstalled = false;
+
+// check if this actoin needs to
+if (isAgent(action)) {
+// ups, action is our agent, not the original
+// happens if a previous wskdebug was killed and could not restore 
before it exited
+const backupName = getActionCopyName(this.actionName);
+
+// check the backup action
+try {
+const backup = await this.wsk.actions.get(backupName);
+
+if (isAgent(backup)) {
+// backup is also an agent (should not happen)
+// backup is useless, delete it
+// await this.wsk.actions.delete(backupName);
+throw new Error(`Dang! Agent is already installed and 
action backup is broken (${backupName}).\n\nPlease redeploy your action first 
before running wskdebug again.`);
+
+} else {
+console.warn("Agent was already installed, but backup is 
still present. All good.");
+
+// need to look at the original action
+action = backup;
+agentAlreadyInstalled = true

[openwhisk-wskdebug] branch master updated (35cbe91 -> 397aa85)

2020-03-31 Thread alexkli
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git.


from 35cbe91  remove node 8 in travis as we don't really support it and it 
keeps failing fsevents tests (#33)
 new 0097ab1  refactor huge debugger.js into separate files & classes
 new 7290fc6  add missing EOL
 new cd50058  guard this.* access in Debugger.shutdown()/stop()/kill()
 new c07093d  ensure latest yargs 15.3.0 is used as #17 depends on it
 new 8eebc66  add complete invocation test for ngrok (failing for now)
 new 2da4644  quick fix for ngrok agent requiring access to invoker
 new 397aa85  fix duplicated shutdown() issue on CTRL+C

The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .eslintignore   |   1 +
 package-lock.json   |  47 +++-
 package.json|   3 +-
 src/agentmgr.js | 503 +
 src/agents/ngrok.js | 140 +++
 src/debugger.js | 705 
 src/watcher.js  | 123 +
 test/ngrok.test.js  | 133 +-
 test/test.js|  85 +--
 9 files changed, 1049 insertions(+), 691 deletions(-)
 create mode 100644 .eslintignore
 create mode 100644 src/agentmgr.js
 create mode 100644 src/agents/ngrok.js
 create mode 100644 src/watcher.js



[openwhisk-wskdebug] branch concurrency-not-supported updated (c24b163 -> 96292a3)

2020-03-31 Thread alexkli
This is an automated email from the ASF dual-hosted git repository.

alexkli pushed a change to branch concurrency-not-supported
in repository https://gitbox.apache.org/repos/asf/openwhisk-wskdebug.git.


from c24b163  Concurrency error when using wskdebug with IBM Cloud 
Functions #7
 add 35cbe91  remove node 8 in travis as we don't really support it and it 
keeps failing fsevents tests (#33)
 add 0097ab1  refactor huge debugger.js into separate files & classes
 add 7290fc6  add missing EOL
 add cd50058  guard this.* access in Debugger.shutdown()/stop()/kill()
 add c07093d  ensure latest yargs 15.3.0 is used as #17 depends on it
 add 8eebc66  add complete invocation test for ngrok (failing for now)
 add 2da4644  quick fix for ngrok agent requiring access to invoker
 add 397aa85  fix duplicated shutdown() issue on CTRL+C
 add 96292a3  Merge branch 'master' into concurrency-not-supported

No new revisions were added by this update.

Summary of changes:
 .travis.yml  | 1 -
 test/test.js | 1 +
 2 files changed, 1 insertion(+), 1 deletion(-)



[openwhisk-wskdebug] branch master updated: Use activation db agent if concurrency is not supported (#32)

2020-03-31 Thread alexkli
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


The following commit(s) were added to refs/heads/master by this push:
 new da0806b  Use activation db agent if concurrency is not supported (#32)
da0806b is described below

commit da0806b51b3935eaea8b3ebc6af779fe27c26637
Author: Alexander Klimetschek 
AuthorDate: Tue Mar 31 13:47:24 2020 -0700

Use activation db agent if concurrency is not supported (#32)

Fixes Concurrency error when using wskdebug with IBM Cloud Functions #7

if concurrency > 1 is not supported, fallback to activation db agent
---
 src/agentmgr.js   |  21 ++-
 test/agentmgr.test.js | 164 ++
 test/test.js  |   6 ++
 3 files changed, 188 insertions(+), 3 deletions(-)

diff --git a/src/agentmgr.js b/src/agentmgr.js
index 8b59f28..15ea202 100644
--- a/src/agentmgr.js
+++ b/src/agentmgr.js
@@ -158,7 +158,7 @@ class AgentMgr {
 console.log("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.getPollingActivationRecordAgent();
+agentCode = await this.getPollingActivationDbAgent();
 }
 }
 
@@ -185,7 +185,17 @@ class AgentMgr {
 });
 }
 
-await this.pushAgent(action, agentCode, backupName);
+try {
+await this.pushAgent(action, agentCode, backupName);
+} catch (e) {
+// openwhisk does not support concurrent nodejs actions, try with 
another
+if (e.statusCode === 400 && e.error && typeof e.error.error === 
"string" && e.error.error.includes("concurrency")) {
+console.log(`The Openwhisk server does not support concurrent 
actions, using alternative agent. Consider using --ngrok for a possibly faster 
agent.`);
+this.concurrency = false;
+agentCode = await this.getPollingActivationDbAgent();
+await this.pushAgent(action, agentCode, backupName);
+}
+}
 
 if (this.argv.verbose) {
 console.log(`Agent installed.`);
@@ -259,6 +269,11 @@ class AgentMgr {
 const a = activations[0];
 if (a.response && a.response.result && 
!this.activationsSeen[a.activationId]) {
 activation = a;
+if (!activation.response.success) {
+throw {
+error: activation
+};
+}
 break;
 }
 }
@@ -389,7 +404,7 @@ class AgentMgr {
 return fs.readFileSync(`${__dirname}/../agent/agent-concurrency.js`, 
{encoding: 'utf8'});
 }
 
-async getPollingActivationRecordAgent() {
+async getPollingActivationDbAgent() {
 // this needs 2 helper actions in addition to the agent in place of 
the action
 await this.createHelperAction(`${this.actionName}_wskdebug_invoked`,   
`${__dirname}/../agent/echo.js`);
 await this.createHelperAction(`${this.actionName}_wskdebug_completed`, 
`${__dirname}/../agent/echo.js`);
diff --git a/test/agentmgr.test.js b/test/agentmgr.test.js
new file mode 100644
index 000..cf069b7
--- /dev/null
+++ b/test/agentmgr.test.js
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* eslint-env mocha */
+
+'use strict';
+
+const Debugger = require("../src/debugger");
+
+const test = require('./test');
+
+describe('agentmgr',  function() {
+this.timeout(3);
+
+before(function() {
+test.isDockerInstalled();
+});
+
+beforeEach(async function() {
+await test.beforeEach();
+});
+
+afterEach(function() {
+test.afterEach();
+});
+
+it("should use non-concurrrent agent if openwhisk does