You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by wo...@apache.org on 2017/05/31 21:35:56 UTC
[couchdb] 01/01: Improve JS test harness restartServer() support fn
This is an automated email from the ASF dual-hosted git repository.
wohali pushed a commit to branch 553-js-restart
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 0133b59a301b91a0ec55ed3b18afa95db6a142a2
Author: Joan Touzet <jo...@atypical.net>
AuthorDate: Wed May 31 16:44:12 2017 -0400
Improve JS test harness restartServer() support fn
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
---
test/javascript/couch_test_runner.js | 31 -------------------------------
test/javascript/test_setup.js | 29 +++++++++++++++++++++++++++--
2 files changed, 27 insertions(+), 33 deletions(-)
diff --git a/test/javascript/couch_test_runner.js b/test/javascript/couch_test_runner.js
index 6567859..d51748b 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 ccc0485..73667ed 100644
--- a/test/javascript/test_setup.js
+++ b/test/javascript/test_setup.js
@@ -71,11 +71,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;
+ print('\nFAIL restart');
+ quit(1);
+ }
+ try {
+ sleep(500);
+ complete = getUptime() < olduptime;
+ } catch (e) {}
+ }
}
/*
--
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <co...@couchdb.apache.org>.