You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ga...@apache.org on 2015/10/13 16:52:13 UTC

couchdb-nmo git commit: Add Active tasks

Repository: couchdb-nmo
Updated Branches:
  refs/heads/master 17d6fefdb -> e95b93fd3


Add Active tasks

View active tasks for a CouchDB cluster or instance. Also able to filter
them view type or database name.


Project: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/commit/e95b93fd
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/tree/e95b93fd
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-nmo/diff/e95b93fd

Branch: refs/heads/master
Commit: e95b93fd30757cd34e94f785a0625137888b6d83
Parents: 17d6fef
Author: Garren Smith <ga...@gmail.com>
Authored: Tue Oct 6 15:31:34 2015 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Tue Oct 13 16:51:42 2015 +0200

----------------------------------------------------------------------
 doc/api/nmo-activetasks.md |  15 ++
 doc/cli/nmo-activetasks    |  27 +++
 package.json               |   2 +-
 src/activetasks.js         | 107 ++++++++++
 src/cluster.js             |   4 +-
 src/config.js              |  14 +-
 src/couch-config.js        |   3 +-
 src/isonline.js            |  11 +-
 src/nmo.js                 |  15 +-
 src/utils.js               |  21 ++
 test/activetasks.js        | 216 +++++++++++++++++++
 test/cluster.js            | 456 ++++++++++++++++++++++++----------------
 test/common.js             |  46 ++--
 test/config.js             |  34 ++-
 test/couch-config.js       |   3 +
 test/help.js               |   2 +
 test/import-csv.js         |   2 +
 test/isonline.js           |  97 ++++-----
 test/utils.js              |  70 ++++--
 19 files changed, 812 insertions(+), 333 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/doc/api/nmo-activetasks.md
----------------------------------------------------------------------
diff --git a/doc/api/nmo-activetasks.md b/doc/api/nmo-activetasks.md
new file mode 100644
index 0000000..728a152
--- /dev/null
+++ b/doc/api/nmo-activetasks.md
@@ -0,0 +1,15 @@
+nmo-activetasks(3) -- activetasks
+==============================
+
+## SYNOPSIS
+
+    nmo.commands.activetasks([<url> || <cluster>], [filter])
+
+
+## DESCRIPTION
+
+Get the list of active tasks from a specified url or cluster name and filter it according to
+the supplied filter.
+
+The filter can be either the task type e.g replication, view_indexer or a
+database name found in either the source, target or database field.

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/doc/cli/nmo-activetasks
----------------------------------------------------------------------
diff --git a/doc/cli/nmo-activetasks b/doc/cli/nmo-activetasks
new file mode 100644
index 0000000..200334b
--- /dev/null
+++ b/doc/cli/nmo-activetasks
@@ -0,0 +1,27 @@
+nmo-activetasks(1) -- view activetasks
+===========================================
+
+## SYNOPSIS
+
+    nmo activetasks cluster [<filter>] [--json]
+    nmo activetasks url [<filter>] [--json]
+
+
+## DESCRIPTION
+
+Get the list of active tasks from a specified url and filter it according to
+the supplied filter.
+
+The filter can be either the task type e.g replication, view_indexer or a
+database name found in either the source, target or database field.
+
+Example:
+
+This will get all the current activetasks
+    nmo activetasks mycluster
+
+This will get the replication active tasks from the CouchDB at the specified url
+    nmo activetasks http://127.0.0.1:5984 replication
+
+This will get all the current activetasks related the the datbase 'mydb'
+    nmo activetasks mycluster mydb

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/package.json
----------------------------------------------------------------------
diff --git a/package.json b/package.json
index 079e5f3..2a80f6f 100644
--- a/package.json
+++ b/package.json
@@ -7,7 +7,7 @@
   "scripts": {
     "transpile": "babel src -d lib",
     "prepublish": "make && npm run transpile",
-    "test": "lab -v --transform node_modules/lab-babel -t 100 -S",
+    "test": "lab -v --transform node_modules/lab-babel -S -I core,_babelPolyfill,regeneratorRuntime,__core-js_shared__,Reflect",
     "lint": "jshint ./src ./test"
   },
   "author": "Robert Kowalski <ro...@kowalski.gd>",

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/src/activetasks.js
----------------------------------------------------------------------
diff --git a/src/activetasks.js b/src/activetasks.js
new file mode 100644
index 0000000..56caa04
--- /dev/null
+++ b/src/activetasks.js
@@ -0,0 +1,107 @@
+import nmo from './nmo.js';
+import Wreck from 'wreck';
+import Promise from 'bluebird';
+import log from 'npmlog';
+import prettyjson from 'prettyjson';
+import {getUrlFromCluster, validUrl, removeUsernamePw } from './utils';
+
+export function cli (cluster, filter) {
+  return new Promise((resolve, reject) => {
+    if (!cluster) {
+      const msg = [
+        'Usage:',
+        '',
+        'nmo activetasks <cluster> [<filter>] [--json]',
+        'nmo activetasks <url> [<filter>] [--json]'
+      ].join('\n');
+
+      const err = new Error(msg);
+      err.type = 'EUSAGE';
+      return reject(err);
+    }
+
+    getActiveTask(cluster, filter).then(tasks => {
+      const jsonOut = nmo.config.get('json');
+
+      if (jsonOut) {
+        console.log(tasks);
+      } else {
+        if (tasks.length === 0) {
+          if (filter) {
+            console.log('There are no active tasks for that filter.');
+          } else {
+            console.log('There are no active tasks at the moment.');
+          }
+        } else {
+          console.log('Active Tasks:');
+          console.log(prettyjson.render(tasks));
+        }
+      }
+
+      resolve(tasks);
+    }).catch(err => {
+      reject(err);
+    });
+  });
+}
+
+export function filterTasks (tasks, searchTerm) {
+  if (!searchTerm) {
+    return tasks;
+  }
+
+  return tasks.filter(task => {
+    if (task.type === searchTerm) {
+      return true;
+    }
+
+    var regex = new RegExp(searchTerm, 'g');
+
+    const databaseValues = ['database', 'source', 'target'].reduce((sum, field) => {
+      if (task[field]) {
+        sum += task[field];
+      }
+
+      return sum;
+    }, '');
+
+    return regex.test(databaseValues);
+  });
+}
+
+export default function getActiveTask (cluster, filter) {
+  return new Promise((resolve, reject) => {
+    // `cluster` argument can be a cluster or a url.
+    // This function checks that and returns an appropriate url
+    const url = getUrlFromCluster(cluster);
+
+    let er = validUrl(url);
+
+    if (er) {
+      er.type = 'EUSAGE';
+      return reject(er);
+    }
+
+    const activetasksUrl = url + '/_active_tasks';
+    const cleanedUrl = removeUsernamePw(url);
+    log.http('request', 'GET', cleanedUrl);
+
+    Wreck.get(activetasksUrl, (err, res, payload) => {
+      if (err) {
+        if (err.code === 'ECONNREFUSED' || err.code === 'ENOTFOUND') {
+          const noNodeErr = new Error('Could not connect to ' + activetasksUrl +
+            ' this could mean the node is down.');
+          noNodeErr.type = 'EUSAGE';
+          return reject(noNodeErr);
+        }
+
+        err.type = 'EUSAGE';
+        return reject(err);
+      }
+
+      log.http(res.statusCode, cleanedUrl);
+      const tasks = filterTasks(JSON.parse(payload), filter);
+      resolve(tasks);
+    });
+  });
+}

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/src/cluster.js
----------------------------------------------------------------------
diff --git a/src/cluster.js b/src/cluster.js
index 91271c6..de27447 100644
--- a/src/cluster.js
+++ b/src/cluster.js
@@ -2,9 +2,7 @@ import * as config from './config.js';
 import nmo from './nmo.js';
 import isonline from './isonline.js';
 
