From 2a53aad34a54ed6dbb5c4a5407620200c9f1fc0c Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Mon, 23 May 2016 16:19:18 -0400 Subject: [PATCH] test: add test for respawn bitcoind --- test/services/bitcoind.unit.js | 39 ++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/test/services/bitcoind.unit.js b/test/services/bitcoind.unit.js index 59964ed8..77060357 100644 --- a/test/services/bitcoind.unit.js +++ b/test/services/bitcoind.unit.js @@ -1376,6 +1376,7 @@ describe('Bitcoin Service', function() { var sandbox = sinon.sandbox.create(); beforeEach(function() { sandbox.stub(log, 'info'); + sandbox.stub(log, 'warn'); }); afterEach(function() { sandbox.restore(); @@ -1440,6 +1441,44 @@ describe('Bitcoin Service', function() { done(); }); }); + it('will respawn bitcoind spawned process', function(done) { + var process = new EventEmitter(); + var spawn = sinon.stub().returns(process); + var TestBitcoinService = proxyquire('../../lib/services/bitcoind', { + fs: { + readFileSync: readFileSync + }, + child_process: { + spawn: spawn + } + }); + var bitcoind = new TestBitcoinService(baseConfig); + bitcoind._loadSpawnConfiguration = sinon.stub(); + bitcoind.spawn = {}; + bitcoind.spawn.exec = 'bitcoind'; + bitcoind.spawn.datadir = '/tmp/bitcoin'; + bitcoind.spawn.configPath = '/tmp/bitcoin/bitcoin.conf'; + bitcoind.spawn.config = {}; + bitcoind.spawnRestartTime = 1; + bitcoind._loadTipFromNode = sinon.stub().callsArg(1); + bitcoind._initZmqSubSocket = sinon.stub(); + bitcoind._checkReindex = sinon.stub().callsArg(1); + bitcoind._checkSyncedAndSubscribeZmqEvents = sinon.stub(); + bitcoind._stopSpawnedBitcoin = sinon.stub().callsArg(0); + sinon.spy(bitcoind, '_spawnChildProcess'); + bitcoind._spawnChildProcess(function(err) { + if (err) { + return done(err); + } + process.once('exit', function() { + setTimeout(function() { + bitcoind._spawnChildProcess.callCount.should.equal(2); + done(); + }, 5); + }); + process.emit('exit', 1); + }); + }); it('will give error after 60 retries', function(done) { var process = new EventEmitter(); var spawn = sinon.stub().returns(process);