Compare commits
No commits in common. "master" and "v3.0.0-beta.13" have entirely different histories.
master
...
v3.0.0-bet
16 changed files with 99 additions and 513 deletions
|
@ -26,8 +26,7 @@ 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
|
||||||
|
@ -35,6 +34,7 @@ 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 = false
|
||||||
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,
|
||||||
|
@ -55,8 +55,6 @@ export default class Application extends EventEmitter {
|
||||||
this.config.heartbeatPath = this.config.heartbeatPath || '/'
|
this.config.heartbeatPath = this.config.heartbeatPath || '/'
|
||||||
this.config.clusterWaitOnCrash = this.config.clusterWaitOnCrash || (1 * 1000)
|
this.config.clusterWaitOnCrash = this.config.clusterWaitOnCrash || (1 * 1000)
|
||||||
|
|
||||||
this.ctx.config = this.config
|
|
||||||
|
|
||||||
Object.assign(this, {
|
Object.assign(this, {
|
||||||
setInterval: opts.setInterval || setInterval,
|
setInterval: opts.setInterval || setInterval,
|
||||||
setTimeout: opts.setTimeout || setTimeout,
|
setTimeout: opts.setTimeout || setTimeout,
|
||||||
|
@ -100,6 +98,7 @@ export default class Application extends EventEmitter {
|
||||||
updateLog(message, level = 'info') {
|
updateLog(message, level = 'info') {
|
||||||
this.ctx.db.data.core[this.name].updater += message
|
this.ctx.db.data.core[this.name].updater += message
|
||||||
this.ctx.log[level](message)
|
this.ctx.log[level](message)
|
||||||
|
this.emit('updatelog')
|
||||||
return message
|
return message
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +113,6 @@ export default class Application extends EventEmitter {
|
||||||
if (this.ctx.db.data.core[this.name].updater !== this.msgStatic) {
|
if (this.ctx.db.data.core[this.name].updater !== this.msgStatic) {
|
||||||
this.ctx.db.data.core[this.name].updater = ''
|
this.ctx.db.data.core[this.name].updater = ''
|
||||||
this.updateLog(this.msgStatic)
|
this.updateLog(this.msgStatic)
|
||||||
this.emit('updatelog', this.msgStatic)
|
|
||||||
return this.ctx.db.write().then(function() { return null })
|
return this.ctx.db.write().then(function() { return null })
|
||||||
}
|
}
|
||||||
return Promise.resolve(null)
|
return Promise.resolve(null)
|
||||||
|
@ -165,7 +163,6 @@ export default class Application extends EventEmitter {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
log += this.updateLog(`Checking for latest version at ${new Date().toISOString().replace('T', ' ').split('.')[0]}. `, 'debug') + '\n'
|
log += this.updateLog(`Checking for latest version at ${new Date().toISOString().replace('T', ' ').split('.')[0]}. `, 'debug') + '\n'
|
||||||
this.emit('updatelog', log)
|
|
||||||
|
|
||||||
// Get the latest version from our provider
|
// Get the latest version from our provider
|
||||||
latest = await this.provider.getLatestVersion()
|
latest = await this.provider.getLatestVersion()
|
||||||
|
@ -173,8 +170,7 @@ export default class Application extends EventEmitter {
|
||||||
// If the versino matches the latest installed, then there's nothing to do
|
// If the versino matches the latest installed, then there's nothing to do
|
||||||
if (this.ctx.db.data.core[this.name].latestInstalled === latest.version) {
|
if (this.ctx.db.data.core[this.name].latestInstalled === latest.version) {
|
||||||
log += this.updateLog(`Found ${latest.version}. `, 'debug') + '\n'
|
log += this.updateLog(`Found ${latest.version}. `, 'debug') + '\n'
|
||||||
log += this.updateLog('Already up to date, nothing to do. ', 'debug')
|
this.updateLog('Already up to date, nothing to do. ', 'debug')
|
||||||
this.emit('updatelog', log)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,8 +185,7 @@ export default class Application extends EventEmitter {
|
||||||
if (found) {
|
if (found) {
|
||||||
// Check if the existing version found was already installed.
|
// Check if the existing version found was already installed.
|
||||||
if (found.installed) {
|
if (found.installed) {
|
||||||
log += this.updateLog('Version was already installed, nothing to do. ')
|
this.updateLog('Version was already installed, nothing to do. ')
|
||||||
this.emit('updatelog', log)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,14 +201,12 @@ export default class Application extends EventEmitter {
|
||||||
// if so, we should skip them and consider those versions as black
|
// if so, we should skip them and consider those versions as black
|
||||||
// listed and avoid at all cost.
|
// listed and avoid at all cost.
|
||||||
if (latest.failtodownload && latest.failtodownload > 3) {
|
if (latest.failtodownload && latest.failtodownload > 3) {
|
||||||
log += this.updateLog('Version failed to download too many times, skipping this version. ')
|
this.updateLog('Version failed to download too many times, skipping this version. ')
|
||||||
this.emit('updatelog', log)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
if (latest.failtoinstall && latest.failtoinstall > 3) {
|
if (latest.failtoinstall && latest.failtoinstall > 3) {
|
||||||
log += this.updateLog('Version failed to install too many times, skipping this version. ')
|
this.updateLog('Version failed to install too many times, skipping this version. ')
|
||||||
this.emit('updatelog', log)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +217,7 @@ export default class Application extends EventEmitter {
|
||||||
latest.stable = 0
|
latest.stable = 0
|
||||||
this.ctx.db.upsertFirst(this.ctx.db.data.core[this.name].versions, latest)
|
this.ctx.db.upsertFirst(this.ctx.db.data.core[this.name].versions, latest)
|
||||||
}
|
}
|
||||||
this.emit('updatelog', log)
|
|
||||||
this.emit('update', latest)
|
this.emit('update', latest)
|
||||||
|
|
||||||
// The target file for the archive and the target folder for new our version
|
// The target file for the archive and the target folder for new our version
|
||||||
|
@ -235,7 +228,6 @@ export default class Application extends EventEmitter {
|
||||||
await this.fs.mkdir(folder, { recursive: true })
|
await this.fs.mkdir(folder, { recursive: true })
|
||||||
|
|
||||||
log += this.updateLog(`Downloading ${latest.link} to ${target}. `) + '\n'
|
log += this.updateLog(`Downloading ${latest.link} to ${target}. `) + '\n'
|
||||||
this.emit('updatelog', log)
|
|
||||||
await this.ctx.db.write()
|
await this.ctx.db.write()
|
||||||
|
|
||||||
// Download the latest version using the provider in question.
|
// Download the latest version using the provider in question.
|
||||||
|
@ -246,13 +238,11 @@ export default class Application extends EventEmitter {
|
||||||
})
|
})
|
||||||
|
|
||||||
log += '\n' + this.updateLog(`Extracting ${target}. `) + '\n'
|
log += '\n' + this.updateLog(`Extracting ${target}. `) + '\n'
|
||||||
this.emit('updatelog', log)
|
|
||||||
await this.ctx.db.write()
|
await this.ctx.db.write()
|
||||||
|
|
||||||
// Download was successful, extract the archived file that we downloaded
|
// Download was successful, extract the archived file that we downloaded
|
||||||
await this.ctx.util.extractFile(target, (msg) => {
|
await this.ctx.util.extractFile(target, function(msg) {
|
||||||
log += msg
|
log += msg
|
||||||
this.emit('updatelog', log)
|
|
||||||
}).catch(function(err) {
|
}).catch(function(err) {
|
||||||
latest.failtodownload = (latest.failtodownload || 0) + 1
|
latest.failtodownload = (latest.failtodownload || 0) + 1
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
|
@ -272,7 +262,6 @@ export default class Application extends EventEmitter {
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
latest.failtodownload = (latest.failtodownload || 0) + 1
|
latest.failtodownload = (latest.failtodownload || 0) + 1
|
||||||
log += this.updateLog('Version did not include or was missing index.mjs. ') + '\n'
|
log += this.updateLog('Version did not include or was missing index.mjs. ') + '\n'
|
||||||
this.emit('updatelog', log)
|
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -290,7 +279,6 @@ export default class Application extends EventEmitter {
|
||||||
|
|
||||||
if (packageStat) {
|
if (packageStat) {
|
||||||
log += this.updateLog(`running npm install --production. `) + '\n'
|
log += this.updateLog(`running npm install --production. `) + '\n'
|
||||||
this.emit('updatelog', log)
|
|
||||||
await this.ctx.db.write()
|
await this.ctx.db.write()
|
||||||
|
|
||||||
// For some weird reason, --loglevel=notice is required otherwise
|
// For some weird reason, --loglevel=notice is required otherwise
|
||||||
|
@ -299,20 +287,15 @@ export default class Application extends EventEmitter {
|
||||||
this.ctx.util.getNpmExecutable(),
|
this.ctx.util.getNpmExecutable(),
|
||||||
['install', '--production', '--no-optional', '--no-package-lock', '--no-audit', '--loglevel=notice'],
|
['install', '--production', '--no-optional', '--no-package-lock', '--no-audit', '--loglevel=notice'],
|
||||||
folder,
|
folder,
|
||||||
(msg) => {
|
function(msg) { log += msg }
|
||||||
log += msg
|
|
||||||
this.emit('updatelog', log)
|
|
||||||
}
|
|
||||||
).catch(function(err) {
|
).catch(function(err) {
|
||||||
latest.failtoinstall = (latest.failtoinstall || 0) + 1
|
latest.failtoinstall = (latest.failtoinstall || 0) + 1
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
log = this.logAddSeperator(log)
|
log = this.logAddSeperator(log)
|
||||||
this.emit('updatelog', log)
|
|
||||||
} else {
|
} else {
|
||||||
log += this.updateLog('Release did not contain package.json, skipping npm install. ') + '\n'
|
log += this.updateLog('Release did not contain package.json, skipping npm install. ') + '\n'
|
||||||
this.emit('updatelog', log)
|
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log += this.updateLog(`Error: ${err.message}. `) + '\n'
|
log += this.updateLog(`Error: ${err.message}. `) + '\n'
|
||||||
|
@ -328,14 +311,12 @@ export default class Application extends EventEmitter {
|
||||||
if (latest) {
|
if (latest) {
|
||||||
latest.log = log
|
latest.log = log
|
||||||
}
|
}
|
||||||
this.emit('updatelog', log)
|
|
||||||
return Promise.reject(err)
|
return Promise.reject(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// If we reached here then everything went swimmingly. Mark the version
|
// If we reached here then everything went swimmingly. Mark the version
|
||||||
// as being installed and attach the install log to it.
|
// as being installed and attach the install log to it.
|
||||||
log += this.updateLog(`Finished updating ${this.name} to version ${latest.version}.`) + '\n'
|
log += this.updateLog(`Finished updating ${this.name} to version ${latest.version}.`) + '\n'
|
||||||
this.emit('updatelog', log)
|
|
||||||
this.ctx.db.data.core[this.name].latestInstalled = latest.version
|
this.ctx.db.data.core[this.name].latestInstalled = latest.version
|
||||||
latest.installed = true
|
latest.installed = true
|
||||||
latest.log = log
|
latest.log = log
|
||||||
|
@ -388,22 +369,7 @@ export default class Application extends EventEmitter {
|
||||||
this.workers[i].started = new Date()
|
this.workers[i].started = new Date()
|
||||||
}
|
}
|
||||||
|
|
||||||
runVersion(version) {
|
async runVersion(version) {
|
||||||
this.ctx.db.data.core[this.name].active = version
|
|
||||||
this.ctx.version = version
|
|
||||||
this.emit('running', this.ctx.version)
|
|
||||||
|
|
||||||
return this.ctx.db.write().then(() => {
|
|
||||||
return this._runVersion(version)
|
|
||||||
.catch((err) => {
|
|
||||||
this.ctx.version = ''
|
|
||||||
this.emit('running', this.ctx.version)
|
|
||||||
return Promise.reject(err)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async _runVersion(version) {
|
|
||||||
this.ctx.db.data.core[this.name].active = version
|
this.ctx.db.data.core[this.name].active = version
|
||||||
await this.ctx.db.write()
|
await this.ctx.db.write()
|
||||||
|
|
||||||
|
@ -477,8 +443,6 @@ export default class Application extends EventEmitter {
|
||||||
}
|
}
|
||||||
|
|
||||||
closeServer() {
|
closeServer() {
|
||||||
this.ctx.version = ''
|
|
||||||
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)
|
||||||
|
|
|
@ -61,8 +61,6 @@ export default class Core {
|
||||||
|
|
||||||
this.log.info(`Found applications: ${names.join(', ')}.`)
|
this.log.info(`Found applications: ${names.join(', ')}.`)
|
||||||
|
|
||||||
let hasCluster = false
|
|
||||||
|
|
||||||
for (let name of names) {
|
for (let name of names) {
|
||||||
if (this.isSlave && process.env.CLUSTER_APP_NAME !== name) {
|
if (this.isSlave && process.env.CLUSTER_APP_NAME !== name) {
|
||||||
continue
|
continue
|
||||||
|
@ -84,51 +82,17 @@ export default class Core {
|
||||||
let application = new Application({
|
let application = new Application({
|
||||||
db: this.db,
|
db: this.db,
|
||||||
util: this.util,
|
util: this.util,
|
||||||
log: getLog(logName, this.db.config[name].log || null, { name: name }),
|
log: getLog(logName, this.db.config[name].log || null),
|
||||||
core: this,
|
core: this,
|
||||||
}, provider, name)
|
}, provider, name)
|
||||||
this.applications.push(application)
|
this.applications.push(application)
|
||||||
this.applicationMap.set(name, application)
|
this.applicationMap.set(name, application)
|
||||||
|
|
||||||
if (this.db.config[name].cluster) {
|
|
||||||
hasCluster = true
|
|
||||||
}
|
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.log.error(err, `Error creating application ${name} with provider ${this.db.config[name].provider} with config ${JSON.stringify(this.db.config[name])}: ${err.message}`)
|
this.log.error(err, `Error creating application ${name} with provider ${this.db.config[name].provider}: ${err.message}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasCluster && !this.isSlave) {
|
|
||||||
cluster.on('message', (worker, message) => {
|
|
||||||
// Some sanity checking
|
|
||||||
if (!message
|
|
||||||
|| typeof(message) !== 'object'
|
|
||||||
|| typeof(message.apptarget) !== 'string'
|
|
||||||
|| typeof(message.type) !== 'string'
|
|
||||||
|| typeof(message.payload) !== 'object'
|
|
||||||
|| !message.payload
|
|
||||||
) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let app = this.getApplication(message.apptarget)
|
|
||||||
let targetLog = null
|
|
||||||
if (app) {
|
|
||||||
targetLog = app.ctx.log
|
|
||||||
} else if (message.apptarget === this.db.config.name) {
|
|
||||||
targetLog = this.log
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!targetLog) return
|
|
||||||
|
|
||||||
if (message.type === 'newlog') {
|
|
||||||
targetLog.emit('newlog', message.payload)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (names.length && !this.applications.length) {
|
if (names.length && !this.applications.length) {
|
||||||
this.log.error('None of the application were successful in running')
|
|
||||||
return Promise.reject(new Error('None of the application were successful in running'))
|
return Promise.reject(new Error('None of the application were successful in running'))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,9 +122,7 @@ export default function GetDB(config, log, orgFilename = 'db.json') {
|
||||||
return db.read()
|
return db.read()
|
||||||
.then(function() {
|
.then(function() {
|
||||||
if (!isObject(db.data)) {
|
if (!isObject(db.data)) {
|
||||||
if (fullpath !== 'in-memory') {
|
|
||||||
db.log.warn(`File ${fullpath} was empty or not a json object, clearing it.`)
|
db.log.warn(`File ${fullpath} was empty or not a json object, clearing it.`)
|
||||||
}
|
|
||||||
db.data = {}
|
db.data = {}
|
||||||
}
|
}
|
||||||
defaults(db.data, { core: { version: 1 } })
|
defaults(db.data, { core: { version: 1 } })
|
||||||
|
|
|
@ -37,11 +37,7 @@ export default class ServiceCore {
|
||||||
|
|
||||||
async init(module = null) {
|
async init(module = null) {
|
||||||
this.db = await GetDB(this.config, this.log, this.dbfilename)
|
this.db = await GetDB(this.config, this.log, this.dbfilename)
|
||||||
this.core = new Core(this.db, this.util, this.log, (msg) => {
|
this.core = new Core(this.db, this.util, this.log)
|
||||||
let err = new Error('Got request to restart' + (msg ? ': ' + msg : ''))
|
|
||||||
this.log.fatal(err)
|
|
||||||
process.exit(0)
|
|
||||||
})
|
|
||||||
|
|
||||||
let provider = new StaticProvider()
|
let provider = new StaticProvider()
|
||||||
this.app = new Application({
|
this.app = new Application({
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
// import nodewindows from 'node-windows'
|
// import nodewindows from 'node-windows'
|
||||||
import cluster from 'cluster'
|
|
||||||
import bunyan from 'bunyan-lite'
|
import bunyan from 'bunyan-lite'
|
||||||
import { setTimeout } from 'timers/promises'
|
import { setTimeout } from 'timers/promises'
|
||||||
|
|
||||||
|
@ -55,14 +54,6 @@ export default function getLog(name, streams = null, opts = {}) {
|
||||||
stream: {
|
stream: {
|
||||||
write: function(record) {
|
write: function(record) {
|
||||||
logger.emit('newlog', record)
|
logger.emit('newlog', record)
|
||||||
|
|
||||||
if (cluster.isWorker) {
|
|
||||||
process.send({
|
|
||||||
apptarget: opts.name || name,
|
|
||||||
type: 'newlog',
|
|
||||||
payload: record,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
end: function() {},
|
end: function() {},
|
||||||
destroy: function() {},
|
destroy: function() {},
|
||||||
|
|
|
@ -26,10 +26,9 @@ export default class GitProvider {
|
||||||
|
|
||||||
for (let asset of item.assets) {
|
for (let asset of item.assets) {
|
||||||
if (!asset.name.endsWith('-sc.7z')) continue
|
if (!asset.name.endsWith('-sc.7z')) continue
|
||||||
if (this.config.git_required_prefix && !asset.name.startsWith(this.config.git_required_prefix)) continue
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
version: item.name.replace(/ /g, '_'),
|
version: item.name,
|
||||||
link: asset.browser_download_url,
|
link: asset.browser_download_url,
|
||||||
filename: asset.name,
|
filename: asset.name,
|
||||||
description: item.body,
|
description: item.body,
|
||||||
|
@ -56,5 +55,10 @@ export default class GitProvider {
|
||||||
if (typeof(this.config.url) !== 'string') return Promise.reject(new Error('url was not a valid url'))
|
if (typeof(this.config.url) !== 'string') return Promise.reject(new Error('url was not a valid url'))
|
||||||
try { new URL(this.config.url) }
|
try { new URL(this.config.url) }
|
||||||
catch (err) { return Promise.reject(new Error('url was not a valid url: ' + err.message)) }
|
catch (err) { return Promise.reject(new Error('url was not a valid url: ' + err.message)) }
|
||||||
|
|
||||||
|
return this.getLatestVersion()
|
||||||
|
.catch(function(err) {
|
||||||
|
return Promise.reject(new Error(`Error fetching latest release: ${err.message}`))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,9 +34,12 @@ export async function runner(root_import_meta_url, configname = 'config.json', d
|
||||||
const db = await GetDB(config, log, util.getPathFromRoot('./' + dbname))
|
const db = await GetDB(config, log, util.getPathFromRoot('./' + dbname))
|
||||||
|
|
||||||
const core = new Core(db, util, log, function(msg) {
|
const core = new Core(db, util, log, function(msg) {
|
||||||
let err = new Error('Got request to restart' + (msg ? ': ' + msg : ''))
|
if (msg) {
|
||||||
runner.log.fatal(err)
|
runner.log.warn('Got a restart request: ' + msg)
|
||||||
process.exit(0)
|
} else {
|
||||||
|
runner.log.warn('Got a restart request with no message or reason')
|
||||||
|
}
|
||||||
|
process.exit(1)
|
||||||
})
|
})
|
||||||
await core.init()
|
await core.init()
|
||||||
await core.run()
|
await core.run()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "service-core",
|
"name": "service-core",
|
||||||
"version": "3.0.2",
|
"version": "3.0.0-beta.13",
|
||||||
"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,9 @@ t.describe('#runVersion("static")', function() {
|
||||||
assert.strictEqual(checkCtx.app, app)
|
assert.strictEqual(checkCtx.app, app)
|
||||||
})
|
})
|
||||||
|
|
||||||
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.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 +62,9 @@ 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.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.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 +83,9 @@ t.describe('#runVersion("static")', function() {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
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.ctx.version, 'static')
|
|
||||||
|
|
||||||
assert.strictEqual(ctx.db.data.core.testapp.active, 'static')
|
assert.strictEqual(ctx.db.data.core.testapp.active, 'static')
|
||||||
})
|
})
|
||||||
|
@ -107,11 +101,9 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.config.heartbeatAttemptsWait = 5
|
app.config.heartbeatAttemptsWait = 5
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
|
||||||
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.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 +121,11 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.config.heartbeatAttemptsWait = 10
|
app.config.heartbeatAttemptsWait = 10
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
|
||||||
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.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 +150,9 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.config.heartbeatAttemptsWait = 5
|
app.config.heartbeatAttemptsWait = 5
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
|
||||||
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.ctx.version, '')
|
|
||||||
|
|
||||||
await app.closeServer()
|
await app.closeServer()
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
|
@ -185,11 +173,9 @@ t.describe('#runVersion("static")', function() {
|
||||||
app.registerModule(defaultHandler(handler))
|
app.registerModule(defaultHandler(handler))
|
||||||
app.isSlave = true
|
app.isSlave = true
|
||||||
|
|
||||||
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.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 +226,9 @@ t.describe('#runVersion("version")', function() {
|
||||||
app.config.port = assertPort
|
app.config.port = assertPort
|
||||||
stubFsStat.rejects(assertNotError)
|
stubFsStat.rejects(assertNotError)
|
||||||
|
|
||||||
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.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 +246,9 @@ 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.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.ctx.version, '')
|
|
||||||
|
|
||||||
assert.notStrictEqual(err, assertError)
|
assert.notStrictEqual(err, assertError)
|
||||||
assert.strictEqual(err.message, assertError.message)
|
assert.strictEqual(err.message, assertError.message)
|
||||||
|
@ -280,12 +262,10 @@ 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.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.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 +282,9 @@ 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.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.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)
|
||||||
|
|
|
@ -65,7 +65,6 @@ t.describe('constructor()', function() {
|
||||||
assert.strictEqual(app.config.clusterWaitOnCrash, 1 * 1000)
|
assert.strictEqual(app.config.clusterWaitOnCrash, 1 * 1000)
|
||||||
assert.strictEqual(app.ctx.db, ctx.db)
|
assert.strictEqual(app.ctx.db, ctx.db)
|
||||||
assert.strictEqual(app.ctx.app, app)
|
assert.strictEqual(app.ctx.app, app)
|
||||||
assert.strictEqual(app.ctx.config, app.config)
|
|
||||||
assert.strictEqual(app.ctx.util, ctx.util)
|
assert.strictEqual(app.ctx.util, ctx.util)
|
||||||
assert.strictEqual(app.ctx.sc.Util, Util)
|
assert.strictEqual(app.ctx.sc.Util, Util)
|
||||||
assert.strictEqual(app.ctx.sc.bunyan, bunyan)
|
assert.strictEqual(app.ctx.sc.bunyan, bunyan)
|
||||||
|
@ -74,7 +73,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.ctx.version, '')
|
assert.strictEqual(app.running, false)
|
||||||
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)
|
||||||
|
@ -329,13 +328,10 @@ t.describe('#closeServer()', function() {
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should call closeServer correctly', async function() {
|
t.test('should call closeServer correctly', async function() {
|
||||||
const assertNotVersion = 'v1521'
|
|
||||||
const assertError = new Error('Moonlight Fiesta')
|
const assertError = new Error('Moonlight Fiesta')
|
||||||
stubCloseServer.rejects(assertError)
|
stubCloseServer.rejects(assertError)
|
||||||
|
|
||||||
app.ctx.version = assertNotVersion
|
|
||||||
let err = await assert.isRejected(app.closeServer())
|
let err = await assert.isRejected(app.closeServer())
|
||||||
assert.strictEqual(app.ctx.version, '')
|
|
||||||
|
|
||||||
assert.strictEqual(err, assertError)
|
assert.strictEqual(err, assertError)
|
||||||
})
|
})
|
||||||
|
|
|
@ -166,9 +166,7 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
|
|
||||||
function parseLine(line) {
|
function parseLine(line) {
|
||||||
if (line[0] === '{') {
|
if (line[0] === '{') {
|
||||||
try {
|
|
||||||
return JSON.parse(line)
|
return JSON.parse(line)
|
||||||
} catch {}
|
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
msg: line
|
msg: line
|
||||||
|
@ -190,24 +188,6 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function safeTry(func) {
|
|
||||||
let lastException = null
|
|
||||||
for (let i = 0; i < 3; i++) {
|
|
||||||
if (i > 0) {
|
|
||||||
allLogs.push('[safeTry] Failed with error ' + lastException.message + ', trying agian')
|
|
||||||
await setTimeout(500)
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await func()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
lastException = err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw lastException
|
|
||||||
}
|
|
||||||
|
|
||||||
integrationLog.on('newlog', function(record) {
|
integrationLog.on('newlog', function(record) {
|
||||||
allLogs.push(JSON.stringify(record))
|
allLogs.push(JSON.stringify(record))
|
||||||
if (turnDebuggingOn) {
|
if (turnDebuggingOn) {
|
||||||
|
@ -295,7 +275,6 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
t.test('should be fully operational', async function() {
|
t.test('should be fully operational', async function() {
|
||||||
let db;
|
|
||||||
console.log()
|
console.log()
|
||||||
if (!turnDebuggingOn) { console.log('Running empty test') }
|
if (!turnDebuggingOn) { console.log('Running empty test') }
|
||||||
|
|
||||||
|
@ -314,13 +293,12 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
|
|
||||||
let secondLast = parseLine(logs[logs.length - 2])
|
let secondLast = parseLine(logs[logs.length - 2])
|
||||||
let last = parseLine(logs[logs.length - 1])
|
let last = parseLine(logs[logs.length - 1])
|
||||||
assert.match(secondLast.msg, /No/i)
|
assert.match(secondLast.msg, /creating/i)
|
||||||
assert.match(secondLast.msg, /versions/i)
|
assert.match(secondLast.msg, /application/i)
|
||||||
assert.match(secondLast.msg, /found/i)
|
assert.match(secondLast.msg, /testapp/i)
|
||||||
assert.match(last.msg, /starting/i)
|
assert.match(secondLast.msg, /0 releases/i)
|
||||||
assert.match(last.msg, /runner/i)
|
assert.match(last.err.message, /none/i)
|
||||||
assert.match(last.err.message, /stable/i)
|
assert.match(last.err.message, /successful/i)
|
||||||
assert.match(last.err.message, /application/i)
|
|
||||||
|
|
||||||
// Reset our log
|
// Reset our log
|
||||||
logs.splice(0, logs.length); logIndex = 0; logWaitIndex = 0;
|
logs.splice(0, logs.length); logIndex = 0; logWaitIndex = 0;
|
||||||
|
@ -351,13 +329,11 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
|
|
||||||
catchupLog()
|
catchupLog()
|
||||||
|
|
||||||
await safeTry(async function() {
|
let db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
||||||
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
|
||||||
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
||||||
assert.strictEqual(db.core[appname].versions.length, 1)
|
assert.strictEqual(db.core[appname].versions.length, 1)
|
||||||
assert.strictEqual(db.core[appname].versions[0].stable, 1)
|
assert.strictEqual(db.core[appname].versions[0].stable, 1)
|
||||||
assert.strictEqual(db.core[appname].versions[0].installed, true)
|
assert.strictEqual(db.core[appname].versions[0].installed, true)
|
||||||
})
|
|
||||||
|
|
||||||
// Create our second version
|
// Create our second version
|
||||||
await fs.writeFile(index, version_2_nolisten)
|
await fs.writeFile(index, version_2_nolisten)
|
||||||
|
@ -377,7 +353,7 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (appname !== 'testappcluster') {
|
if (appname !== 'testappcluster') {
|
||||||
while (!hasLogLine(/restart.*v2_nolisten.*dirty/)) {
|
while (!hasLogLine(/restart request.*v2_nolisten.*dirty/)) {
|
||||||
await catchupLog(10)
|
await catchupLog(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -386,7 +362,6 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
}
|
}
|
||||||
catchupLog()
|
catchupLog()
|
||||||
|
|
||||||
await safeTry(async function() {
|
|
||||||
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
||||||
assert.strictEqual(db.core[appname].active, assertNameVersion2)
|
assert.strictEqual(db.core[appname].active, assertNameVersion2)
|
||||||
assert.strictEqual(db.core[appname].versions.length, 2)
|
assert.strictEqual(db.core[appname].versions.length, 2)
|
||||||
|
@ -394,7 +369,6 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
assert.strictEqual(db.core[appname].versions[0].installed, true)
|
assert.strictEqual(db.core[appname].versions[0].installed, true)
|
||||||
assert.strictEqual(db.core[appname].versions[1].stable, 1)
|
assert.strictEqual(db.core[appname].versions[1].stable, 1)
|
||||||
assert.strictEqual(db.core[appname].versions[1].installed, true)
|
assert.strictEqual(db.core[appname].versions[1].installed, true)
|
||||||
})
|
|
||||||
|
|
||||||
// Since application was in dirty state, on next attempt should attempt to
|
// Since application was in dirty state, on next attempt should attempt to
|
||||||
// run v2 again and then falling back to v1
|
// run v2 again and then falling back to v1
|
||||||
|
@ -423,13 +397,11 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
await setTimeout(10)
|
await setTimeout(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
await safeTry(async function() {
|
|
||||||
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
||||||
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
||||||
assert.strictEqual(db.core[appname].versions.length, 2)
|
assert.strictEqual(db.core[appname].versions.length, 2)
|
||||||
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
||||||
assert.strictEqual(db.core[appname].versions[1].stable, 1)
|
assert.strictEqual(db.core[appname].versions[1].stable, 1)
|
||||||
})
|
|
||||||
|
|
||||||
assert.ok(findInLogs(/Attempting to run version v2_nolisten/))
|
assert.ok(findInLogs(/Attempting to run version v2_nolisten/))
|
||||||
assert.ok(findInLogs(/Error starting v2_nolisten/))
|
assert.ok(findInLogs(/Error starting v2_nolisten/))
|
||||||
|
@ -452,13 +424,11 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
await setTimeout(10)
|
await setTimeout(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
await safeTry(async function() {
|
|
||||||
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
||||||
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
||||||
assert.strictEqual(db.core[appname].versions.length, 2)
|
assert.strictEqual(db.core[appname].versions.length, 2)
|
||||||
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
||||||
assert.strictEqual(db.core[appname].versions[1].stable, 1)
|
assert.strictEqual(db.core[appname].versions[1].stable, 1)
|
||||||
})
|
|
||||||
|
|
||||||
assert.notOk(findInLogs(/Attempting to run version v2_nolisten/))
|
assert.notOk(findInLogs(/Attempting to run version v2_nolisten/))
|
||||||
assert.notOk(findInLogs(/Error starting v2_nolisten/))
|
assert.notOk(findInLogs(/Error starting v2_nolisten/))
|
||||||
|
@ -485,14 +455,12 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
await catchupLog(10)
|
await catchupLog(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
await safeTry(async function() {
|
|
||||||
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
||||||
assert.strictEqual(db.core[appname].active, assertNameVersion3)
|
assert.strictEqual(db.core[appname].active, assertNameVersion3)
|
||||||
assert.strictEqual(db.core[appname].versions.length, 3)
|
assert.strictEqual(db.core[appname].versions.length, 3)
|
||||||
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
||||||
assert.strictEqual(db.core[appname].versions[1].stable, -2)
|
assert.strictEqual(db.core[appname].versions[1].stable, -2)
|
||||||
assert.strictEqual(db.core[appname].versions[2].stable, 1)
|
assert.strictEqual(db.core[appname].versions[2].stable, 1)
|
||||||
})
|
|
||||||
|
|
||||||
catchupLog()
|
catchupLog()
|
||||||
|
|
||||||
|
@ -518,14 +486,12 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
await setTimeout(10)
|
await setTimeout(10)
|
||||||
}
|
}
|
||||||
|
|
||||||
await safeTry(async function() {
|
|
||||||
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
||||||
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
assert.strictEqual(db.core[appname].active, assertNameVersion1)
|
||||||
assert.strictEqual(db.core[appname].versions.length, 3)
|
assert.strictEqual(db.core[appname].versions.length, 3)
|
||||||
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
assert.strictEqual(db.core[appname].versions[0].stable, -2)
|
||||||
assert.strictEqual(db.core[appname].versions[1].stable, -2)
|
assert.strictEqual(db.core[appname].versions[1].stable, -2)
|
||||||
assert.strictEqual(db.core[appname].versions[2].stable, 1)
|
assert.strictEqual(db.core[appname].versions[2].stable, 1)
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create our fourth version
|
// Create our fourth version
|
||||||
|
@ -559,32 +525,11 @@ runners.forEach(function([runnerName, appname]) {
|
||||||
|
|
||||||
await setTimeout(10)
|
await setTimeout(10)
|
||||||
|
|
||||||
await safeTry(async function() {
|
|
||||||
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
db = JSON.parse(await fs.readFile(util.getPathFromRoot('./db.json')))
|
||||||
assert.strictEqual(db.core[appname].active, assertNameVersion4)
|
assert.strictEqual(db.core[appname].active, assertNameVersion4)
|
||||||
assert.strictEqual(db.core[appname].versions.length, 4)
|
assert.strictEqual(db.core[appname].versions.length, 4)
|
||||||
assert.strictEqual(db.core[appname].versions[0].stable, 1)
|
assert.strictEqual(db.core[appname].versions[0].stable, 1)
|
||||||
assert.strictEqual(db.core[appname].versions[1].stable, -2)
|
assert.strictEqual(db.core[appname].versions[1].stable, -2)
|
||||||
})
|
|
||||||
|
|
||||||
if (appname === 'testappcluster') {
|
|
||||||
let foundCore = false
|
|
||||||
let foundWorker = false
|
|
||||||
for (let line of allLogs) {
|
|
||||||
if (line.startsWith('[FROMWORKERCORE] test-runner-cluster')) {
|
|
||||||
foundCore = true
|
|
||||||
}
|
|
||||||
else if (line.startsWith('[FROMWORKERAPP] testappcluster-1')) {
|
|
||||||
foundWorker = true
|
|
||||||
}
|
|
||||||
if (foundCore && foundWorker) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.ok(foundCore)
|
|
||||||
assert.ok(foundWorker)
|
|
||||||
}
|
|
||||||
wasSuccessful = true
|
wasSuccessful = true
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import cluster from 'cluster'
|
|
||||||
import { Eltro as t, assert, stub } from 'eltro'
|
import { Eltro as t, assert, stub } from 'eltro'
|
||||||
import fs from 'fs/promises'
|
import fs from 'fs/promises'
|
||||||
import Core from '../core/core.mjs'
|
import Core from '../core/core.mjs'
|
||||||
|
@ -440,108 +439,6 @@ t.describe('#init()', function() {
|
||||||
assert.strictEqual(application.ctx.log.streams[1].level, 40)
|
assert.strictEqual(application.ctx.log.streams[1].level, 40)
|
||||||
assert.strictEqual(application.ctx.log.streams[1].type, 'stream')
|
assert.strictEqual(application.ctx.log.streams[1].type, 'stream')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should listen on cluster messages if one or more are cluster on', async function() {
|
|
||||||
const assertAppName1 = 'Dai Sagara Yoshiharu'
|
|
||||||
const assertAppName2 = 'Kuryo'
|
|
||||||
const assertCoreName = 'Ichuu'
|
|
||||||
const assertPayload1 = { a: 1 }
|
|
||||||
const assertPayload2 = { b: 2 }
|
|
||||||
const assertConfig = {
|
|
||||||
name: assertCoreName,
|
|
||||||
[assertAppName1]: {
|
|
||||||
provider: assertProviderName,
|
|
||||||
cluster: 2,
|
|
||||||
},
|
|
||||||
[assertAppName2]: {
|
|
||||||
provider: assertProviderName,
|
|
||||||
cluster: 1,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
db.config = assertConfig
|
|
||||||
fakeUtil.getAppNames.returns([assertAppName1, assertAppName2])
|
|
||||||
assert.strictEqual(core.applications.length, 0)
|
|
||||||
|
|
||||||
await core.init()
|
|
||||||
|
|
||||||
core.log.emit = stub()
|
|
||||||
|
|
||||||
assert.strictEqual(core.applications.length, 2)
|
|
||||||
|
|
||||||
let app1 = core.getApplication(assertAppName1)
|
|
||||||
let app2 = core.getApplication(assertAppName2)
|
|
||||||
|
|
||||||
app1.ctx.log.emit = stub()
|
|
||||||
app2.ctx.log.emit = stub()
|
|
||||||
|
|
||||||
cluster.emit('message', null, {
|
|
||||||
apptarget: app1.name,
|
|
||||||
type: 'newlog',
|
|
||||||
payload: assertPayload1
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.notOk(core.log.emit.called)
|
|
||||||
assert.ok(app1.ctx.log.emit.called)
|
|
||||||
assert.ok(app1.ctx.log.emit.firstCall[0], 'newlog')
|
|
||||||
assert.ok(app1.ctx.log.emit.firstCall[1], assertPayload1)
|
|
||||||
assert.notOk(app2.ctx.log.emit.called)
|
|
||||||
|
|
||||||
app1.ctx.log.emit.reset()
|
|
||||||
|
|
||||||
cluster.emit('message', null, {
|
|
||||||
apptarget: app2.name,
|
|
||||||
type: 'newlog',
|
|
||||||
payload: assertPayload2
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.notOk(core.log.emit.called)
|
|
||||||
assert.notOk(app1.ctx.log.emit.called)
|
|
||||||
assert.ok(app2.ctx.log.emit.called)
|
|
||||||
assert.ok(app2.ctx.log.emit.firstCall[0], 'newlog')
|
|
||||||
assert.ok(app2.ctx.log.emit.firstCall[1], assertPayload2)
|
|
||||||
|
|
||||||
app2.ctx.log.emit.reset()
|
|
||||||
|
|
||||||
let tests = [
|
|
||||||
null,
|
|
||||||
undefined,
|
|
||||||
12412,
|
|
||||||
'asdfag',
|
|
||||||
{},
|
|
||||||
{ apptarget: 12421, type: 'newlog', payload: {}},
|
|
||||||
{ apptarget: {}, type: 'newlog', payload: {}},
|
|
||||||
{ apptarget: null, type: 'newlog', payload: {}},
|
|
||||||
{ type: 'newlog', payload: {}},
|
|
||||||
{ apptarget: app1.name, type: 12421, payload: {}},
|
|
||||||
{ apptarget: app1.name, type: {}, payload: {}},
|
|
||||||
{ apptarget: app1.name, type: null, payload: {}},
|
|
||||||
{ apptarget: app1.name, payload: {}},
|
|
||||||
{ apptarget: app1.name, type: 'newlog', payload: 12421},
|
|
||||||
{ apptarget: app1.name, type: 'newlog', payload: null},
|
|
||||||
{ apptarget: app1.name, type: 'newlog', payload: 'test'},
|
|
||||||
]
|
|
||||||
|
|
||||||
tests.forEach(function(test) {
|
|
||||||
cluster.emit('message', null, test)
|
|
||||||
|
|
||||||
assert.notOk(core.log.emit.called)
|
|
||||||
assert.notOk(app1.ctx.log.emit.called)
|
|
||||||
assert.notOk(app2.ctx.log.emit.called)
|
|
||||||
})
|
|
||||||
|
|
||||||
cluster.emit('message', null, {
|
|
||||||
apptarget: assertCoreName,
|
|
||||||
type: 'newlog',
|
|
||||||
payload: assertPayload1
|
|
||||||
})
|
|
||||||
|
|
||||||
assert.notOk(app1.ctx.log.emit.called)
|
|
||||||
assert.notOk(app2.ctx.log.emit.called)
|
|
||||||
assert.ok(core.log.emit.called)
|
|
||||||
assert.ok(core.log.emit.called)
|
|
||||||
assert.ok(core.log.emit.firstCall[0], 'newlog')
|
|
||||||
assert.ok(core.log.emit.firstCall[1], assertPayload1)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.describe('#run()', function() {
|
t.describe('#run()', function() {
|
||||||
|
|
|
@ -86,7 +86,7 @@ export function prettyPrintMessage(line) {
|
||||||
console.log(err)
|
console.log(err)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
} catch { }
|
} catch (err){ console.log(err)}
|
||||||
}
|
}
|
||||||
console.log(line)
|
console.log(line)
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,26 +16,28 @@ 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, /\/download\//)
|
assert.match(version.link, /\/attachments\//)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
t.timeout(5000).describe('#checkConfig()', function() {
|
||||||
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() {
|
||||||
let err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/repos/thething/ProgramQueuer' }).getLatestVersion())
|
let err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/repos/thething/ProgramQueuer' }).checkConfig())
|
||||||
assert.match(err.message, /valid/i)
|
assert.match(err.message, /valid/i)
|
||||||
assert.match(err.message, /repository/i)
|
assert.match(err.message, /repository/i)
|
||||||
err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/orgs/nfp/repos' }).getLatestVersion())
|
err = await assert.isRejected(new GitProvider({ url: 'http://git.nfp.is/api/v1/orgs/nfp/repos' }).checkConfig())
|
||||||
assert.match(err.message, /service-core/i)
|
assert.match(err.message, /service-core/i)
|
||||||
assert.match(err.message, /release/i)
|
assert.match(err.message, /release/i)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should fail if no active release repository with assets', async function() {
|
t.test('should fail if no active release repository with assets', async function() {
|
||||||
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/thething/eltro/releases' }).getLatestVersion())
|
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/thething/eltro/releases' }).checkConfig())
|
||||||
assert.match(err.message, /service-core/i)
|
assert.match(err.message, /service-core/i)
|
||||||
assert.match(err.message, /release/i)
|
assert.match(err.message, /release/i)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should fail on private repositories', async function() {
|
t.test('should fail on private repositories', async function() {
|
||||||
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases' }).getLatestVersion())
|
let err = await assert.isRejected(new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases' }).checkConfig())
|
||||||
assert.match(err.message, /fail/i)
|
assert.match(err.message, /fail/i)
|
||||||
assert.match(err.message, /404/i)
|
assert.match(err.message, /404/i)
|
||||||
assert.match(err.message, /release/i)
|
assert.match(err.message, /release/i)
|
||||||
|
@ -43,19 +45,19 @@ t.timeout(5000).describe('#getLatestVersion()', function() {
|
||||||
|
|
||||||
t.test('should otherwise succeed', function() {
|
t.test('should otherwise succeed', function() {
|
||||||
return new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/sc-helloworld/releases' })
|
return new GitProvider({ url: 'https://git.nfp.is/api/v1/repos/TheThing/sc-helloworld/releases' })
|
||||||
.getLatestVersion()
|
.checkConfig()
|
||||||
})
|
})
|
||||||
|
|
||||||
let test = t
|
let test = t
|
||||||
if (!process.env.gittesttoken) {
|
if (!process.env.gittesttoken) {
|
||||||
console.log('Skipping "git.test.integration: #getLatestVersion() should succeed on private repo with token"')
|
console.log('Skipping "git.test.integration: #checkConfig() should succeed on private repo with token"')
|
||||||
test = test.skip()
|
test = test.skip()
|
||||||
}
|
}
|
||||||
test.test('should succeed on private repo with token', function() {
|
test.test('should succeed on private repo with token', function() {
|
||||||
return new GitProvider({
|
return new GitProvider({
|
||||||
token: process.env.gittesttoken.trim(),
|
token: process.env.gittesttoken.trim(),
|
||||||
url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases',
|
url: 'https://git.nfp.is/api/v1/repos/TheThing/privateexample/releases',
|
||||||
}).getLatestVersion()
|
}).checkConfig()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -20,25 +20,6 @@ t.describe('#getLatestVersion()', function() {
|
||||||
assert.strictEqual(version.log, '')
|
assert.strictEqual(version.log, '')
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should auto replace spaces with underscores result', async function() {
|
|
||||||
const assertOriginalName = 'The Smell Of Sea'
|
|
||||||
const assertCorrectName = 'The_Smell_Of_Sea'
|
|
||||||
const assertLink = 'Over The Future'
|
|
||||||
const assertFilename = 'test-sc.7z'
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({}, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: assertOriginalName, assets: [{ name: assertFilename, browser_download_url: assertLink }] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let version = await provider.getLatestVersion()
|
|
||||||
assert.strictEqual(version.version, assertCorrectName)
|
|
||||||
assert.strictEqual(version.link, assertLink)
|
|
||||||
assert.strictEqual(version.filename, assertFilename)
|
|
||||||
assert.strictEqual(version.log, '')
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should skip zip files for now', async function() {
|
t.test('should skip zip files for now', async function() {
|
||||||
const assertName = 'Karen'
|
const assertName = 'Karen'
|
||||||
const assertLink = 'My Wings'
|
const assertLink = 'My Wings'
|
||||||
|
@ -127,135 +108,6 @@ t.describe('#getLatestVersion()', function() {
|
||||||
assert.match(err.message, /found/)
|
assert.match(err.message, /found/)
|
||||||
})
|
})
|
||||||
|
|
||||||
// --
|
|
||||||
|
|
||||||
|
|
||||||
t.test('should return correct name and link in result when git_required_prefix is specified', async function() {
|
|
||||||
const assertName = 'Karen'
|
|
||||||
const assertLink = 'Over The Future'
|
|
||||||
const assertFilename = 'gittest_test-sc.7z'
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({ git_required_prefix: 'gittest' }, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: assertName, assets: [{ name: assertFilename, browser_download_url: assertLink }] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let version = await provider.getLatestVersion()
|
|
||||||
assert.strictEqual(version.version, assertName)
|
|
||||||
assert.strictEqual(version.link, assertLink)
|
|
||||||
assert.strictEqual(version.filename, assertFilename)
|
|
||||||
assert.strictEqual(version.log, '')
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should skip zip files for now even when git_required_prefix is specified', async function() {
|
|
||||||
const assertName = 'Karen'
|
|
||||||
const assertLink = 'My Wings'
|
|
||||||
const assertFilename = 'gittest_test-sc.zip'
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({ git_required_prefix: 'gittest' }, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: assertName, assets: [{ name: assertFilename, browser_download_url: assertLink }] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let err = await assert.isRejected(provider.getLatestVersion())
|
|
||||||
assert.match(err.message, /release/)
|
|
||||||
assert.match(err.message, /found/)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should skip versions with missing git_required_prefix prefix', async function() {
|
|
||||||
const assertName = 'name1'
|
|
||||||
const assertLink = 'somelink'
|
|
||||||
const assertFilename = 'gittest_something-sc.7z'
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({ git_required_prefix: 'gittest' }, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: 'test', assets: [] },
|
|
||||||
{ name: assertName, assets: [{ name: 'something-sc.7z', browser_download_url: 'nope' }] },
|
|
||||||
{ name: assertName, assets: [{ name: assertFilename, browser_download_url: assertLink }] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let version = await provider.getLatestVersion()
|
|
||||||
assert.strictEqual(version.version, assertName)
|
|
||||||
assert.strictEqual(version.link, assertLink)
|
|
||||||
assert.strictEqual(version.filename, assertFilename)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should skip versions with non-sc, non-git_required_prefix filename', async function() {
|
|
||||||
const assertName = 'name2'
|
|
||||||
const assertLink = 'somelink2'
|
|
||||||
const assertFilename = 'gittest_something-sc.7z'
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({ git_required_prefix: 'gittest' }, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: 'test', assets: [{ name: 'nope.7z', browser_download_url: 'nope' }] },
|
|
||||||
{ name: 'test', assets: [{ name: 'gittest_nope.7z', browser_download_url: 'nope' }] },
|
|
||||||
{ name: assertName, assets: [{ name: assertFilename, browser_download_url: assertLink }] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let version = await provider.getLatestVersion()
|
|
||||||
assert.strictEqual(version.version, assertName)
|
|
||||||
assert.strictEqual(version.link, assertLink)
|
|
||||||
assert.strictEqual(version.filename, assertFilename)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should skip assets with non-sc filename and non-git_required_prefix', async function() {
|
|
||||||
const assertName = 'name3'
|
|
||||||
const assertLink = 'somelink3'
|
|
||||||
const assertFilename = 'gittest_something-sc.7z'
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({ git_required_prefix: 'gittest' }, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: 'test', assets: [{ name: 'gittest_nope.7z', browser_download_url: 'nope' }] },
|
|
||||||
{ name: assertName, assets: [
|
|
||||||
{ name: 'nope.7z', browser_download_url: 'nope' },
|
|
||||||
{ name: 'gittest_nope.7z', browser_download_url: 'nope' },
|
|
||||||
{ name: 'something-sc.7z', browser_download_url: 'nope' },
|
|
||||||
{ name: assertFilename, browser_download_url: assertLink },
|
|
||||||
] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let version = await provider.getLatestVersion()
|
|
||||||
assert.strictEqual(version.version, assertName)
|
|
||||||
assert.strictEqual(version.link, assertLink)
|
|
||||||
assert.strictEqual(version.filename, assertFilename)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should otherwise reject non-git_required_prefix files', async function() {
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({ git_required_prefix: 'gittest' }, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: 'test', assets: [{ name: 'nope.7z', browser_download_url: 'nope' }] },
|
|
||||||
{ name: 'test2', assets: [{ name: 'nope2.7z', browser_download_url: 'nope' },] },
|
|
||||||
{ name: 'test3', assets: [{ name: 'nope2.7z', browser_download_url: 'nope' },] },
|
|
||||||
{ name: 'test3', assets: [{ name: 'something-sc.7z', browser_download_url: 'nope' },] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let err = await assert.isRejected(provider.getLatestVersion())
|
|
||||||
assert.match(err.message, /release/)
|
|
||||||
assert.match(err.message, /found/)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should otherwise reject', async function() {
|
|
||||||
let stubber = stub()
|
|
||||||
let provider = new GitProvider({}, stubber)
|
|
||||||
|
|
||||||
stubber.resolves({ body: [
|
|
||||||
{ name: 'test', assets: [{ name: 'nope.7z', browser_download_url: 'nope' }] },
|
|
||||||
{ name: 'test2', assets: [{ name: 'nope2.7z', browser_download_url: 'nope' },] },
|
|
||||||
{ name: 'test3', assets: [{ name: 'nope2.7z', browser_download_url: 'nope' },] },
|
|
||||||
]})
|
|
||||||
|
|
||||||
let err = await assert.isRejected(provider.getLatestVersion())
|
|
||||||
assert.match(err.message, /release/)
|
|
||||||
assert.match(err.message, /found/)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.test('should reject if not valid body', async function() {
|
t.test('should reject if not valid body', async function() {
|
||||||
let provider = new GitProvider({}, stub())
|
let provider = new GitProvider({}, stub())
|
||||||
|
|
||||||
|
@ -338,10 +190,19 @@ t.describe('#checkConfig()', function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.test('should not call requester with correct config and url', async function() {
|
t.test('should call requester with correct config and url', async function() {
|
||||||
|
const assertError = new Error('Toki wo Koeta Yoru')
|
||||||
|
const assertRequestConfig = { a: 1 }
|
||||||
const assertUrl = 'http://test'
|
const assertUrl = 'http://test'
|
||||||
|
|
||||||
let provider = new GitProvider({ url: assertUrl }, stub())
|
let provider = new GitProvider({ url: assertUrl }, stub())
|
||||||
let err = await provider.checkConfig()
|
provider.requestConfig = assertRequestConfig
|
||||||
assert.notOk(provider.requester.called)
|
provider.requester.rejects(assertError)
|
||||||
|
|
||||||
|
let err = await assert.isRejected(provider.checkConfig())
|
||||||
|
assert.notStrictEqual(err, assertError)
|
||||||
|
assert.match(err.message, new RegExp(assertError.message))
|
||||||
|
assert.strict(provider.requester.firstCall[0], assertRequestConfig)
|
||||||
|
assert.strict(provider.requester.firstCall[1], assertUrl)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -27,19 +27,6 @@ runner(import.meta.url, {
|
||||||
}, 'db.json')
|
}, 'db.json')
|
||||||
.then(
|
.then(
|
||||||
function(core) {
|
function(core) {
|
||||||
if (cluster.isPrimary) {
|
|
||||||
let app = core.applications[0]
|
|
||||||
app.ctx.log.on('newlog', function(record) {
|
|
||||||
if (record.name !== app.name) {
|
|
||||||
console.log(`[FROMWORKERAPP] ${record.name} (${record.pid}) ${record.msg}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
core.log.on('newlog', function(record) {
|
|
||||||
if (record.pid !== process.pid) {
|
|
||||||
console.log(`[FROMWORKERCORE] ${record.name} (${record.pid}) ${record.msg}`)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
core.log.info('core is running')
|
core.log.info('core is running')
|
||||||
},
|
},
|
||||||
function(err) {
|
function(err) {
|
||||||
|
|
Loading…
Reference in a new issue