-import xtend from 'xtend';
 import Promise from 'bluebird';
-import log from 'npmlog';
 
 import * as utils from './utils';
 import url from 'url';
@@ -32,7 +30,7 @@ export function cli (cmd, ...args) {
   }
 
   return cmdCommands[cmd].apply(exports[cmd], args);
-};
+}
 
 function joinCli (cluster) {
   return new Promise((resolve, reject) => {

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/src/config.js
----------------------------------------------------------------------
diff --git a/src/config.js b/src/config.js
index 1af6317..3a49411 100644
--- a/src/config.js
+++ b/src/config.js
@@ -3,11 +3,8 @@ import ini from 'ini';
 import xtend from 'xtend';
 import Promise from 'bluebird';
 
-import nmo from './nmo.js';
-
 let cfg;
 
-
 export function cli (cmd, ...args) {
   if (!cmd) {
     return cliGet();
@@ -31,7 +28,7 @@ export function cli (cmd, ...args) {
   }
 
   return exports[cmd].apply(exports[cmd], args);
-};
+}
 
 export const load = function load (nopts = {nmoconf: '.nmorc'}) {
   return new Promise((resolve, reject) => {
@@ -76,8 +73,7 @@ export function get (section, key) {
   }
 
   return res;
-};
-
+}
 
 export function cliGet (section, key) {
   return new Promise((resolve, reject) => {
@@ -86,10 +82,10 @@ export function cliGet (section, key) {
 
     return resolve(res);
   });
-};
+}
 
 export function handleResult (data, key) {
-  const jsonOut = nmo.config.get('json');
+  let jsonOut = cfg.get('json');
 
   if (typeof data === 'string') {
     if (jsonOut) {
@@ -115,4 +111,4 @@ export function handleResult (data, key) {
   console.log(parsed);
 
   return data;
-};
+}

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/src/couch-config.js
----------------------------------------------------------------------
diff --git a/src/couch-config.js b/src/couch-config.js
index 676e386..e5070b8 100644
--- a/src/couch-config.js
+++ b/src/couch-config.js
@@ -4,7 +4,8 @@ import Wreck from 'wreck';
 import Promise from 'bluebird';
 import prettyjson from 'prettyjson';
 import nmo from './nmo.js';
-import isonline, { getClusterUrls } from './isonline.js';
+import isonline from './isonline.js';
+import { getClusterUrls } from './utils.js';
 
 export function cli (cmd, cluster, section, key, value) {
   return new Promise((resolve, reject) => {

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/src/isonline.js
----------------------------------------------------------------------
diff --git a/src/isonline.js b/src/isonline.js
index 5fbce1d..baf3ae3 100644
--- a/src/isonline.js
+++ b/src/isonline.js
@@ -3,6 +3,7 @@ import log from 'npmlog';
 import Wreck from 'wreck';
 import Promise from 'bluebird';
 import nmo from './nmo.js';
+import { getClusterUrls } from './utils';
 
 
 export const cli = isOnlineCli;
@@ -41,16 +42,6 @@ function isOnlineCli (...urls) {
   });
 }
 
-export function getClusterUrls (clusterName) {
-  const nodes = nmo.config.get(clusterName);
-  if (!nodes) {
-    const err = new Error('Cluster does not exist');
-    err.type = 'EUSAGE';
-    throw err;
-  }
-  return Object.keys(nodes).map(key => nodes[key]);
-}
-
 export default isonline;
 function isonline (...args) {
   return new Promise((resolve, reject) => {

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/src/nmo.js
----------------------------------------------------------------------
diff --git a/src/nmo.js b/src/nmo.js
index 60309e6..7d6a2e0 100644
--- a/src/nmo.js
+++ b/src/nmo.js
@@ -1,6 +1,10 @@
+//This needs to go here so that the polyfill
+//is used when the cli loads and the tests
+require('babel/polyfill');
+
 import * as config from './config.js';
 import Promise from 'bluebird';
-import pkg from '../package.json'
+import pkg from '../package.json';
 
 const commands = [
   'isonline',
@@ -9,13 +13,17 @@ const commands = [
   'cluster',
   'v',
   'import-csv',
-  'couch-config'
+  'couch-config',
+  'activetasks'
 ];
 
 const nmo = {
   config: null
 };
 
+nmo.version = pkg.version;
+const commandFuncs = {}, cliFuncs = {};
+
 Object.defineProperty(nmo, 'commands', {
   get: () => {
     if (nmo.config === null) {
@@ -34,9 +42,6 @@ Object.defineProperty(nmo, 'cli', {
   }
 });
 
-nmo.version = pkg.version;
-
-const commandFuncs = {}, cliFuncs = {};
 nmo.load = function load (opts) {
   return new Promise((resolve, reject) => {
     config

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/src/utils.js
----------------------------------------------------------------------
diff --git a/src/utils.js b/src/utils.js
index a0ad1db..2f4fc38 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -7,6 +7,7 @@ import Wreck from 'wreck';
 import Promise from 'bluebird';
 import log from 'npmlog';
 import url from 'url';
+import nmo from './nmo';
 
 export function validUrl (url) {
   let er = checkUrl(url);
@@ -69,3 +70,23 @@ export function removeUsernamePw (u) {
   parsed.auth = parsed.auth ? parsed.auth.replace(/.*:.*/, 'USER:PW') : parsed.auth;
   return url.format(parsed);
 }
+
+export function getUrlFromCluster(clusterName) {
+  const err = validUrl(clusterName);
+
+  if (err === null) {
+    return clusterName;
+  }
+
+  return getClusterUrls(clusterName)[0];
+}
+
+export function getClusterUrls (clusterName) {
+  const nodes = nmo.config.get(clusterName);
+  if (!nodes) {
+    const err = new Error('Cluster does not exist');
+    err.type = 'EUSAGE';
+    throw err;
+  }
+  return Object.keys(nodes).map(key => nodes[key]);
+}

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/activetasks.js
----------------------------------------------------------------------
diff --git a/test/activetasks.js b/test/activetasks.js
new file mode 100644
index 0000000..3cdd348
--- /dev/null
+++ b/test/activetasks.js
@@ -0,0 +1,216 @@
+import assert from 'assert';
+import nock from 'nock';
+import Lab from 'lab';
+export const lab = Lab.script();
+import { createConfigFile } from './common';
+
+import nmo from '../src/nmo.js';
+import getActiveTask, { filterTasks, cli }  from '../src/activetasks.js';
+
+lab.experiment('activetasks', () => {
+  createConfigFile();
+  lab.beforeEach((done) => {
+    nmo
+      .load({nmoconf: __dirname + '/fixtures/randomini'})
+      .then(() => done())
+      .catch(() => done());
+  });
+
+  lab.experiment('cli', () => {
+    const oldConsole = console.log;
+
+    lab.afterEach(done => {
+      console.log = oldConsole;
+      done();
+    });
+
+    lab.test('no arguments', done => {
+      cli().catch(err => {
+        assert.ok(/Usage/.test(err.message));
+        done();
+      });
+    });
+
+    lab.test('does json', done => {
+      nock('http://127.0.0.11')
+        .get('/_active_tasks')
+        .reply(200, []);
+
+      console.log = msg => {
+        assert.deepEqual(msg, []);
+        done();
+      };
+
+      nmo
+        .load({nmoconf: __dirname + '/fixtures/randomini', json: true})
+        .then(() => {
+          cli('http://127.0.0.11');
+        });
+
+    });
+
+    lab.test('rejests errors', done => {
+      cli('http://127.0.0.11')
+      .catch(err => {
+        assert.ok(err);
+        done();
+      });
+    });
+
+    lab.test('Not existing cluster', (done) => {
+
+      cli('wrong').catch(err => {
+        assert.ok(/Cluster does not exist/.test(err.message));
+        done();
+      });
+    });
+
+    lab.test('returns no active tasks for filter', done => {
+      console.log = function (msg) {
+        assert.ok(/for that filter/.test(msg));
+        done();
+      };
+
+      nock('http://127.0.0.11')
+        .get('/_active_tasks')
+        .reply(200, []);
+
+      cli('http://127.0.0.11', 'filter');
+    });
+
+
+    lab.test('returns no active tasks', done => {
+      console.log = function (msg) {
+        assert.ok(/There are no active tasks/.test(msg));
+        done();
+      };
+
+      nock('http://127.0.0.11')
+        .get('/_active_tasks')
+        .reply(200, []);
+
+      cli('http://127.0.0.11');
+    });
+
+    lab.test('returns active tasks', done => {
+      const resp = `[{"node":"node1@127.0.0.1","pid":"<0.8331.5>",
+                    "changes_pending":null,"checkpoint_interval":5000,
+                    "checkpointed_source_seq":"1234",
+                    "continuous":true,"database":null,
+                    "doc_id":null,"doc_write_failures":0,"docs_read":44,
+                    "docs_written":44,"missing_revisions_found":44,
+                    "replication_id":"123123123",
+                    "revisions_checked":44,
+                    "source":"http://127.0.0.1:15984/mango-query/",
+                    "source_seq":"1231",
+                    "started_on":1444135320,
+                    "target":"http://127.0.0.1:15984/test-mango/",
+                    "through_seq":"12313","type":"replication",
+                    "updated_on":1444135325,"user":null}]`;
+
+      nock('http://127.0.0.11')
+        .get('/_active_tasks')
+        .reply(200, resp);
+
+      console.log = msg => {
+        if (!/Active/.test(msg)) { return; }
+
+        assert.ok(/Active Tasks:/.test(msg));
+        done();
+      };
+
+      cli('http://127.0.0.11');
+    });
+
+  });
+
+
+
+  lab.experiment('getActiveTask', () => {
+
+    lab.test('rejects for invalid url', done => {
+
+      getActiveTask('hhhh')
+        .catch(err => {
+          assert.deepEqual(err.type, 'EUSAGE');
+          done();
+        });
+    });
+
+    lab.test('returns error for bad connections', done => {
+
+      getActiveTask('http://127.1.1.10')
+      .catch(err => {
+        console.log('ERR', err);
+        assert.ok(/Could not connect/.test(err.message));
+        done();
+      });
+
+    });
+
+    lab.test('returns active tasks info', done => {
+      const resp = `[{"node":"node1@127.0.0.1","pid":"<0.8331.5>",
+                    "changes_pending":null,"checkpoint_interval":5000,
+                    "checkpointed_source_seq":"1234",
+                    "continuous":true,"database":null,
+                    "doc_id":null,"doc_write_failures":0,"docs_read":44,
+                    "docs_written":44,"missing_revisions_found":44,
+                    "replication_id":"123123123",
+                    "revisions_checked":44,
+                    "source":"http://127.0.0.1:15984/mango-query/",
+                    "source_seq":"1231",
+                    "started_on":1444135320,
+                    "target":"http://127.0.0.1:15984/test-mango/",
+                    "through_seq":"12313","type":"replication",
+                    "updated_on":1444135325,"user":null}]`;
+
+      nock('http://127.0.0.11')
+        .get('/_active_tasks')
+        .reply(200, resp);
+
+      getActiveTask('http://127.0.0.11')
+      .then(activetasks => {
+        assert.deepEqual(activetasks, JSON.parse(resp));
+        done();
+      });
+    });
+  });
+
+  lab.experiment('filterTasks', () => {
+    const tasks = [
+      {
+        type: 'replication',
+        target: 'mydatabase'
+      },
+      {
+        type: 'view_compaction',
+        target: 'another-db'
+      },
+      {
+        type: 'indexer',
+        source: 'mydatabase'
+      },
+    ];
+
+    lab.test('for no filter returns', done => {
+      const filtered = filterTasks(tasks);
+      assert.deepEqual(tasks, filtered);
+      done();
+    });
+
+    lab.test('only returns for filtered type', done => {
+      const filtered = filterTasks(tasks, 'replication');
+      assert.deepEqual(filtered.length, 1);
+      assert.deepEqual(filtered[0].type, 'replication');
+      done();
+    });
+
+    lab.test('returns filter for database', done => {
+      const filtered = filterTasks(tasks, 'mydatabase');
+      assert.deepEqual(filtered.length, 2);
+      assert.deepEqual(filtered[0].target, 'mydatabase');
+      done();
+    });
+  });
+
+});

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/cluster.js
----------------------------------------------------------------------
diff --git a/test/cluster.js b/test/cluster.js
index 950b412..adc741f 100644
--- a/test/cluster.js
+++ b/test/cluster.js
@@ -1,216 +1,274 @@
 import assert from 'assert';
+import nock from 'nock';
 
 import Lab from 'lab';
 export const lab = Lab.script();
 
 import * as cluster from '../src/cluster.js';
 import nmo from '../src/nmo.js';
-import * as common from './common.js';
+import {createConfigFile} from './common.js';
 
-import fs from 'fs';
 
-const data = `[clusterone]
-node0=http://127.0.0.1
-node1=http://192.168.0.1
-
-[onenodecluster]
-node1=iamalonelylnode
-
-[clustervalidurlsbothdown]
-node0=http:\/\/neverexists.neverexists
-node1=http:\/\/neverexists2.neverexists
-
-[clustervalidurlsonedown]
-node1=http:\/\/neverexists2.neverexists
-node2=${common.NODE}
-
-[clustervalidurls]
-node1=${common.NODE}
-node2=${common.NODE_TWO}
-
-[clustervalidurlswithpw]
-node1=${common.NODE_WITH_PW}
-node2=${common.NODE_TWO_WITH_PW}
-`;
 
 const nmoconf = {nmoconf: __dirname + '/fixtures/randomini'};
 const oldConsole = console.log;
 
 lab.experiment('cluster - get', () => {
-  fs.writeFileSync(__dirname + '/fixtures/randomini', data, 'utf-8');
+
+  lab.beforeEach((done) => {
+    createConfigFile();
+    nmo
+      .load(nmoconf)
+      .then(() => done())
+      .catch(() => done());
+  });
 
   lab.test('errors on nmoconf', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .get('nmoconfig')
-        .catch((err) => {
-          assert.ok(/valid/.test(err.message));
-          done();
-        });
-    });
+    cluster
+      .get('nmoconfig')
+      .catch((err) => {
+        assert.ok(/valid/.test(err.message));
+        done();
+      });
   });
 
   lab.test('returns the clustername', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .get('clusterone', 'node0')
-        .then((res) => {
-          assert.equal(res, 'http://127.0.0.1');
-          done();
-        });
+    cluster
+      .get('clusterone', 'node0')
+      .then((res) => {
+        assert.equal(res, 'http://127.0.0.1');
+        done();
+      });
     });
-  });
 });
 
 lab.experiment('cluster - add', () => {
-  fs.writeFileSync(__dirname + '/fixtures/randomini', data, 'utf-8');
+
+  lab.beforeEach((done) => {
+    createConfigFile();
+    nmo
+      .load(nmoconf)
+      .then(() => done())
+      .catch(() => done());
+  });
 
   lab.test('errors on empty args', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .add()
-        .catch((err) => {
-          assert.ok(/provide/.test(err.message));
-          done();
-        });
-    });
+    cluster
+      .add()
+      .catch((err) => {
+        assert.ok(/provide/.test(err.message));
+        done();
+      });
   });
 
   lab.test('errors on nmoconf', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .add('foo', 'bar', 'nmoconfig')
-        .catch((err) => {
-          assert.ok(/valid/.test(err.message));
-          done();
-        });
-    });
+    cluster
+      .add('foo', 'bar', 'nmoconfig')
+      .catch((err) => {
+        assert.ok(/valid/.test(err.message));
+        done();
+      });
   });
 
   lab.test('adds cluster', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .add('rockbert', 'artischockbert', 'foocluster')
-        .then((res) => {
-          cluster
-            .get('foocluster')
-            .then((res) => {
-              assert.deepEqual(res, {rockbert: 'artischockbert'});
-              done();
-            });
-        });
-    });
+    cluster
+      .add('rockbert', 'artischockbert', 'foocluster')
+      .then((res) => {
+        cluster
+          .get('foocluster')
+          .then((res) => {
+            assert.deepEqual(res, {rockbert: 'artischockbert'});
+            done();
+          });
+      });
   });
 
 });
 
 lab.experiment('cluster - join', () => {
 
-  let servers;
-
   lab.beforeEach((done) => {
-    fs.writeFileSync(__dirname + '/fixtures/randomini', data, 'utf-8');
-    common.createTestServers().done((s) => {
-      servers = s;
-      done();
-    });
-  });
+    createConfigFile();
+    nmo
+      .load(nmoconf)
+      .then(() => done())
+      .catch(() => done());
 
-  lab.afterEach((done) => {
-    common.stopTestServers(servers).then((res) => {
-      done();
-    });
   });
 
   lab.test('errors on empty args', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join()
-        .catch((err) => {
-          assert.ok(/Usage/.test(err.message));
-          done();
-        });
-    });
+    cluster
+      .join()
+      .catch((err) => {
+        assert.ok(/Usage/.test(err.message));
+        done();
+      });
   });
 
   lab.test('errors on nmoconf', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join('nmoconfig')
-        .catch((err) => {
-          assert.ok(/valid/.test(err.message));
-          done();
-        });
-    });
+    cluster
+      .join('nmoconfig')
+      .catch((err) => {
+        assert.ok(/valid/.test(err.message));
+        done();
+      });
   });
 
   lab.test('errors on a cluster with no nodes', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join('doesnotexist')
-        .catch((err) => {
-          assert.ok(/any nodes/.test(err.message));
-          done();
-        });
-    });
+    cluster
+      .join('doesnotexist')
+      .catch((err) => {
+        assert.ok(/any nodes/.test(err.message));
+        done();
+      });
   });
 
   lab.test('errors on cluster with 1 node', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join('onenodecluster')
-        .catch((err) => {
-          assert.ok(/enough nodes/.test(err.message));
-          done();
-        });
-    });
+    cluster
+      .join('onenodecluster')
+      .catch((err) => {
+        assert.ok(/enough nodes/.test(err.message));
+        done();
+      });
   });
 
