You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by al...@apache.org on 2016/09/29 16:01:38 UTC
[1/2] cordova-paramedic git commit: CB-11926 Start a server for
file-transfer tests locally
Repository: cordova-paramedic
Updated Branches:
refs/heads/master 031343cbb -> 91c906ff3
CB-11926 Start a server for file-transfer tests locally
Project: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/commit/3315570a
Tree: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/tree/3315570a
Diff: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/diff/3315570a
Branch: refs/heads/master
Commit: 3315570a458d58ee5a33c683cc8a5964533fd124
Parents: 031343c
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Wed Sep 28 17:54:22 2016 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Thu Sep 29 15:17:12 2016 +0300
----------------------------------------------------------------------
lib/LocalServer.js | 72 +++++++++++++++++++++++++++++++++-----
lib/appium/AppiumRunner.js | 14 +++-----
lib/paramedic.js | 41 +++++++++++++++-------
lib/utils/utilities.js | 12 ++++++-
paramedic-plugin/paramedic.js | 45 +++++++++++++++++++++---
5 files changed, 147 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/3315570a/lib/LocalServer.js
----------------------------------------------------------------------
diff --git a/lib/LocalServer.js b/lib/LocalServer.js
index c8e5422..0a2b2f3 100644
--- a/lib/LocalServer.js
+++ b/lib/LocalServer.js
@@ -20,10 +20,13 @@
var Q = require('q');
var io = require('socket.io');
var logger = require('./utils').logger;
+var exec = require('./utils').execPromise;
var util = require('util');
var portChecker = require('tcp-port-used');
var EventEmitter = require('events').EventEmitter;
var localtunnel = require('localtunnel');
+var shell = require('shelljs');
+var spawn = require('child_process').spawn;
// how many ms without a pong packet to consider the connection closed
@@ -34,6 +37,7 @@ var CONNECTION_HEARBEAT_PING_INTERVAL = 25000;
function LocalServer(port, externalServerUrl) {
this.port = port;
this.externalServerUrl = externalServerUrl;
+ this.server = { alive: false };
}
util.inherits(LocalServer, EventEmitter);
@@ -57,6 +61,50 @@ LocalServer.startServer = function (ports, externalServerUrl, useTunnel) {
});
};
+LocalServer.prototype.cleanUp = function () {
+ logger.normal('local-server: killing local file transfer server if it\'s up...');
+ if (this.server.alive) {
+ this.server.alive = false;
+ this.server.process.kill('SIGKILL');
+ }
+};
+
+LocalServer.prototype.startFileTransferServer = function (tempPath) {
+ var self = this;
+
+ function exitGracefully(e) {
+ // clean up only once
+ if (self.exiting) {
+ return;
+ }
+ self.exiting = true;
+ self.cleanUp();
+ }
+
+ process.on('uncaughtException', function(err) {
+ exitGracefully(err);
+ });
+
+ return Q().then(function () {
+ shell.pushd(tempPath);
+ logger.normal('local-server: cloning file tranfer server');
+ return exec('git clone https://github.com/apache/cordova-labs --branch cordova-filetransfer');
+ }).then(function () {
+ shell.pushd('cordova-labs');
+ logger.normal('local-server: installing local file transfer server');
+ return exec('npm i');
+ }).then(function () {
+ logger.normal('local-server: starting local file transfer server');
+ self.server.process = spawn('node', [ 'server.js' ]);
+ self.server.alive = true;
+
+ logger.info('local-server: local file transfer server started');
+ shell.popd();
+ shell.popd();
+ return self.server;
+ });
+};
+
LocalServer.getFirstAvailablePort = function (startPort, endPort) {
return portChecker.check(startPort).then(function (isInUse) {
if (!isInUse) {
@@ -117,16 +165,12 @@ LocalServer.prototype.createSocketListener = function () {
});
};
-// Connection url could be platform specific so we pass platform as param here
-LocalServer.prototype.getConnectionUrl = function (platformId) {
- // --useTunnel option
- if (this.tunneledUrl) {
- return this.tunneledUrl;
- }
- // --externalServerUrl option / we know ip or dns name
+// Connection address could be platform specific so we pass platform as param here
+LocalServer.prototype.getConnectionAddress = function (platformId) {
if (this.externalServerUrl) {
- return this.externalServerUrl + ":" + this.port;
+ return this.externalServerUrl;
}
+
// build connection uri for localhost based on platform
var connectionUrl;
@@ -142,7 +186,17 @@ LocalServer.prototype.getConnectionUrl = function (platformId) {
connectionUrl = "http://127.0.0.1";
}
- return connectionUrl + ":" + this.port;
+ return connectionUrl;
+};
+
+// Connection url could be platform specific so we pass platform as param here
+LocalServer.prototype.getConnectionUrl = function (platformId) {
+ // --useTunnel option
+ if (this.tunneledUrl) {
+ return this.tunneledUrl;
+ }
+
+ return this.getConnectionAddress(platformId) + ":" + this.port;
};
LocalServer.prototype.isDeviceConnected = function () {
http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/3315570a/lib/appium/AppiumRunner.js
----------------------------------------------------------------------
diff --git a/lib/appium/AppiumRunner.js b/lib/appium/AppiumRunner.js
index 699b24f..3e19059 100644
--- a/lib/appium/AppiumRunner.js
+++ b/lib/appium/AppiumRunner.js
@@ -30,7 +30,6 @@ var logger = require('../utils').logger;
var wd = require('wd');
var wdHelper = require('./helpers/wdHelper');
var screenshotHelper = require('./helpers/screenshotHelper');
-var kill = require('tree-kill');
var child_process = require('child_process');
var expectTelnet = require('expect-telnet');
var shell = require('shelljs');
@@ -42,7 +41,6 @@ var Reporters = require('../Reporters');
var execPromise = require('../utils').execPromise;
var Reporters = require('../Reporters');
-var KILL_SIGNAL = 'SIGINT';
var SMALL_BUFFER_SIZE = 1024 * 1024;
var BIG_BUFFER_SIZE = 50 * 1024 * 1024;
var APPIUM_SERVER_PATH = getAppiumServerPath();
@@ -187,12 +185,10 @@ function isFailFastError(error) {
return false;
}
-function killProcess(procObj, killSignal, callback) {
+function killProcess(procObj, callback) {
if (procObj && procObj.alive) {
procObj.alive = false;
- setTimeout(function () {
- kill(procObj.process.pid, killSignal, callback);
- }, 1000);
+ util.killProcess(procObj.pid, callback);
} else {
callback();
}
@@ -223,8 +219,8 @@ AppiumRunner.prototype.prepareOptions = function () {
AppiumRunner.prototype.cleanUp = function (callback) {
var self = this;
- killProcess(self.appium, KILL_SIGNAL, function () {
- killProcess(self.iosProxy, KILL_SIGNAL, function () {
+ killProcess(self.appium, function () {
+ killProcess(self.iosProxy, function () {
callback();
});
});
@@ -242,7 +238,7 @@ AppiumRunner.prototype.startTests = function () {
if (!!e) {
logger.normal('paramedic-appium: ' + e);
}
- logger.normal('paramedic-appium: Uncaught exception! Killing server and exiting in 2 seconds...');
+ logger.normal('paramedic-appium: Uncaught exception! Killing Appium server and exiting in 2 seconds...');
self.exiting = true;
self.cleanUp(function () {
setTimeout(function () {
http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/3315570a/lib/paramedic.js
----------------------------------------------------------------------
diff --git a/lib/paramedic.js b/lib/paramedic.js
index cfcbdb0..24aea6f 100644
--- a/lib/paramedic.js
+++ b/lib/paramedic.js
@@ -85,8 +85,9 @@ ParamedicRunner.prototype.run = function () {
self.injectReporters();
self.subcribeForEvents();
- var connectionUrl = server.getConnectionUrl(self.config.getPlatformId());
- self.writeMedicConnectionUrl(connectionUrl);
+ var logUrl = server.getConnectionUrl(self.config.getPlatformId());
+ var fileServerUrl = server.getConnectionAddress(self.config.getPlatformId()) + ':5000';
+ self.writeMedicJson(logUrl, fileServerUrl);
logger.normal('Start running tests at ' + (new Date()).toLocaleTimeString());
}
@@ -198,9 +199,14 @@ ParamedicRunner.prototype.subcribeForEvents = function () {
});
};
-ParamedicRunner.prototype.writeMedicConnectionUrl = function(url) {
- logger.normal('cordova-paramedic: writing medic log url to project ' + url);
- fs.writeFileSync(path.join('www','medic.json'), JSON.stringify({logurl:url}));
+ParamedicRunner.prototype.writeMedicJson = function(logUrl, fileServerUrl) {
+ logger.normal('cordova-paramedic: writing medic log url to project ' + logUrl);
+ logger.normal('cordova-paramedic: writing file server url to project ' + fileServerUrl);
+
+ fs.writeFileSync(path.join('www','medic.json'), JSON.stringify({
+ logurl:logUrl,
+ fileserverurl: fileServerUrl
+ }));
};
ParamedicRunner.prototype.buildApp = function () {
@@ -228,7 +234,18 @@ ParamedicRunner.prototype.runLocalTests = function () {
return Q(util.TEST_PASSED);
}
- return self.getCommandForStartingTests()
+ return Q().then(function () {
+ var plugins = self.config.getPlugins();
+ for (var i = 0; i < plugins.length; i++) {
+ if (plugins[i].indexOf('cordova-plugin-file-transfer') >= 0) {
+ logger.warn('found cordova-plugin-file-transfer in ' + plugins[i]);
+ return self.server.startFileTransferServer(self.tempFolder.name);
+ }
+ }
+ })
+ .then(function () {
+ return self.getCommandForStartingTests();
+ })
.then(function(command) {
self.setPermissions();
logger.normal('cordova-paramedic: running command ' + command);
@@ -250,16 +267,14 @@ ParamedicRunner.prototype.runLocalTests = function () {
self.waitForConnection().catch(reject);
// resolve if got results
self.waitForTests().then(resolve);
+ })
+ .then(function (result) {
+ self.server.cleanUp();
+ return result;
});
}
+
return util.TEST_PASSED; // if we're not waiting for a test result, just report tests as passed
- }, function(output) {
- // this trace is automatically available in verbose mode
- // so we check for this flag to not trace twice
- if (!self.config.verbose) {
- logger.normal(output);
- }
- throw new Error('Unable to run tests.');
});
};
http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/3315570a/lib/utils/utilities.js
----------------------------------------------------------------------
diff --git a/lib/utils/utilities.js b/lib/utils/utilities.js
index eac4a45..ea2ae1a 100644
--- a/lib/utils/utilities.js
+++ b/lib/utils/utilities.js
@@ -25,10 +25,13 @@ var os = require('os');
var util = require('util');
var path = require('path-extra');
var logger = require('cordova-common').CordovaLogger.get();
+var kill = require('tree-kill');
var HEADING_LINE_PATTERN = /List of devices/m;
var DEVICE_ROW_PATTERN = /(emulator|device|host)/m;
+var KILL_SIGNAL = 'SIGINT';
+
function isWindows() {
return /^win/.test(os.platform());
}
@@ -141,6 +144,12 @@ function contains(collection, item) {
return collection.indexOf(item) !== (-1);
}
+function killProcess(pid, callback) {
+ kill(pid, KILL_SIGNAL, function () {
+ setTimeout(callback, 1000);
+ });
+}
+
module.exports = {
ANDROID: 'android',
IOS: 'ios',
@@ -171,5 +180,6 @@ module.exports = {
getSimulatorModelId: getSimulatorModelId,
getSimulatorId: getSimulatorId,
contains: contains,
- mkdirSync: mkdirSync
+ mkdirSync: mkdirSync,
+ killProcess: killProcess
};
http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/3315570a/paramedic-plugin/paramedic.js
----------------------------------------------------------------------
diff --git a/paramedic-plugin/paramedic.js b/paramedic-plugin/paramedic.js
index 8fd9971..e225e7a 100644
--- a/paramedic-plugin/paramedic.js
+++ b/paramedic-plugin/paramedic.js
@@ -21,6 +21,7 @@
var io = cordova.require('cordova-plugin-paramedic.socket.io');
var PARAMEDIC_SERVER_DEFAULT_URL = 'http://127.0.0.1:8008';
+var PARAMEDIC_FILESERVER_DEFAULT_URL = 'http://127.0.0.1:5000';
function Paramedic() {
@@ -28,7 +29,7 @@ function Paramedic() {
Paramedic.prototype.initialize = function() {
var me = this;
- var connectionUri = loadParamedicServerUrl();
+ var connectionUri = me.loadParamedicServerUrl();
this.socket = io.connect(connectionUri);
this.socket.on('connect', function () {
@@ -76,10 +77,7 @@ Paramedic.prototype.injectJasmineReporter = function () {
};
};
-new Paramedic().initialize();
-
-function loadParamedicServerUrl() {
-
+Paramedic.prototype.loadParamedicServerUrl = function () {
try {
// attempt to synchronously load medic config
var xhr = new XMLHttpRequest();
@@ -94,6 +92,43 @@ function loadParamedicServerUrl() {
}
return PARAMEDIC_SERVER_DEFAULT_URL;
+};
+
+
+Paramedic.prototype.loadParamedicServerUrl = function () {
+ return getMedicConfig().logurl;
+};
+
+Paramedic.prototype.loadParamedicFileServerUrl = function () {
+ return getMedicConfig().fileserverurl;
+};
+
+cordova.paramedic = new Paramedic();
+cordova.paramedic.initialize();
+
+function getMedicConfig () {
+ var cfg = {
+ logurl: PARAMEDIC_SERVER_DEFAULT_URL,
+ fileserverurl: PARAMEDIC_FILESERVER_DEFAULT_URL
+ };
+
+ try {
+ // attempt to synchronously load medic config
+ var xhr = new XMLHttpRequest();
+ xhr.open("GET", "../medic.json", false);
+ xhr.send(null);
+ var parsedCfg = JSON.parse(xhr.responseText);
+ if (parsedCfg.logurl) {
+ cfg.logurl = parsedCfg.logurl;
+ }
+ if (parsedCfg.fileserverurl) {
+ cfg.fileserverurl = parsedCfg.fileserverurl;
+ }
+ } catch (ex) {
+ console.log('Unable to load paramedic server url: ' + ex);
+ }
+
+ return cfg;
}
module.exports = Paramedic;
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org
[2/2] cordova-paramedic git commit: Better file transfer server clean
up
Posted by al...@apache.org.
Better file transfer server clean up
Project: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/commit/91c906ff
Tree: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/tree/91c906ff
Diff: http://git-wip-us.apache.org/repos/asf/cordova-paramedic/diff/91c906ff
Branch: refs/heads/master
Commit: 91c906ff3c14015a42c67784989511fb4efa9e91
Parents: 3315570
Author: Alexander Sorokin <al...@akvelon.com>
Authored: Thu Sep 29 19:00:44 2016 +0300
Committer: Alexander Sorokin <al...@akvelon.com>
Committed: Thu Sep 29 19:00:44 2016 +0300
----------------------------------------------------------------------
lib/paramedic.js | 29 ++++++++++++++++-------------
1 file changed, 16 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cordova-paramedic/blob/91c906ff/lib/paramedic.js
----------------------------------------------------------------------
diff --git a/lib/paramedic.js b/lib/paramedic.js
index 24aea6f..fc7601b 100644
--- a/lib/paramedic.js
+++ b/lib/paramedic.js
@@ -226,22 +226,28 @@ ParamedicRunner.prototype.buildApp = function () {
});
};
-ParamedicRunner.prototype.runLocalTests = function () {
+ParamedicRunner.prototype.maybeRunFileTransferServer = function () {
var self = this;
-
- if (!self.config.runMainTests() && self.config.getPlatformId() !== 'android') {
- logger.normal('Skipping main tests...');
- return Q(util.TEST_PASSED);
- }
-
return Q().then(function () {
var plugins = self.config.getPlugins();
for (var i = 0; i < plugins.length; i++) {
if (plugins[i].indexOf('cordova-plugin-file-transfer') >= 0) {
- logger.warn('found cordova-plugin-file-transfer in ' + plugins[i]);
return self.server.startFileTransferServer(self.tempFolder.name);
}
}
+ });
+};
+
+ParamedicRunner.prototype.runLocalTests = function () {
+ var self = this;
+
+ if (!self.config.runMainTests() && self.config.getPlatformId() !== 'android') {
+ logger.normal('Skipping main tests...');
+ return Q(util.TEST_PASSED);
+ }
+
+ Q().then(function () {
+ return self.maybeRunFileTransferServer();
})
.then(function () {
return self.getCommandForStartingTests();
@@ -267,10 +273,6 @@ ParamedicRunner.prototype.runLocalTests = function () {
self.waitForConnection().catch(reject);
// resolve if got results
self.waitForTests().then(resolve);
- })
- .then(function (result) {
- self.server.cleanUp();
- return result;
});
}
@@ -452,6 +454,7 @@ ParamedicRunner.prototype.waitForConnection = function () {
};
ParamedicRunner.prototype.cleanUpProject = function () {
+ this.server.cleanUp();
if (this.config.shouldCleanUpAfterRun()) {
logger.info('cordova-paramedic: Deleting the application: ' + this.tempFolder.name);
shell.popd();
@@ -745,7 +748,7 @@ ParamedicRunner.prototype.runSauceTests = function () {
return Q(util.TEST_PASSED);
}
- logger.info('cordova-paramedic: running sauce tests');
+ logger.info('cordova-paramedic: running tests with sauce');
return this.buildApp()
.then(self.packageApp.bind(self))
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org