@@ -96,7 +96,7 @@ describe("syncSpecsLogs", () => {
9696 expect ( options . columns [ 1 ] . alignment ) . to . equal ( 'center' ) ;
9797 expect ( options . columns [ 2 ] . alignment ) . to . equal ( 'left' ) ;
9898 expect ( options . columns [ 1 ] . width ) . to . equal ( 1 ) ;
99- expect ( options . columns [ 2 ] . width ) . to . equal ( 30 ) ;
99+ expect ( options . columns [ 2 ] . width ) . to . equal ( 50 ) ;
100100 expect ( options . columnCount ) . to . equal ( 3 ) ;
101101 expect ( getBorderConfigStub . calledOnce ) . to . be . true ;
102102 } ) ;
@@ -259,7 +259,60 @@ describe("syncSpecsLogs", () => {
259259 context ( "whileProcess" , ( ) => {
260260 const whileProcess = syncSpecsLogs . __get__ ( "whileProcess" ) ;
261261
262- it ( 'Should break the loop if request has error' , ( ) => {
262+ context ( 'network issue' , ( ) => {
263+ it ( 'Should retry when error is because of network issue' , ( ) => {
264+ let delayed_n = 2 , timeout = 3000 , n = 1 ;
265+ let error = new Error ( "error" ) ;
266+ error . code = "ETIMEDOUT" ;
267+
268+ let requestStub = sandbox . stub ( ) ;
269+
270+ let postStub = sandbox
271+ . stub ( request , "post" )
272+ . yields ( error , { statusCode : 502 } , JSON . stringify ( { } ) ) ;
273+
274+ requestStub . post = postStub ;
275+
276+ let setTimeout = sandbox . stub ( ) ;
277+ syncSpecsLogs . __set__ ( 'setTimeout' , setTimeout ) ;
278+ syncSpecsLogs . __set__ ( 'n' , n ) ;
279+ syncSpecsLogs . __set__ ( 'timeout' , timeout ) ;
280+ syncSpecsLogs . __set__ ( 'request' , requestStub ) ;
281+ syncSpecsLogs . __set__ ( 'whileTries' , 5 ) ;
282+
283+ let whilstCallback = sandbox . stub ( ) ;
284+ whileProcess ( whilstCallback ) ;
285+
286+ sinon . assert . calledWith ( setTimeout , whilstCallback , timeout * delayed_n , null ) ;
287+ expect ( syncSpecsLogs . __get__ ( "whileTries" ) ) . to . equal ( 4 ) ;
288+ } ) ;
289+
290+ it ( 'Should give-up on retry when error is b because of network issue after 5 retries and set proper exit code' , ( ) => {
291+ let error = new Error ( "error" ) , requestStub = sandbox . stub ( ) ;
292+ error . code = "ETIMEDOUT" ;
293+
294+ let postStub = sandbox
295+ . stub ( request , "post" )
296+ . yields ( error , { statusCode : 502 } , JSON . stringify ( { } ) ) ;
297+
298+ requestStub . post = postStub ;
299+
300+ syncSpecsLogs . __set__ ( 'request' , requestStub ) ;
301+ syncSpecsLogs . __set__ ( 'whileTries' , 1 ) ;
302+ syncSpecsLogs . __set__ ( 'specSummary' , { } ) ;
303+ syncSpecsLogs . __set__ ( 'whileLoop' , true ) ;
304+
305+ let whilstCallback = sandbox . stub ( ) ;
306+ whileProcess ( whilstCallback ) ;
307+
308+ sinon . assert . calledWith ( whilstCallback , { status : 504 , message : "Tries limit reached" } ) ;
309+ expect ( syncSpecsLogs . __get__ ( "whileTries" ) ) . to . equal ( 0 ) ;
310+ expect ( syncSpecsLogs . __get__ ( "whileLoop" ) ) . to . equal ( false ) ;
311+ expect ( syncSpecsLogs . __get__ ( "specSummary.exitCode" ) ) . to . equal ( 2 ) ;
312+ } ) ;
313+ } ) ;
314+
315+ it ( 'Should break the loop if request has error other than network issue' , ( ) => {
263316 let error = new Error ( "error" ) ;
264317 let requestStub = sandbox . stub ( ) ;
265318 let postStub = sandbox
0 commit comments