-  lab.test('warns on offline node', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join('clustervalidurlsbothdown')
-        .catch((err) => {
-          assert.ok(/nodes are/.test(err.message));
-          done();
-        });
-    });
+  lab.test('warns on offline nodes', (done) => {
+    nock('http://neverexists.neverexists')
+      .get('/')
+      .reply(500);
+
+    nock('http://neverexists.neverexists')
+      .get('/')
+      .reply(500);
+
+    cluster
+      .join('clustervalidurlsbothdown')
+      .catch((err) => {
+        assert.ok(/nodes are/.test(err.message));
+        done();
+      });
   });
 
-  lab.test('warns on offline nodes', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join('clustervalidurlsonedown')
-        .catch((err) => {
-          assert.ok(/node is/.test(err.message));
-          done();
-        });
-    });
+  lab.test('warns on offline node', (done) => {
+    nock('http://neverexists.neverexists')
+      .get('/')
+      .reply(500);
+
+    nock('http://127.0.0.1:1337')
+      .get('/')
+      .reply(200);
+
+    cluster
+      .join('clustervalidurlsonedown')
+      .catch((err) => {
+        assert.ok(/node is/.test(err.message));
+        done();
+      });
   });
 
   lab.test('succeeds at online nodes with pw', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join('clustervalidurlswithpw')
-        .then((res) => {
-          assert.deepEqual(res, { ok: true });
-          done();
-        });
-    });
+    nock('http://a:b@127.0.0.1:1337')
+      .get('/')
+      .reply(200);
+
+    nock('http://a:b@127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://a:b@127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://a:b@127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://a:b@127.0.0.1:1338')
+      .get('/')
+      .reply(200);
+
+    nock('http://a:b@127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://a:b@127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://a:b@127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    cluster
+      .join('clustervalidurlswithpw')
+      .then((res) => {
+        assert.deepEqual(res, { ok: true });
+        done();
+      });
   });
 
   lab.test('succeeds at online nodes', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .join('clustervalidurls')
-        .then((res) => {
-          assert.deepEqual(res, { ok: true });
-          done();
-        });
-    });
+    nock('http://127.0.0.1:1337')
+      .get('/')
+      .reply(200);
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1338')
+      .get('/')
+      .reply(200);
+
+    nock('http://127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    cluster
+      .join('clustervalidurls')
+      .then((res) => {
+        assert.deepEqual(res, { ok: true });
+        done();
+      });
   });
 
   lab.test('succeeds with offline nodes, but --force given', (done) => {
+    nock('http://127.0.0.1:1337')
+      .get('/')
+      .reply(200);
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('neverexists2.neverexists')
+      .get('/')
+      .reply(500);
+
     nmo.load({nmoconf: __dirname + '/fixtures/randomini', force: true}).then(() => {
       cluster
         .join('clustervalidurlsonedown')
@@ -226,76 +284,100 @@ lab.experiment('cluster - join', () => {
 
 lab.experiment('cluster - cli', () => {
 
-  let servers;
-
   lab.beforeEach((done) => {
-    fs.writeFileSync(__dirname + '/fixtures/randomini', data, 'utf-8');
-    common.createTestServers().done((s) => {
-      servers = s;
-      done();
-    });
+    createConfigFile();
+    nmo
+      .load(nmoconf)
+      .then(() => done())
+      .catch(() => done());
+
   });
 
   lab.afterEach((done) => {
     console.log = oldConsole;
-
-    common.stopTestServers(servers).then((res) => {
-      done();
-    });
+    done();
   });
 
   lab.test('adds cluster', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .cli('add', 'rockbert', 'artischockbert', 'foocluster2')
-        .then((res) => {
-          cluster
-            .get('foocluster2')
-            .then((res) => {
-              assert.deepEqual(res, {rockbert: 'artischockbert'});
-              done();
-            });
-        });
-    });
+    cluster
+      .cli('add', 'rockbert', 'artischockbert', 'foocluster2')
+      .then((res) => {
+        cluster
+          .get('foocluster2')
+          .then((res) => {
+            assert.deepEqual(res, {rockbert: 'artischockbert'});
+            done();
+          });
+      });
   });
 
   lab.test('gets cluster', (done) => {
     console.log = (...args) => {
-      assert.equal('rockbert=artischockbert\n', args[0]);
-      done();
+      if (/rockbert=artischockbert/.test(args[0])) {
+        assert.equal('rockbert=artischockbert\n', args[0]);
+        done();
+      }
     };
 
-    nmo.load(nmoconf).then(() => {
+    nmo.load({nmoconf: __dirname + '/fixtures/randomini' }).then(() => {
       cluster
         .cli('add', 'rockbert', 'artischockbert', 'foocluster3')
         .then((res) => {
           cluster
             .cli('get', 'foocluster3');
+          });
         });
-    });
   });
 
   lab.test('joins cluster', (done) => {
+    nock('http://127.0.0.1:1337')
+      .get('/')
+      .reply(200);
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1337')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1338')
+      .get('/')
+      .reply(200);
+
+    nock('http://127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
+    nock('http://127.0.0.1:1338')
+      .post('/_cluster_setup')
+      .reply(200, {ok: true});
+
     console.log = (...args) => {
       assert.equal('cluster joined', args[0]);
-      done()
+      done();
     };
 
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .cli('join', 'clustervalidurls');
-    });
+    cluster
+      .cli('join', 'clustervalidurls');
   });
 
   lab.test('returns error on wrong usage', (done) => {
-    nmo.load(nmoconf).then(() => {
-      cluster
-        .cli('lalala')
-    })
-    .catch((err) => {
+    try {
+      cluster.cli('lalala');
+    } catch(err) {
       assert.ok(err instanceof Error);
       done();
-    });
+    }
   });
 
 });

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/common.js
----------------------------------------------------------------------
diff --git a/test/common.js b/test/common.js
index c0ff48b..bf9824f 100644
--- a/test/common.js
+++ b/test/common.js
@@ -1,5 +1,4 @@
-import http from 'http';
-import Promise from 'bluebird';
+import fs from 'fs';
 
 export const PORT = 1337;
 export const PORT_TWO = 1338;
@@ -11,29 +10,30 @@ export const NODE_TWO = 'http://127.0.0.1:' + PORT_TWO;
 export const NODE_WITH_PW = 'http://a:b@127.0.0.1:' + PORT;
 export const NODE_TWO_WITH_PW = 'http://a:b@127.0.0.1:' + PORT_TWO;
 
-export function createTestServers () {
-  const promises = [PORT, PORT_TWO].map((port) => {
-    return createTestServer(port);
-  });
+const data = `[clusterone]
+node0=http://127.0.0.1
+node1=http://192.168.0.1
 
-  return Promise.all(promises);
-}
+[onenodecluster]
+node1=iamalonelylnode
 
-export function stopTestServers (servers) {
-  const s = servers.map((s) => {
-    const close = Promise.promisify(s.close).bind(s);
-    return close();
-  });
-  return Promise.all(s);
-}
+[clustervalidurlsbothdown]
+node0=http:\/\/neverexists.neverexists
+node1=http:\/\/neverexists2.neverexists
+
+[clustervalidurlsonedown]
+node1=http:\/\/neverexists2.neverexists
+node2=${NODE}
+
+[clustervalidurls]
+node1=${NODE}
+node2=${NODE_TWO}
 
-export function createTestServer (port) {
-  let i = 0;
-  return new Promise((resolve) => {
-    const s = http.createServer((req, res) => {
+[clustervalidurlswithpw]
+node1=${NODE_WITH_PW}
+node2=${NODE_TWO_WITH_PW}
+`;
 
-      res.writeHead(200, {'Content-Type': 'application/json'});
-      res.end(JSON.stringify({ok: true}));
-    }).listen(port, '127.0.0.1', () => { resolve(s); });
-  });
+export function createConfigFile () {
+  fs.writeFileSync(__dirname + '/fixtures/randomini', data, 'utf-8');
 }

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/config.js
----------------------------------------------------------------------
diff --git a/test/config.js b/test/config.js
index 19df52d..5894ab4 100644
--- a/test/config.js
+++ b/test/config.js
@@ -4,12 +4,10 @@ import Lab from 'lab';
 export const lab = Lab.script();
 
 import * as config from '../src/config.js';
