diff --git a/ghost/job-manager/test/job-manager.test.js b/ghost/job-manager/test/job-manager.test.js index a7467d4915..d65089fdd6 100644 --- a/ghost/job-manager/test/job-manager.test.js +++ b/ghost/job-manager/test/job-manager.test.js @@ -12,6 +12,7 @@ describe('Job Manager', function () { beforeEach(function () { logging = { info: sinon.stub(), + warn: sinon.stub(), error: sinon.stub() }; }); @@ -67,4 +68,18 @@ describe('Job Manager', function () { } }); }); + + describe('Shutdown', function () { + it('gracefully shuts down synchronous jobs', async function () { + const jobManager = new JobManager(logging); + + jobManager.addJob(require('./jobs/timed-job'), 200); + + should(jobManager.queue.idle()).be.false(); + + await jobManager.shutdown(); + + should(jobManager.queue.idle()).be.true(); + }); + }); }); diff --git a/ghost/job-manager/test/jobs/timed-job.js b/ghost/job-manager/test/jobs/timed-job.js new file mode 100644 index 0000000000..b759972e47 --- /dev/null +++ b/ghost/job-manager/test/jobs/timed-job.js @@ -0,0 +1,9 @@ +const util = require('util'); +const setTimeoutPromise = util.promisify(setTimeout); + +const passTime = async (ms) => { + await setTimeoutPromise(ms); + return 'done'; +}; + +module.exports = passTime;