Skip to content

Commit e73b90e

Browse files
authored
Merge pull request #286 from strongloop/fix/booting-flag
fix: set `app.booting` flag immediately
2 parents 825411e + c10e822 commit e73b90e

4 files changed

Lines changed: 51 additions & 2 deletions

File tree

lib/bootstrapper.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,20 @@ Bootstrapper.prototype.run = function(context, done) {
202202
context = context || {};
203203

204204
var phases = context.phases || this.phases;
205+
206+
if (phases.includes('starting') || phases.includes('start')) {
207+
context.app.booting = true;
208+
}
209+
205210
var bootPlugins = this.getExtensions('/boot');
206211
async.eachSeries(phases, function(phase, done) {
207212
debug('Phase %s', phase);
208213
async.eachSeries(bootPlugins, pluginIteratorFactory(context, phase), done);
209214
}, function(err) {
215+
if (phases.includes('started')) {
216+
context.app.booting = false;
217+
}
218+
210219
return done(err, context);
211220
});
212221
return done.promise;

lib/plugins/application.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ function applyAppConfig(app, appConfig) {
116116

117117
Application.prototype.starting = function(context) {
118118
var app = context.app;
119-
app.booting = true;
120119
assertLoopBackVersion(app);
121120

122121
var appConfig = context.instructions.application;
@@ -129,7 +128,6 @@ Application.prototype.starting = function(context) {
129128

130129
Application.prototype.started = function(context, done) {
131130
var app = context.app;
132-
app.booting = false;
133131
process.nextTick(function() {
134132
app.emit('booted');
135133
done();

test/acceptance.test.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright IBM Corp. 2015,2016. All Rights Reserved.
2+
// Node module: loopback-boot
3+
// This file is licensed under the MIT License.
4+
// License text available at https://opensource.org/licenses/MIT
5+
6+
'use strict';
7+
8+
var path = require('path');
9+
var loopback = require('loopback');
10+
11+
var chai = require('chai');
12+
var dirtyChai = require('dirty-chai');
13+
var expect = chai.expect;
14+
chai.use(dirtyChai);
15+
16+
const bootLoopBackApp = require('..');
17+
18+
describe('bootLoopBackApp', function() {
19+
var app;
20+
beforeEach(function() {
21+
app = loopback();
22+
});
23+
24+
it('sets app.booting immediately', function() {
25+
const appDir = path.join(__dirname, './fixtures/empty-app');
26+
27+
// Start the bootstrapper
28+
const promise = bootLoopBackApp(app, appDir);
29+
30+
// Still in the original turn of the event loop,
31+
// verify that the app is signalling "boot in progress"
32+
expect(app.booting).to.equal(true);
33+
34+
// Wait for bootstrapper to finish
35+
return promise.then(() => {
36+
// Verify that app is signalling "boot has finished"
37+
expect(app.booting).to.equal(false);
38+
});
39+
});
40+
});
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
{
2+
}

0 commit comments

Comments
 (0)