-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_self.js
37 lines (31 loc) · 969 Bytes
/
test_self.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict'
const config = require('config')
config.port += 10000
require('./app')
const ilog = require('ilog')
const thunk = require('thunks')()
const urllib = require('urllib')
const mongo = require('./lib/service/limbo')
const redis = require('./lib/service/redis')
thunk.race([
function * () {
yield thunk.delay(3000)
throw new Error('Self test timeout!')
},
function * () {
let time = Date.now()
// should not shrow error.
ilog.info('Check Mongodb...')
ilog('Mongodb result', yield mongo.testSelf())
ilog.info('Check Redis...')
ilog('Redis result:', yield redis.testSelf())
ilog.info('Check App Server...')
let res = yield urllib.request(`http://localhost:${config.port}`)
if (res.status !== 200) throw new Error(`App failure: ${res.status}`)
ilog('App result:', res.res)
ilog.info(`Self test success, ${Date.now() - time} ms!`)
}
])((err) => {
if (err) ilog(err)
process.exit(err ? 1 : 0)
})