Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
d4cb1ec9
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d4cb1ec9
编写于
8月 18, 2017
作者:
M
Mike Greiling
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix unnecessarily long gl.utils.backOff test
上级
5a332c59
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
31 addition
and
29 deletion
+31
-29
app/assets/javascripts/lib/utils/common_utils.js
app/assets/javascripts/lib/utils/common_utils.js
+4
-4
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+27
-25
未找到文件。
app/assets/javascripts/lib/utils/common_utils.js
浏览文件 @
d4cb1ec9
...
...
@@ -378,15 +378,15 @@
w
.
gl
.
utils
.
backOff
=
(
fn
,
timeout
=
60000
)
=>
{
const
maxInterval
=
32000
;
let
nextInterval
=
2000
;
const
startTime
=
Date
.
now
();
let
timeElapsed
=
0
;
return
new
Promise
((
resolve
,
reject
)
=>
{
const
stop
=
arg
=>
((
arg
instanceof
Error
)
?
reject
(
arg
)
:
resolve
(
arg
));
const
next
=
()
=>
{
if
(
Date
.
now
()
-
startTime
<
timeout
)
{
setTimeout
(
fn
.
bind
(
null
,
next
,
stop
),
nextInterval
);
if
(
timeElapsed
<
timeout
)
{
setTimeout
(()
=>
fn
(
next
,
stop
),
nextInterval
);
timeElapsed
+=
nextInterval
;
nextInterval
=
Math
.
min
(
nextInterval
+
nextInterval
,
maxInterval
);
}
else
{
reject
(
new
Error
(
'
BACKOFF_TIMEOUT
'
));
...
...
spec/javascripts/lib/utils/common_utils_spec.js
浏览文件 @
d4cb1ec9
...
...
@@ -266,6 +266,12 @@ import '~/lib/utils/common_utils';
});
describe
(
'
gl.utils.backOff
'
,
()
=>
{
beforeEach
(()
=>
{
// shortcut our timeouts otherwise these tests will take a long time to finish
const
origSetTimeout
=
window
.
setTimeout
;
spyOn
(
window
,
'
setTimeout
'
).
and
.
callFake
(
cb
=>
origSetTimeout
(
cb
,
0
));
});
it
(
'
solves the promise from the callback
'
,
(
done
)
=>
{
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
(
...
...
@@ -299,37 +305,33 @@ import '~/lib/utils/common_utils';
let
numberOfCalls
=
1
;
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
(
new
Promise
((
resolve
)
=>
{
resolve
(
expectedResponseValue
);
}).
then
((
resp
)
=>
{
if
(
numberOfCalls
<
3
)
{
numberOfCalls
+=
1
;
next
();
}
else
{
stop
(
resp
);
}
})
Promise
.
resolve
(
expectedResponseValue
)
.
then
((
resp
)
=>
{
if
(
numberOfCalls
<
3
)
{
numberOfCalls
+=
1
;
next
();
}
else
{
stop
(
resp
);
}
})
)).
then
((
respBackoff
)
=>
{
const
timeouts
=
window
.
setTimeout
.
calls
.
allArgs
().
map
(([,
timeout
])
=>
timeout
);
expect
(
timeouts
).
toEqual
([
2000
,
4000
]);
expect
(
respBackoff
).
toBe
(
expectedResponseValue
);
expect
(
numberOfCalls
).
toBe
(
3
);
done
();
});
}
,
10000
);
});
it
(
'
rejects the backOff promise after timing out
'
,
(
done
)
=>
{
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
(
next
=>
(
new
Promise
((
resolve
)
=>
{
resolve
(
expectedResponseValue
);
}).
then
(()
=>
{
setTimeout
(
next
(),
5000
);
// it will time out
})
),
3000
).
catch
((
errBackoffResp
)
=>
{
expect
(
errBackoffResp
instanceof
Error
).
toBe
(
true
);
expect
(
errBackoffResp
.
message
).
toBe
(
'
BACKOFF_TIMEOUT
'
);
done
();
});
},
10000
);
gl
.
utils
.
backOff
(
next
=>
next
(),
64000
)
.
catch
((
errBackoffResp
)
=>
{
const
timeouts
=
window
.
setTimeout
.
calls
.
allArgs
().
map
(([,
timeout
])
=>
timeout
);
expect
(
timeouts
).
toEqual
([
2000
,
4000
,
8000
,
16000
,
32000
,
32000
]);
expect
(
errBackoffResp
instanceof
Error
).
toBe
(
true
);
expect
(
errBackoffResp
.
message
).
toBe
(
'
BACKOFF_TIMEOUT
'
);
done
();
});
});
});
describe
(
'
gl.utils.setFavicon
'
,
()
=>
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录