@@ -38,6 +38,11 @@ describe('Dash Service', function() {
3838 }
3939 } ;
4040
41+ var RPC_IN_WARMUP_ERROR = new Error ( 'Verifying blocks...' ) ;
42+ Object . assign ( RPC_IN_WARMUP_ERROR , {
43+ code : DashService . E_RPC_IN_WARMUP
44+ } )
45+
4146 describe ( '@constructor' , function ( ) {
4247 it ( 'will create an instance' , function ( ) {
4348 var dashd = new DashService ( baseConfig ) ;
@@ -1592,17 +1597,17 @@ describe('Dash Service', function() {
15921597 done ( ) ;
15931598 } ) ;
15941599 } ) ;
1595- it ( 'will log when error is RPC_IN_WARMUP' , function ( done ) {
1600+ it ( 'will throw when error is RPC_IN_WARMUP outside of retry ' , function ( done ) {
15961601 var dashd = new DashService ( baseConfig ) ;
1597- var getBestBlockHash = sinon . stub ( ) . callsArgWith ( 0 , { code : - 28 , message : 'Verifying blocks...' } ) ;
1602+ var getBestBlockHash = sinon . stub ( ) . callsArgWith ( 0 , RPC_IN_WARMUP_ERROR ) ;
15981603 var node = {
15991604 client : {
16001605 getBestBlockHash : getBestBlockHash
16011606 }
16021607 } ;
16031608 dashd . _loadTipFromNode ( node , function ( err ) {
16041609 err . should . be . instanceof ( Error ) ;
1605- log . warn . callCount . should . equal ( 1 ) ;
1610+ log . warn . callCount . should . equal ( 0 ) ;
16061611 done ( ) ;
16071612 } ) ;
16081613 } ) ;
@@ -1968,7 +1973,7 @@ describe('Dash Service', function() {
19681973 process . emit ( 'exit' , 1 ) ;
19691974 } ) ;
19701975 } ) ;
1971- it ( 'will give error after 60 retries' , function ( done ) {
1976+ it ( 'will give error after 60 retries of RPC_IN_WARMUP warning ' , function ( done ) {
19721977 var process = new EventEmitter ( ) ;
19731978 var spawn = sinon . stub ( ) . returns ( process ) ;
19741979 var TestDashService = proxyquire ( '../../lib/services/dashd' , {
@@ -1992,13 +1997,44 @@ describe('Dash Service', function() {
19921997 dashd . spawn . config . rpcpassword = 'password' ;
19931998 dashd . spawn . config . zmqpubrawtx = 'tcp://127.0.0.1:30001' ;
19941999 dashd . spawn . config . zmqpubrawtxlock = 'tcp://127.0.0.1:30001' ;
1995- dashd . _loadTipFromNode = sinon . stub ( ) . callsArgWith ( 1 , new Error ( 'test' ) ) ;
2000+ dashd . _loadTipFromNode = sinon . stub ( ) . callsArgWith ( 1 , RPC_IN_WARMUP_ERROR ) ;
19962001 dashd . _spawnChildProcess ( function ( err ) {
19972002 dashd . _loadTipFromNode . callCount . should . equal ( 60 ) ;
19982003 err . should . be . instanceof ( Error ) ;
19992004 done ( ) ;
20002005 } ) ;
20012006 } ) ;
2007+ it ( 'will give error WITHOUT retrying for fatal and unknown errors' , function ( done ) {
2008+ var process = new EventEmitter ( ) ;
2009+ var spawn = sinon . stub ( ) . returns ( process ) ;
2010+ var TestDashService = proxyquire ( '../../lib/services/dashd' , {
2011+ fs : {
2012+ readFileSync : readFileSync
2013+ } ,
2014+ child_process : {
2015+ spawn : spawn
2016+ }
2017+ } ) ;
2018+ var dashd = new TestDashService ( baseConfig ) ;
2019+ dashd . startRetryInterval = 1 ;
2020+ dashd . _loadSpawnConfiguration = sinon . stub ( ) ;
2021+ dashd . spawn = { } ;
2022+ dashd . spawn . exec = 'testexec' ;
2023+ dashd . spawn . configPath = 'testdir/dash.conf' ;
2024+ dashd . spawn . datadir = 'testdir' ;
2025+ dashd . spawn . config = { } ;
2026+ dashd . spawn . config . rpcport = 20001 ;
2027+ dashd . spawn . config . rpcuser = 'dash' ;
2028+ dashd . spawn . config . rpcpassword = 'password' ;
2029+ dashd . spawn . config . zmqpubrawtx = 'tcp://127.0.0.1:30001' ;
2030+ dashd . spawn . config . zmqpubrawtxlock = 'tcp://127.0.0.1:30001' ;
2031+ dashd . _loadTipFromNode = sinon . stub ( ) . callsArgWith ( 1 , new Error ( 'test' ) ) ;
2032+ dashd . _spawnChildProcess ( function ( err ) {
2033+ dashd . _loadTipFromNode . callCount . should . equal ( 1 ) ;
2034+ err . should . be . instanceof ( Error ) ;
2035+ done ( ) ;
2036+ } ) ;
2037+ } ) ;
20022038 it ( 'will give error from check reindex' , function ( done ) {
20032039 var process = new EventEmitter ( ) ;
20042040 var spawn = sinon . stub ( ) . returns ( process ) ;
@@ -2058,9 +2094,9 @@ describe('Dash Service', function() {
20582094 done ( ) ;
20592095 } ) ;
20602096 } ) ;
2061- it ( 'will give error from loadTipFromNode after 60 retries' , function ( done ) {
2097+ it ( 'will give error for warnings from loadTipFromNode after 60 retries' , function ( done ) {
20622098 var dashd = new DashService ( baseConfig ) ;
2063- dashd . _loadTipFromNode = sinon . stub ( ) . callsArgWith ( 1 , new Error ( 'test' ) ) ;
2099+ dashd . _loadTipFromNode = sinon . stub ( ) . callsArgWith ( 1 , RPC_IN_WARMUP_ERROR ) ;
20642100 dashd . startRetryInterval = 1 ;
20652101 var config = { } ;
20662102 dashd . _connectProcess ( config , function ( err ) {
@@ -2069,6 +2105,17 @@ describe('Dash Service', function() {
20692105 done ( ) ;
20702106 } ) ;
20712107 } ) ;
2108+ it ( 'will immediately fail from loadTipFromNode for fatal and unknown errors' , function ( done ) {
2109+ var dashd = new DashService ( baseConfig ) ;
2110+ dashd . _loadTipFromNode = sinon . stub ( ) . callsArgWith ( 1 , new Error ( 'test' ) ) ;
2111+ dashd . startRetryInterval = 1 ;
2112+ var config = { } ;
2113+ dashd . _connectProcess ( config , function ( err ) {
2114+ err . should . be . instanceof ( Error ) ;
2115+ dashd . _loadTipFromNode . callCount . should . equal ( 1 ) ;
2116+ done ( ) ;
2117+ } ) ;
2118+ } ) ;
20722119 it ( 'will init zmq/rpc on node' , function ( done ) {
20732120 var dashd = new DashService ( baseConfig ) ;
20742121 dashd . _initZmqSubSocket = sinon . stub ( ) ;
0 commit comments