Skip to content

Commit

Permalink
Allow initializing connectionless. Closes #3325
Browse files Browse the repository at this point in the history
  • Loading branch information
hueniverse committed Aug 28, 2016
1 parent 1cc8f35 commit b02673a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 11 deletions.
14 changes: 5 additions & 9 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ internals.Server.prototype.start = function (callback) {
Hoek.assert(typeof callback === 'function', 'Missing required start callback function');
const nextTickCallback = Hoek.nextTick(callback);

if (!this.connections.length) {
return nextTickCallback(new Error('No connections to start'));
}

if (this._state === 'initialized' ||
this._state === 'started') {

Expand Down Expand Up @@ -224,10 +228,6 @@ internals.Server.prototype.initialize = function (callback) {
Hoek.assert(typeof callback === 'function', 'Missing required start callback function');
const nextTickCallback = Hoek.nextTick(callback);

if (!this.connections.length) {
return nextTickCallback(new Error('No connections to start'));
}

if (this._registring) {
return nextTickCallback(new Error('Cannot start server before plugins finished registration'));
}
Expand All @@ -249,12 +249,8 @@ internals.Server.prototype.initialize = function (callback) {

// Start cache

const each = (cache, next) => {

this._caches[cache].client.start(next);
};

const caches = Object.keys(this._caches);
const each = (cache, next) => this._caches[cache].client.start(next);
Items.parallel(caches, each, (err) => {

if (err) {
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "hapi",
"description": "HTTP Server framework",
"homepage": "http://hapijs.com",
"version": "15.0.1",
"version": "15.0.2",
"repository": {
"type": "git",
"url": "git://github.com/hapijs/hapi"
Expand Down
43 changes: 43 additions & 0 deletions test/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2870,6 +2870,49 @@ describe('Plugin', () => {
});
});
});

it('errors when missing dependencies on connection added after start', (done) => {

const a = function (srv, options, next) {

return next();
};

a.attributes = {
name: 'a'
};

const b = function (srv, options, next) {

srv.dependency('a');
return next();
};

b.attributes = {
name: 'b'
};

const server = new Hapi.Server();
server.connection();
server.register([a, b], (err) => {

expect(err).to.not.exist();
server.start((err) => {

expect(err).to.not.exist();
const select = server.connection();
select.register(b, (err) => {

expect(err).to.not.exist();
server.start((err) => {

expect(err).to.be.an.error(`Plugin b missing dependency a in connection: ${select.info.uri}`);
server.stop(done);
});
});
});
});
});
});

describe('encoder()', () => {
Expand Down
13 changes: 13 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ describe('Server', () => {
done();
});

describe('initialize()', () => {

it('allows initializing a server without connections', (done) => {

const server = new Hapi.Server();
server.initialize((err) => {

expect(err).to.not.exist();
done();
});
});
});

describe('start()', () => {

it('starts and stops', (done) => {
Expand Down

0 comments on commit b02673a

Please sign in to comment.