Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
6c720f4c2d | |||
14fead9c17 | |||
6c115aa8b2 |
5 changed files with 35 additions and 35 deletions
|
@ -26,7 +26,8 @@ export default class Application extends EventEmitter {
|
||||||
getLog: getLog,
|
getLog: getLog,
|
||||||
HttpServer: HttpServer,
|
HttpServer: HttpServer,
|
||||||
request: request,
|
request: request,
|
||||||
}
|
},
|
||||||
|
version: '',
|
||||||
}
|
}
|
||||||
this.config = defaults({}, this.ctx.db.config[name])
|
this.config = defaults({}, this.ctx.db.config[name])
|
||||||
this.provider = provider
|
this.provider = provider
|
||||||
|
@ -34,7 +35,6 @@ export default class Application extends EventEmitter {
|
||||||
this.updating = false
|
this.updating = false
|
||||||
this.http = new HttpServer(this.config)
|
this.http = new HttpServer(this.config)
|
||||||
this.module = null
|
this.module = null
|
||||||
this.running = ''
|
|
||||||
this.workers = {}
|
this.workers = {}
|
||||||
|
|
||||||
// Fresh is used to indicate that when we run the application and it fails,
|
// Fresh is used to indicate that when we run the application and it fails,
|
||||||
|
@ -390,14 +390,14 @@ export default class Application extends EventEmitter {
|
||||||
|
|
||||||
runVersion(version) {
|
runVersion(version) {
|
||||||
this.ctx.db.data.core[this.name].active = version
|
this.ctx.db.data.core[this.name].active = version
|
||||||
this.running = version
|
this.ctx.version = version
|
||||||
this.emit('running', this.running)
|
this.emit('running', this.ctx.version)
|
||||||
|
|
||||||
return this.ctx.db.write().then(() => {
|
return this.ctx.db.write().then(() => {
|
||||||
return this._runVersion(version)
|
return this._runVersion(version)
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
this.running = ''
|
this.ctx.version = ''
|
||||||
this.emit('running', this.running)
|
this.emit('running', this.ctx.version)
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -477,8 +477,8 @@ export default class Application extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
closeServer() {
|
closeServer() {
|
||||||
this.running = ''
|
this.ctx.version = ''
|
||||||
this.emit('running', this.running)
|
this.emit('running', this.ctx.version)
|
||||||
if (this.config.cluster && !this.isSlave) {
|
if (this.config.cluster && !this.isSlave) {
|
||||||
if (this.__clusterWorkerDied) {
|
if (this.__clusterWorkerDied) {
|
||||||
this.cluster.off('exit', this.__clusterWorkerDied)
|
this.cluster.off('exit', this.__clusterWorkerDied)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "service-core",
|
"name": "service-core",
|
||||||
"version": "3.0.1",
|
"version": "3.0.2",
|
||||||
"description": "Core boiler plate code to install node server as windows service",
|
"description": "Core boiler plate code to install node server as windows service",
|
||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
|
@ -48,11 +48,11 @@ t.describe('#runVersion("static")', function() {
|
||||||
assert.strictEqual(checkCtx.app, app)
|
assert.strictEqual(checkCtx.app, app)
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
let err = await assert.isRejected(app.runVersion('static'))
|
let err = await assert.isRejected(app.runVersion('static'))
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.match(err.message, /http/i)
|
assert.match(err.message, /http/i)
|
||||||
assert.match(err.message, /createServer/i)
|
assert.match(err.message, /createServer/i)
|
||||||
|
@ -64,11 +64,11 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.config.startWaitUntilFail = 50
|
app.config.startWaitUntilFail = 50
|
||||||
app.registerModule(function() { return new Promise(function() {}) })
|
app.registerModule(function() { return new Promise(function() {}) })
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
let err = await assert.isRejected(app.runVersion('static'))
|
let err = await assert.isRejected(app.runVersion('static'))
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.match(err.message, /time/i)
|
assert.match(err.message, /time/i)
|
||||||
assert.match(err.message, /out/i)
|
assert.match(err.message, /out/i)
|
||||||
|
@ -87,11 +87,11 @@ t.describe('#runVersion("static")', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
await app.runVersion('static')
|
await app.runVersion('static')
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, 'static')
|
assert.strictEqual(app.ctx.version, 'static')
|
||||||
|
|
||||||
assert.strictEqual(ctx.db.data.core.testapp.active, 'static')
|
assert.strictEqual(ctx.db.data.core.testapp.active, 'static')
|
||||||
})
|
})
|
||||||
|
@ -107,11 +107,11 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.config.heartbeatAttemptsWait = 5
|
app.config.heartbeatAttemptsWait = 5
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
let err = await assert.isRejected(app.runVersion('static'))
|
let err = await assert.isRejected(app.runVersion('static'))
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.match(err.message, /failed/i)
|
assert.match(err.message, /failed/i)
|
||||||
assert.match(err.message, /400/i)
|
assert.match(err.message, /400/i)
|
||||||
|
@ -129,13 +129,13 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.config.heartbeatAttemptsWait = 10
|
app.config.heartbeatAttemptsWait = 10
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
let start = performance.now()
|
let start = performance.now()
|
||||||
let err = await assert.isRejected(app.runVersion('static'))
|
let err = await assert.isRejected(app.runVersion('static'))
|
||||||
let end = performance.now()
|
let end = performance.now()
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.match(err.message, /failed/i)
|
assert.match(err.message, /failed/i)
|
||||||
assert.match(err.message, /time/i)
|
assert.match(err.message, /time/i)
|
||||||
|
@ -160,11 +160,11 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.config.heartbeatAttemptsWait = 5
|
app.config.heartbeatAttemptsWait = 5
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
let err = await assert.isRejected(app.runVersion('static'))
|
let err = await assert.isRejected(app.runVersion('static'))
|
||||||
assert.match(err.message, /failed/i)
|
assert.match(err.message, /failed/i)
|
||||||
assert.match(err.message, /400/i)
|
assert.match(err.message, /400/i)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
await app.closeServer()
|
await app.closeServer()
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
@ -185,11 +185,11 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
app.isSlave = true
|
app.isSlave = true
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
await app.runVersion('static')
|
await app.runVersion('static')
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, 'static')
|
assert.strictEqual(app.ctx.version, 'static')
|
||||||
|
|
||||||
assert.strictEqual(called, 0)
|
assert.strictEqual(called, 0)
|
||||||
assert.strictEqual(ctx.db.data.core.testapp.active, 'static')
|
assert.strictEqual(ctx.db.data.core.testapp.active, 'static')
|
||||||
|
@ -240,11 +240,11 @@ t.describe('#runVersion("version")', function() {
|
||||||
app.config.port = assertPort
|
app.config.port = assertPort
|
||||||
stubFsStat.rejects(assertNotError)
|
stubFsStat.rejects(assertNotError)
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
let err = await assert.isRejected(app.runVersion('v100'))
|
let err = await assert.isRejected(app.runVersion('v100'))
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.notStrictEqual(err, assertNotError)
|
assert.notStrictEqual(err, assertNotError)
|
||||||
assert.match(err.message, new RegExp(assertNotError.message))
|
assert.match(err.message, new RegExp(assertNotError.message))
|
||||||
|
@ -262,11 +262,11 @@ t.describe('#runVersion("version")', function() {
|
||||||
await fs.mkdir(util.getPathFromRoot('./testnoexisting/v99'), { recursive: true })
|
await fs.mkdir(util.getPathFromRoot('./testnoexisting/v99'), { recursive: true })
|
||||||
await fs.writeFile(util.getPathFromRoot('./testnoexisting/v99/index.mjs'), `throw new Error('${assertError.message}')`)
|
await fs.writeFile(util.getPathFromRoot('./testnoexisting/v99/index.mjs'), `throw new Error('${assertError.message}')`)
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
let err = await assert.isRejected(app.runVersion('v99'))
|
let err = await assert.isRejected(app.runVersion('v99'))
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.notStrictEqual(err, assertError)
|
assert.notStrictEqual(err, assertError)
|
||||||
assert.strictEqual(err.message, assertError.message)
|
assert.strictEqual(err.message, assertError.message)
|
||||||
|
@ -280,12 +280,12 @@ t.describe('#runVersion("version")', function() {
|
||||||
await fs.mkdir(util.getPathFromRoot('./testnoexisting/v98'), { recursive: true })
|
await fs.mkdir(util.getPathFromRoot('./testnoexisting/v98'), { recursive: true })
|
||||||
await fs.writeFile(util.getPathFromRoot('./testnoexisting/v98/index.mjs'), ``)
|
await fs.writeFile(util.getPathFromRoot('./testnoexisting/v98/index.mjs'), ``)
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
let err = await assert.isRejected(app.runVersion('v98'))
|
let err = await assert.isRejected(app.runVersion('v98'))
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.match(err.message, /start/i)
|
assert.match(err.message, /start/i)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.strictEqual(app.ctx.db.data.core.testnoexisting.active, 'v98')
|
assert.strictEqual(app.ctx.db.data.core.testnoexisting.active, 'v98')
|
||||||
let checkDb = await lowdb({}, ctx.log, assertConfig)
|
let checkDb = await lowdb({}, ctx.log, assertConfig)
|
||||||
|
@ -302,11 +302,11 @@ t.describe('#runVersion("version")', function() {
|
||||||
app.ctx.log.info.reset()
|
app.ctx.log.info.reset()
|
||||||
app.ctx.log.event.info.reset()
|
app.ctx.log.event.info.reset()
|
||||||
|
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
await app.runVersion('v97')
|
await app.runVersion('v97')
|
||||||
assert.strictEqual(app.fresh, false)
|
assert.strictEqual(app.fresh, false)
|
||||||
assert.strictEqual(app.running, 'v97')
|
assert.strictEqual(app.ctx.version, 'v97')
|
||||||
|
|
||||||
assert.ok(app.ctx.log.info.called)
|
assert.ok(app.ctx.log.info.called)
|
||||||
assert.ok(app.ctx.log.event.info.called)
|
assert.ok(app.ctx.log.event.info.called)
|
||||||
|
|
|
@ -74,7 +74,7 @@ t.describe('constructor()', function() {
|
||||||
assert.strictEqual(app.ctx.sc.getLog, getLog)
|
assert.strictEqual(app.ctx.sc.getLog, getLog)
|
||||||
assert.strictEqual(app.name, assertName)
|
assert.strictEqual(app.name, assertName)
|
||||||
assert.strictEqual(app.fresh, true)
|
assert.strictEqual(app.fresh, true)
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
assert.strictEqual(app.monitoringCluster, false)
|
assert.strictEqual(app.monitoringCluster, false)
|
||||||
assert.deepStrictEqual(app.workers, {})
|
assert.deepStrictEqual(app.workers, {})
|
||||||
assert.strictEqual(app.isSlave, false)
|
assert.strictEqual(app.isSlave, false)
|
||||||
|
@ -333,9 +333,9 @@ t.describe('#closeServer()', function() {
|
||||||
const assertError = new Error('Moonlight Fiesta')
|
const assertError = new Error('Moonlight Fiesta')
|
||||||
stubCloseServer.rejects(assertError)
|
stubCloseServer.rejects(assertError)
|
||||||
|
|
||||||
app.running = assertNotVersion
|
app.ctx.version = assertNotVersion
|
||||||
let err = await assert.isRejected(app.closeServer())
|
let err = await assert.isRejected(app.closeServer())
|
||||||
assert.strictEqual(app.running, '')
|
assert.strictEqual(app.ctx.version, '')
|
||||||
|
|
||||||
assert.strictEqual(err, assertError)
|
assert.strictEqual(err, assertError)
|
||||||
})
|
})
|
||||||
|
|
|
@ -16,7 +16,7 @@ t.timeout(5000).describe('#getLatestVersion()', function() {
|
||||||
assert.ok(version.version)
|
assert.ok(version.version)
|
||||||
assert.ok(version.description)
|
assert.ok(version.description)
|
||||||
assert.ok(version.link)
|
assert.ok(version.link)
|
||||||
assert.match(version.link, /\/attachments\//)
|
assert.match(version.link, /\/download\//)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should fail if link does not return json repository object', async function() {
|
t.test('should fail if link does not return json repository object', async function() {
|
||||||
|
|
Loading…
Reference in a new issue