-import nmo from '../src/nmo.js';
 
 import ini from 'ini';
 import fs from 'fs';
 
-
 const data = `[clusterone]
 node0=http://127.0.0.1
 node1=http://192.168.0.1
@@ -137,7 +135,7 @@ lab.experiment('config', () => {
 
     lab.test('returns the whole config as JSON', (done) => {
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           const result = config.get();
           assert.deepEqual(jsonData, result);
@@ -147,7 +145,7 @@ lab.experiment('config', () => {
 
     lab.test('will get sections as JSON', (done) => {
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           const result = config.get('gang');
           assert.deepEqual(jsonData.gang, result);
@@ -157,7 +155,7 @@ lab.experiment('config', () => {
 
     lab.test('will get keys', (done) => {
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           const result = config.get('gang', 'rocko');
           assert.equal(jsonData.gang.rocko, result);
@@ -180,7 +178,7 @@ lab.experiment('config', () => {
 
    lab.test('it can get the whole config', (done) => {
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           config.cli().then((result) => {
             assert.deepEqual(jsonData, result);
@@ -195,7 +193,7 @@ lab.experiment('config', () => {
         assert.equal(data, args[0]);
       };
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           config.cli('get').then((result) => {
             done();
@@ -207,19 +205,18 @@ lab.experiment('config', () => {
 
       console.log = (...args) => {
         assert.deepEqual(jsonData, args[0]);
+        done();
       };
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
+      config.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
         .then((res) => {
-          config.cli('get').then((result) => {
-            done();
-          });
+          config.cli('get');
         });
     });
 
     lab.test('it can handle sections in the config', (done) => {
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           config.cli('get', 'gang').then((result) => {
             assert.deepEqual(jsonData.gang, result);
@@ -234,7 +231,7 @@ lab.experiment('config', () => {
         assert.equal(gangConf, args[0]);
       };
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           config.cli('get', 'gang').then((result) => {
             done();
@@ -244,7 +241,7 @@ lab.experiment('config', () => {
 
     lab.test('it can handle sections with keys in the config', (done) => {
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
+      config.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
         .then((res) => {
           config.cli('get', 'gang', 'rocko').then((result) => {
             assert.deepEqual({rocko: 'artischocko'}, result);
@@ -259,7 +256,7 @@ lab.experiment('config', () => {
         assert.equal('artischocko', args[0]);
       };
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           config.cli('get', 'gang', 'rocko').then((result) => {
             done();
@@ -273,7 +270,7 @@ lab.experiment('config', () => {
         assert.deepEqual({rocko: 'artischocko'}, args[0]);
       };
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
+      config.load({nmoconf: __dirname + '/fixtures/randomini', json: true})
         .then((res) => {
           config.cli('get', 'gang', 'rocko').then((result) => {
             done();
@@ -283,7 +280,7 @@ lab.experiment('config', () => {
 
     lab.test('saves a value', (done) => {
 
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then((res) => {
           config.cli('set', 'cluster1337', 'node1337', '192.168.133.7').then((e) => {
             const c = ini.parse(fs.readFileSync(__dirname + '/fixtures/randomini', 'utf-8'));
@@ -296,7 +293,7 @@ lab.experiment('config', () => {
     });
 
     lab.test('returns error on wrong usage', (done) => {
-      nmo.load({nmoconf: __dirname + '/fixtures/randomini'})
+      config.load({nmoconf: __dirname + '/fixtures/randomini'})
         .then(() => {
 
           config
@@ -308,5 +305,4 @@ lab.experiment('config', () => {
         });
     });
   });
-
 });

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/couch-config.js
----------------------------------------------------------------------
diff --git a/test/couch-config.js b/test/couch-config.js
index 68eabf7..1e56a84 100644
--- a/test/couch-config.js
+++ b/test/couch-config.js
@@ -3,10 +3,13 @@ import assert from 'assert';
 import Lab from 'lab';
 export const lab = Lab.script();
 import nock from 'nock';
+import { createConfigFile } from './common';
 import nmo from '../src/nmo.js';
 import {cli, setConfig, getClusterNodes, buildConfigUrl, getConfig, get, set} from '../src/couch-config.js';
 
 lab.experiment('couch-config', () => {
+  createConfigFile();
+
   lab.beforeEach((done) => {
     nmo
       .load({nmoconf: __dirname + '/fixtures/randomini'})

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/help.js
----------------------------------------------------------------------
diff --git a/test/help.js b/test/help.js
index 38aec44..81e2180 100644
--- a/test/help.js
+++ b/test/help.js
@@ -3,6 +3,7 @@ import assert from 'assert';
 import Lab from 'lab';
 export const lab = Lab.script();
 
+import { createConfigFile } from './common';
 import help from '../src/help.js';
 import {cli} from '../src/help.js';
 
@@ -11,6 +12,7 @@ import {load} from '../src/nmo.js';
 const oldConsole = console.log;
 
 lab.experiment('help', () => {
+  createConfigFile();
 
   lab.before((done) => {
     load({nmoconf: __dirname + '/fixtures/randomini'}).then(() => {

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/import-csv.js
----------------------------------------------------------------------
diff --git a/test/import-csv.js b/test/import-csv.js
index c86eb18..4bc24aa 100644
--- a/test/import-csv.js
+++ b/test/import-csv.js
@@ -3,6 +3,7 @@ import assert from 'assert';
 import Lab from 'lab';
 export const lab = Lab.script();
 import nock from 'nock';
+import { createConfigFile } from './common';
 import nmo from '../src/nmo.js';
 import {cli} from '../src/import-csv.js';
 import importcsv from '../src/import-csv.js';
@@ -22,6 +23,7 @@ const docs = {
   ]};
 
 lab.experiment('import csv', () => {
+  createConfigFile();
   lab.beforeEach((done) => {
     nmo
       .load({nmoconf: __dirname + '/fixtures/randomini'})

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/isonline.js
----------------------------------------------------------------------
diff --git a/test/isonline.js b/test/isonline.js
index aa9cc5a..3ad645e 100644
--- a/test/isonline.js
+++ b/test/isonline.js
@@ -11,27 +11,24 @@ import nock from 'nock';
 
 export let lab = Lab.script();
 const oldConsole = console.log;
+const nmoconf = {nmoconf: __dirname + '/fixtures/randomini'};
 
-lab.experiment('isonline', () => {
+common.createConfigFile();
 
-  let servers, conf;
+lab.experiment('isonline', () => {
 
   lab.experiment('cli', () => {
     lab.beforeEach((done) => {
-      conf = {nmoconf: __dirname + '/fixtures/randomini'};
+      nmo
+        .load(nmoconf)
+        .then(() => done())
+        .catch(() => done());
 
-      common.createTestServers().done((s) => {
-        servers = s;
-        done();
-      });
     });
 
     lab.afterEach((done) => {
       console.log = oldConsole;
-
-      common.stopTestServers(servers).then((res) => {
-        done();
-      });
+      done();
     });
 
     lab.test('returns error on no value provided', (done) => {
@@ -51,11 +48,8 @@ lab.experiment('isonline', () => {
         .get('/')
         .reply(200);
 
-      nmo
-        .load({nmoconf: __dirname + '/fixtures/randomini', json: true})
-        .then(() => {
-          return cli('clusterone');
-        }).then(res => {
+      cli('clusterone')
+        .then(res => {
           assert.deepEqual(res, {'http://127.0.0.1': true, 'http://192.168.0.1': true });
           done();
         });
@@ -97,41 +91,20 @@ lab.experiment('isonline', () => {
   });
 
   lab.experiment('api', () => {
+    //I'm worried these before's are not actually running
     lab.beforeEach((done) => {
-      conf = {nmoconf: __dirname + '/fixtures/randomini'};
-
-      common.createTestServers().done((s) => {
-        servers = s;
-        done();
-      });
-    });
-
-    lab.afterEach((done) => {
-      console.log = oldConsole;
-
-      common.stopTestServers(servers).then((res) => {
-        done();
-      });
-    });
-
-    lab.test('getClustersUrl returns correct urls', (done) => {
       nmo
-        .load({nmoconf: __dirname + '/fixtures/randomini'})
+        .load(nmoconf)
         .then(() => {
-          const urls = getClusterUrls('clusterone');
-          assert.deepEqual(['http://127.0.0.1', 'http://192.168.0.1'], urls);
           done();
-        });
+        })
+        .catch(() => done());
+      });
     });
 
-    lab.test("getClustersUrl throws an error if the cluster doesn't exist", (done) => {
-        try {
-          getClusterUrls('doesnt-exist');
-        } catch(e) {
-          assert.ok(/Cluster does not exist/.test(e.message));
-          done();
-        }
-
+    lab.afterEach((done) => {
+      console.log = oldConsole;
+      done();
     });
 
     lab.test('returns error for all other errors', (done) => {
@@ -167,6 +140,10 @@ lab.experiment('isonline', () => {
     });
 
     lab.test('returns true for online site', (done) => {
+      nock(common.NODE)
+        .get('/')
+        .reply(200);
+
       isonline(common.NODE)
         .then((res) => {
           assert.deepEqual(res, {[common.NODE]: true});
@@ -175,6 +152,14 @@ lab.experiment('isonline', () => {
     });
 
     lab.test('accepts multiple sites and options', (done) => {
+      nock(common.NODE)
+        .get('/')
+        .reply(200);
+
+      nock(common.NODE_TWO)
+        .get('/')
+        .reply(200);
+
       nmo
         .load({nmoconf: __dirname + '/fixtures/randomini', json: true})
         .then(() => {
@@ -187,25 +172,22 @@ lab.experiment('isonline', () => {
           });
         });
     });
-  });
 
   lab.experiment('cli', () => {
     lab.beforeEach((done) => {
-      conf = {nmoconf: __dirname + '/fixtures/randomini'};
-
-      common.createTestServers().done((s) => {
-        servers = s;
-        done();
-      });
+      done();
     });
+
     lab.afterEach((done) => {
       console.log = oldConsole;
-
-      common.stopTestServers(servers).then((res) => {
-        done();
-      });
+      done();
     });
+
     lab.test('returns online for online nodes', (done) => {
+      nock(common.NODE)
+        .get('/')
+        .reply(200);
+
       console.log = (...args) => {
         assert.ok(/online/.test(args[1]), 'returns online for online nodes');
         done();
@@ -228,6 +210,9 @@ lab.experiment('isonline', () => {
     });
 
     lab.test('can output json', (done) => {
+      nock(common.NODE)
+        .get('/')
+        .reply(200);
 
       console.log = (...args) => {
         assert.deepEqual({ [common.NODE]: true }, args[0]);

http://git-wip-us.apache.org/repos/asf/couchdb-nmo/blob/e95b93fd/test/utils.js
----------------------------------------------------------------------
diff --git a/test/utils.js b/test/utils.js
index c0dfa9f..7192f8f 100644
--- a/test/utils.js
+++ b/test/utils.js
@@ -1,5 +1,4 @@
 import assert from 'assert';
-import http from 'http';
 import nock from 'nock';
 
 import Lab from 'lab';
@@ -7,6 +6,10 @@ export const lab = Lab.script();
 
 import * as utils from '../src/utils.js';
 import * as common from './common.js';
+import nmo from '../src/nmo.js';
+
+const nmoconf = {nmoconf: __dirname + '/fixtures/randomini'};
+common.createConfigFile();
 
 lab.experiment('utils: validUrl', () => {
 
@@ -26,6 +29,48 @@ lab.experiment('utils: validUrl', () => {
 
 });
 
+lab.experiment('utils: getClusterUrls', () => {
+
+  lab.test('getClustersUrl returns correct urls', (done) => {
+    nmo
+      .load(nmoconf)
+      .then(() => {
+      const urls = utils.getClusterUrls('clusterone');
+      assert.deepEqual(['http://127.0.0.1', 'http://192.168.0.1'], urls);
+      done();
+    });
+  });
+
+  lab.test("getClustersUrl throws an error if the cluster doesn't exist", (done) => {
+    nmo
+      .load(nmoconf)
+      .then(() => {
+        return utils.getClusterUrls('doesnt-exist');
+      })
+      .catch(e => {
+        assert.ok(/Cluster does not exist/.test(e.message));
+        done();
+      });
+  });
+
+});
+
+lab.experiment('utils: getUrlFromCluster', () => {
+
+  lab.test('it returns url for url passed to it', done => {
+    const url = 'http://127.0.0.1';
+    const out = utils.getUrlFromCluster(url);
+    assert.deepEqual(url, out);
+    done();
+  });
+
+  lab.test('returns url for cluster', done => {
+    const out = utils.getUrlFromCluster('clusterone');
+    assert.deepEqual('http://127.0.0.1', out);
+    done();
+  });
+});
+
 lab.experiment('utils: uri', () => {
 
   lab.test('valid uri', (done) => {
@@ -60,22 +105,6 @@ lab.experiment('utils: checkUrl', () => {
 });
 
 lab.experiment('utils: send json to node', () => {
-  let data = '', server;
-
-  lab.before((done) => {
-    server = http.createServer((req, res) => {
-      res.writeHead(200, {'Content-Type': 'application/json'});
-
-      req.on('data', (chunk) => {
-        data += chunk;
-      });
-      res.end('{"msg": "hi rocko artischocko!"}');
-    }).listen(common.PORT, '127.0.0.1', done);
-  });
-
-  lab.after((done) => {
-    server.close(done);
-  });
 
   lab.test('returns error on no value provided', (done) => {
     utils
@@ -105,11 +134,14 @@ lab.experiment('utils: send json to node', () => {
   });
 
   lab.test('communicates with the server', (done) => {
+    nock('http://127.0.0.1:1337')
+      .post('/')
+      .reply(200, {ok: true, msg: 'hello'});
+
     utils
       .sendJsonToNode(common.NODE, {'ok': 'true'})
       .then((res) => {
-      assert.equal(data, '{"ok":"true"}');
-        assert.equal(res.msg, 'hi rocko artischocko!');
+        assert.equal(res.msg, 'hello');
         done();
       });
   });