summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoan Touzet <joant@atypical.net>2017-05-31 16:44:12 -0400
committerJoan Touzet <joant@atypical.net>2017-05-31 18:02:09 -0400
commitc024d00c5e07b25ff6b379d1961734469361dd36 (patch)
treee7c8f30d7feb9a4c317aaf81bc031fa8aee73af4
parentacd74c801fbb597d75849711a5f773bb9cc9ae54 (diff)
downloadcouchdb-553-js-restart.tar.gz
Improve JS test harness restartServer() support fn553-js-restart
restartServer() is still erroring out sometimes in Travis/Jenkins. This PR both bumps the timeout to 15s as well as changes the detection mechanism for restart to look for the uptime in _system to reset to a low number. This PR also removes the eclipsed redundant restartServer() definition in couch_test_runner.js. Closes #553
-rw-r--r--test/javascript/couch_test_runner.js31
-rw-r--r--test/javascript/test_setup.js32
2 files changed, 28 insertions, 35 deletions
diff --git a/test/javascript/couch_test_runner.js b/test/javascript/couch_test_runner.js
index 656785980..d51748b7b 100644
--- a/test/javascript/couch_test_runner.js
+++ b/test/javascript/couch_test_runner.js
@@ -436,37 +436,6 @@ function waitForSuccess(fun, tag) {
}
}
-function getCurrentToken() {
- var xhr = CouchDB.request("GET", "/_restart/token");
- return JSON.parse(xhr.responseText).token;
-};
-
-
-function restartServer() {
- var token = getCurrentToken();
- var token_changed = false;
- var tDelta = 5000;
- var t0 = new Date();
- var t1;
-
- CouchDB.request("POST", "/_restart");
-
- do {
- try {
- if(token != getCurrentToken()) {
- token_changed = true;
- }
- } catch (e) {
- // Ignore errors while the server restarts
- }
- t1 = new Date();
- } while(((t1 - t0) <= tDelta) && !token_changed);
-
- if(!token_changed) {
- throw("Server restart failed");
- }
-}
-
// legacy functions for CouchDB < 1.2.0
// we keep them to make sure we keep BC
CouchDB.user_prefix = "org.couchdb.user:";
diff --git a/test/javascript/test_setup.js b/test/javascript/test_setup.js
index ccc0485aa..567848d9f 100644
--- a/test/javascript/test_setup.js
+++ b/test/javascript/test_setup.js
@@ -61,8 +61,7 @@ function waitForSuccess(fun, tag) {
var now = new Date().getTime();
if (now > start + 10000) {
complete = true;
- print('\nFAIL ' + tag);
- quit(1);
+ throw(Error('\nFAIL ' + tag));
}
try {
while (new Date().getTime() < now + 500);
@@ -71,11 +70,36 @@ function waitForSuccess(fun, tag) {
}
}
+function getUptime() {
+ var url = "/_node/node1@127.0.0.1/_system"
+ var stats = JSON.parse(CouchDB.request("GET", url).responseText);
+ return stats['uptime'];
+}
+
function restartServer() {
+ var olduptime = getUptime();
+ if (olduptime < 5) {
+ // handle quick-restarts, though this slows things down
+ sleep(5000);
+ olduptime = getUptime();
+ }
print('restart');
+
+ /* Need to pass olduptime to check fn so can't reuse waitForSuccess here */
var start = new Date().getTime();
- while (new Date().getTime() < start + 1000);
- waitForSuccess(CouchDB.isRunning, 'restart');
+ var complete = false;
+ while (!complete) {
+ var now = new Date().getTime();
+ if (now > start + 10000) {
+ complete = true;
+ uptime = getUptime();
+ throw(Error('FAILED to restart: ' + uptime + ' not < ' + olduptime));
+ }
+ try {
+ sleep(500);
+ complete = getUptime() < olduptime;
+ } catch (e) {}
+ }
}
/*