Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reload bug #81

Merged
merged 1 commit into from
Sep 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ prepare-test: parser
@cd example-apps && tar cfz socket-app_1.0.0_2.tgz socket-app_1.0.0_2/
@cd example-apps && tar cfz https-app.tgz https-app/
@cd example-apps && tar cfz exception-retry-app.tgz exception-retry-app/
@cd example-apps && tar cfz reload-app_1.0.0_1.tgz reload-app_1.0.0_1/
@cd example-apps && tar cfz java-app.tgz java-app/

test: eslint prepare-test
Expand Down
20 changes: 20 additions & 0 deletions example-apps/reload-app_1.0.0_1/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

let http = require('http');
let path = require('path');
let serverConfig = JSON.parse(process.env.HC_APP_CONFIG);

let serv = http.createServer(function (req, res) {
res.setHeader('content-type', 'application/json');
res.end(JSON.stringify(serverConfig.config));
});

exports.run = function (cb) {
let sock = serverConfig.targetSock;
serv.listen(sock);
cb(null, {
bind: '6001',
router: '/reload-app',
target: sock
});
};
8 changes: 8 additions & 0 deletions example-apps/reload-app_1.0.0_1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"main": "index.js",
"version": "1.0.0",
"buildNum": "1",
"honeycomb": {
"processorNum": 1
}
}
2 changes: 2 additions & 0 deletions example-apps/simple-app_1.1.0_1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ let serv = http.createServer(function (req, res) {
res.end('simple-app_v1.1.0_1');
});

console.log(serverConfig.config);

exports.run = function (cb) {
let sock = serverConfig.targetSock || path.join(__dirname, '../../simple-app_v1.1.0_1.sock');
serv.listen(sock);
Expand Down
11 changes: 7 additions & 4 deletions lib/child.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Child extends EventEmitter {
processorNum: 1,
exitWhenTimeout: true,
timeout: 60000,
name: appInfo.name,
version: appInfo.version,
buildNum: appInfo.buildNum,
weight: utils.genWeight(appInfo.version, appInfo.buildNum)
Expand Down Expand Up @@ -262,15 +263,17 @@ class Child extends EventEmitter {
if (err) {
log.error(FLAG_CHILD, `app_reload_failed : ${this.appId}`, err);
let workers = this.workers;
this.cleanWorkers(workers, () => {});
this.cleanWorkers(workers, () => {
this.status = 'online';
});
this.workers = this.oldWorkers;
this.oldWorkers = {};
this.status = 'online';
} else {
log.info(FLAG_CHILD, `app_reload_success : ${this.appId} , now stop old workers`);
this.cleanWorkers(this.oldWorkers, () => {});
this.cleanWorkers(this.oldWorkers, () => {
this.status = 'online';
});
this.oldWorkers = {};
this.status = 'online';
}
});
});
Expand Down
2 changes: 1 addition & 1 deletion lib/master.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ Master.prototype.$reload = function (appId, cb) {
processorNum = privateConfig.honeycomb.processorNum || processorNum;
}

child.options.config = this.getAppConfig(child.options.name);
child.options.config = privateConfig;
child.options.processorNum = child.options.config.processorNum || processorNum;
child.reload((err, done) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "honeycomb-server",
"version": "1.0.9",
"build": "5",
"build": "6",
"description": "Honeycomb, the micro-app's container",
"repository": {
"type": "git",
Expand Down
40 changes: 36 additions & 4 deletions test/lib/admin/api_config.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,44 @@ describe('api_config.test.js', () => {

});

it.skip('should affect app when common config changed and app reloaded', () => {

it('should affect app when common config changed and app reloaded', (done) => {
common.publishApp(agent, ips, path.join(appsPkgBase, 'reload-app_1.0.0_1.tgz'))
.expect(200)
.end(() => {
let d = new Date().getTime();
common.setServerConfig(agent, ips, 'common', {testCommon: d})
.end(() => {
common.reloadApp(agent, ips, 'reload-app_1.0.0_1')
.end(() => {
let ag1 = supertest('http://localhost:6001/reload-app');
ag1.get('/')
.expect((res)=> {
res.body.testCommon.should.eql(d);
})
.end(done);
});
});
});
});

it.skip('should affect app when config changed and app reloaded', () => {

it('should affect app when config changed and app reloaded', (done) => {
common.publishApp(agent, ips, path.join(appsPkgBase, 'reload-app_1.0.0_1.tgz'))
.expect(200)
.end(() => {
let d = new Date().getTime();
common.setAppConfig(agent, ips, 'reload-app', {test: d})
.end(() => {
common.reloadApp(agent, ips, 'reload-app_1.0.0_1')
.end(() => {
let ag1 = supertest('http://localhost:6001/reload-app');
ag1.get('/')
.expect((res)=> {
res.body.test.should.eql(d);
})
.end(done);
});
});
});
});

});