From e960cfd808201fa21129f82b75cfefc46c51ec75 Mon Sep 17 00:00:00 2001 From: Unitech Date: Mon, 1 Oct 2018 12:07:29 +0200 Subject: [PATCH] upgrade to @pm2/io 2.4.x + add test to verify auto restart of throwing application --- package.json | 2 +- test/programmatic/auto_restart.mocha.js | 49 +++++++++++++++++++ .../fixtures/auto-restart/throw.js | 1 + test/unit.sh | 2 + 4 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 test/programmatic/auto_restart.mocha.js create mode 100644 test/programmatic/fixtures/auto-restart/throw.js diff --git a/package.json b/package.json index 787f5252..faf4c952 100644 --- a/package.json +++ b/package.json @@ -159,7 +159,7 @@ }, "dependencies": { "@pm2/agent": "^0.5.11", - "@pm2/io": "~2.3.11", + "@pm2/io": "~2.4.2", "@pm2/js-api": "^0.5.15", "async": "^2.6.1", "blessed": "^0.1.81", diff --git a/test/programmatic/auto_restart.mocha.js b/test/programmatic/auto_restart.mocha.js new file mode 100644 index 00000000..84c0dc13 --- /dev/null +++ b/test/programmatic/auto_restart.mocha.js @@ -0,0 +1,49 @@ + +const pm2 = require('../..'); +const should = require('should'); +const path = require('path') + +describe('PM2 auto restart on uncaughtexception', function() { + var test_path = path.join(__dirname, 'fixtures', 'auto-restart') + + after((done) => { + pm2.delete('all', () => { done() }) + }) + + before((done) => { + pm2.uninstall('all', () => { + pm2.delete('all', () => { done() }) + }) + }) + + it('should start a failing app in fork mode', function(done) { + pm2.start({ + script: path.join(test_path, 'throw.js'), + }, (err, apps) => { + setTimeout(function() { + pm2.list((err, list) => { + should(list[0].pm2_env.restart_time).aboveOrEqual(0) + pm2.delete('throw', () => { + done() + }) + }) + }, 200) + }) + }) + + it('should start a failing app in cluster mode', function(done) { + pm2.start({ + script: path.join(test_path, 'throw.js'), + instances: 4 + }, (err, apps) => { + setTimeout(function() { + pm2.list((err, list) => { + should(list[0].pm2_env.restart_time).aboveOrEqual(0) + pm2.delete('throw', () => { + done() + }) + }) + }, 200) + }) + }) +}) diff --git a/test/programmatic/fixtures/auto-restart/throw.js b/test/programmatic/fixtures/auto-restart/throw.js new file mode 100644 index 00000000..4e6d81e3 --- /dev/null +++ b/test/programmatic/fixtures/auto-restart/throw.js @@ -0,0 +1 @@ +throw new Error('err') diff --git a/test/unit.sh b/test/unit.sh index acc03d51..ff738237 100644 --- a/test/unit.sh +++ b/test/unit.sh @@ -48,6 +48,8 @@ spec "API tests" mocha --exit --opts ./mocha.opts ./reload-locker.mocha.js spec "Reload locker tests" +mocha --exit --opts ./mocha.opts ./auto_restart.mocha.js +spec "Auto restart feature when uncaughtException" mocha --exit --opts ./mocha.opts ./version.mocha.js spec "Package json version retriever" mocha --exit --opts ./mocha.opts ./exp_backoff_restart_delay.mocha.js