diff --git a/test/bash/resurrect.sh b/test/bash/resurrect.sh index f25d5325..b37abf58 100644 --- a/test/bash/resurrect.sh +++ b/test/bash/resurrect.sh @@ -6,13 +6,23 @@ cd $file_path $pm2 start echo.js -i 4 spec "should start 4 processes" +should 'should have 4 apps started' 'online' 4 + $pm2 save -spec "should save process list" -ls ~/.pm2/dump.pm2 -spec "should dump file exists" $pm2 resurrect -spec "should resurrect" +spec "should resurrect from dump" should 'should have still 4 apps started' 'online' 4 + +$pm2 save +$pm2 delete all +echo "[{" > ~/.pm2/dump.pm2 +$pm2 resurrect +spec "should resurrect from backup if dump is broken" +ls ~/.pm2/dump.pm2 +ispec "should delete broken dump" +should 'should have still 4 apps started' 'online' 4 + $pm2 delete all $pm2 resurrect +spec "should resurrect from backup if dump is missing" should 'should have still 4 apps started' 'online' 4 diff --git a/test/programmatic/misc_commands.js b/test/programmatic/misc_commands.js index a359a159..b0b7aa15 100644 --- a/test/programmatic/misc_commands.js +++ b/test/programmatic/misc_commands.js @@ -117,7 +117,7 @@ describe('Misc commands', function() { }); }); - it('should resurrect previous processes', function(done) { + it('should resurrect previous processes from dump', function(done) { pm2.resurrect(function(err, data) { should(err).be.null(); @@ -129,5 +129,62 @@ describe('Misc commands', function() { }); }); + it('should resurrect previous processes from backup if dump is broken', function(done) { + fs.writeFileSync(cst.DUMP_FILE_PATH, '[{'); + + pm2.resurrect(function(err, data) { + should(err).be.null(); + + pm2.list(function(err, procs) { + should(err).be.null(); + procs.length.should.eql(4); + done(); + }); + }); + }); + + it('should delete broken dump', function() { + should(fs.existsSync(cst.DUMP_FILE_PATH)).be.false(); + }); + + it('should resurrect previous processes from backup if dump is missing', function(done) { + if (fs.existsSync(cst.DUMP_FILE_PATH)) { + fs.unlinkSync(cst.DUMP_FILE_PATH); + } + + pm2.resurrect(function(err, data) { + should(err).be.null(); + + pm2.list(function(err, procs) { + should(err).be.null(); + procs.length.should.eql(4); + done(); + }); + }); + }); + + it('should resurrect no processes if dump and backup are broken', function() { + fs.writeFileSync(cst.DUMP_FILE_PATH, '[{'); + fs.writeFileSync(cst.DUMP_BACKUP_FILE_PATH, '[{'); + + should(pm2.resurrect()).be.false(); + }); + + it('should delete broken dump and backup', function() { + should(fs.existsSync(cst.DUMP_FILE_PATH)).be.false(); + should(fs.existsSync(cst.DUMP_BACKUP_FILE_PATH)).be.false(); + }); + + it('should resurrect no processes if dump and backup are missing', function() { + if (fs.existsSync(cst.DUMP_FILE_PATH)) { + fs.unlinkSync(cst.DUMP_FILE_PATH); + } + + if (fs.existsSync(cst.DUMP_BACKUP_FILE_PATH)) { + fs.unlinkSync(cst.DUMP_BACKUP_FILE_PATH); + } + + should(pm2.resurrect()).be.false(); + }); });