提交 fa319851 编写于 作者: Huan (李卓桓)'s avatar Huan (李卓桓)

add timeout for ding socket test

上级 b7da4146
...@@ -198,6 +198,7 @@ class Bridge { ...@@ -198,6 +198,7 @@ class Bridge {
const wechatyScript = `return Wechaty.${wechatyFunc}.apply(undefined, ${argsDecoded})` const wechatyScript = `return Wechaty.${wechatyFunc}.apply(undefined, ${argsDecoded})`
// log.silly('PuppetWebBridge', 'proxyWechaty(%s, ...args) %s', wechatyFunc, wechatyScript) // log.silly('PuppetWebBridge', 'proxyWechaty(%s, ...args) %s', wechatyFunc, wechatyScript)
return this.execute('return typeof Wechaty === "undefined"') return this.execute('return typeof Wechaty === "undefined"')
.then(noWechaty => { .then(noWechaty => {
if (noWechaty) { if (noWechaty) {
......
...@@ -35,13 +35,11 @@ test('PuppetWeb smoke testing', function(t) { ...@@ -35,13 +35,11 @@ test('PuppetWeb smoke testing', function(t) {
yield p1 yield p1
const p2 = new Promise((resolve) => { const p2 = new Promise((resolve) => {
pw.once('logout', r => { pw.once('logout', r => process.nextTick(() => { // wait to next tick for pw clean logined user status
process.nextTick(() => { // wait to next tick for pw clean logined user status // log.verbose('TestPuppetWeb', 'on(logout) received %s, islogined: %s', r, pw.logined())
// log.verbose('TestPuppetWeb', 'on(logout) received %s, islogined: %s', r, pw.logined()) t.equal(pw.logined() , false , 'should be logouted after logout event')
t.equal(pw.logined() , false , 'should be logouted after logout event') resolve()
resolve() }))
})
})
}) })
pw.server.emit('logout') pw.server.emit('logout')
yield p2 yield p2
...@@ -69,11 +67,11 @@ log.level = 'silly' ...@@ -69,11 +67,11 @@ log.level = 'silly'
const ret = yield dingSocket(pw.server) const ret = yield dingSocket(pw.server)
t.equal(ret, EXPECTED_DING_DATA, 'should got EXPECTED_DING_DATA after resolved dingSocket()') t.equal(ret, EXPECTED_DING_DATA, 'should got EXPECTED_DING_DATA after resolved dingSocket()')
}) })
.catch(e => { // Reject .catch(e => { // Reject
log.warn('TestPuppetWeb', 'error: %s', e) log.warn('TestPuppetWeb', 'error: %s', e)
t.fail(e) t.fail(e)
}) })
.then(r => { // Finally .then(r => { // Finally
pw.quit() pw.quit()
.then(t.end) .then(t.end)
...@@ -89,6 +87,11 @@ log.level = 'info' ...@@ -89,6 +87,11 @@ log.level = 'info'
let totalTime = 0 let totalTime = 0
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
log.verbose('TestPuppetWeb', 'dingSocket()') log.verbose('TestPuppetWeb', 'dingSocket()')
setTimeout(_ => {
reject('no response timeout after ' + 2 * maxTime)
}, 2 * maxTime)
return testDing() return testDing()
function testDing() { function testDing() {
...@@ -119,9 +122,9 @@ test('Puppet Web Self Message Identification', function(t) { ...@@ -119,9 +122,9 @@ test('Puppet Web Self Message Identification', function(t) {
t.ok(p, 'should instantiated a PuppetWeb') t.ok(p, 'should instantiated a PuppetWeb')
const EXPECTED_USER_ID = 'zixia' const EXPECTED_USER_ID = 'zixia'
p.userId = EXPECTED_USER_ID
const m = new Message() const m = new Message()
m.set('from', EXPECTED_USER_ID) m.set('from', EXPECTED_USER_ID)
p.userId = EXPECTED_USER_ID
t.ok(p.self(m), 'should identified self for message which from is self') t.ok(p.self(m), 'should identified self for message which from is self')
t.end() t.end()
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册