Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
weixin_46011646
wechaty
提交
eb8d79fa
W
wechaty
项目概览
weixin_46011646
/
wechaty
与 Fork 源项目一致
Fork自
wechaty / wechaty
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
W
wechaty
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
eb8d79fa
编写于
12月 08, 2016
作者:
Huan (李卓桓)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
do not reject a promise twice #122
上级
8423c0b2
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
23 addition
and
13 deletion
+23
-13
src/puppet-web/browser-driver.ts
src/puppet-web/browser-driver.ts
+15
-3
src/puppet-web/event.ts
src/puppet-web/event.ts
+6
-6
test/puppet-web/event.spec.ts
test/puppet-web/event.spec.ts
+2
-4
未找到文件。
src/puppet-web/browser-driver.ts
浏览文件 @
eb8d79fa
...
...
@@ -251,10 +251,15 @@ export class BrowserDriver {
*/
const
TIMEOUT
=
7
*
1000
const
timer
=
setTimeout
(()
=>
{
let
timer
:
NodeJS
.
Timer
|
null
timer
=
setTimeout
(()
=>
{
const
e
=
new
Error
(
'
valid() driver.getSession() timeout(halt?)
'
)
log
.
warn
(
'
PuppetWebBrowserDriver
'
,
e
.
message
)
// record timeout by set timer to null
timer
=
null
// 1. Promise rejected
return
reject
(
e
)
...
...
@@ -264,7 +269,10 @@ export class BrowserDriver {
driver
.
getSession
()
.
then
(
session
=>
{
log
.
verbose
(
'
PuppetWebBrowserDriver
'
,
'
valid() getSession() done
'
)
clearTimeout
(
timer
)
if
(
timer
)
{
clearTimeout
(
timer
)
timer
=
null
}
// 2. Promise resolved
return
resolve
(
session
)
...
...
@@ -274,7 +282,11 @@ export class BrowserDriver {
log
.
warn
(
'
PuppetWebBrowserDriver
'
,
'
valid() getSession() rejected: %s
'
,
e
&&
e
.
message
||
e
)
// 3. Promise rejected
return
reject
(
e
)
if
(
timer
)
{
// do not call reject again if there's already a timeout
timer
=
null
return
reject
(
e
)
}
})
...
...
src/puppet-web/event.ts
浏览文件 @
eb8d79fa
...
...
@@ -72,8 +72,8 @@ async function onBrowserDead(this: PuppetWeb, e: Error): Promise<void> {
const
TIMEOUT
=
180000
// 180s / 3m
// this.watchDog(`onBrowserDead() set a timeout of ${Math.floor(TIMEOUT / 1000)} seconds to prevent unknown state change`, {timeout: TIMEOUT})
this
.
emit
(
'
watchdog
'
,
{
data
:
`onBrowserDead() set a timeout of
${
Math
.
floor
(
TIMEOUT
/
1000
)}
seconds to prevent unknown state change`
,
timeout
:
TIMEOUT
data
:
`onBrowserDead() set a timeout of
${
Math
.
floor
(
TIMEOUT
/
1000
)}
seconds to prevent unknown state change`
,
timeout
:
TIMEOUT
,
})
this
.
scan
=
null
...
...
@@ -109,13 +109,13 @@ async function onBrowserDead(this: PuppetWeb, e: Error): Promise<void> {
}
log
.
verbose
(
'
PuppetWebEvent
'
,
'
onBrowserDead() ding() works well after reset
'
)
}
catch
(
e
)
{
log
.
error
(
'
PuppetWebEvent
'
,
'
onBrowserDead() exception: %s
'
,
e
.
message
)
}
catch
(
e
rr
)
{
log
.
error
(
'
PuppetWebEvent
'
,
'
onBrowserDead() exception: %s
'
,
e
rr
.
message
)
try
{
await
this
.
quit
()
await
this
.
init
()
}
catch
(
err
)
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() fail safe for this.quit(): %s
'
,
err
.
message
)
}
catch
(
err
or
)
{
log
.
warn
(
'
PuppetWebEvent
'
,
'
onBrowserDead() fail safe for this.quit(): %s
'
,
err
or
.
message
)
}
}
...
...
test/puppet-web/event.spec.ts
浏览文件 @
eb8d79fa
...
...
@@ -8,15 +8,13 @@
import
{
test
}
from
'
ava
'
import
{
Event
,
PuppetWeb
Event
,
PuppetWeb
,
}
from
'
../../src/puppet-web/
'
// const PORT = process.env.WECHATY_PORT || 58788
const
PROFILE
=
'
unit-test-session.wechaty.json
'
// const PuppetWeb = require('../../src/puppet-web')
test
(
'
Puppet Web Event smoking test
'
,
async
t
=>
{
let
pw
=
new
PuppetWeb
({
profile
:
PROFILE
})
t
.
truthy
(
pw
,
'
should instantiated a PuppetWeb
'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录