Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
gitlab-ce
Commits
d4cb1ec9
Commit
d4cb1ec9
authored
Aug 18, 2017
by
Mike Greiling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix unnecessarily long gl.utils.backOff test
parent
5a332c59
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
29 deletions
+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
No files found.
app/assets/javascripts/lib/utils/common_utils.js
View file @
d4cb1ec9
...
@@ -378,15 +378,15 @@
...
@@ -378,15 +378,15 @@
w
.
gl
.
utils
.
backOff
=
(
fn
,
timeout
=
60000
)
=>
{
w
.
gl
.
utils
.
backOff
=
(
fn
,
timeout
=
60000
)
=>
{
const
maxInterval
=
32000
;
const
maxInterval
=
32000
;
let
nextInterval
=
2000
;
let
nextInterval
=
2000
;
let
timeElapsed
=
0
;
const
startTime
=
Date
.
now
();
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
stop
=
arg
=>
((
arg
instanceof
Error
)
?
reject
(
arg
)
:
resolve
(
arg
));
const
stop
=
arg
=>
((
arg
instanceof
Error
)
?
reject
(
arg
)
:
resolve
(
arg
));
const
next
=
()
=>
{
const
next
=
()
=>
{
if
(
Date
.
now
()
-
startTime
<
timeout
)
{
if
(
timeElapsed
<
timeout
)
{
setTimeout
(
fn
.
bind
(
null
,
next
,
stop
),
nextInterval
);
setTimeout
(()
=>
fn
(
next
,
stop
),
nextInterval
);
timeElapsed
+=
nextInterval
;
nextInterval
=
Math
.
min
(
nextInterval
+
nextInterval
,
maxInterval
);
nextInterval
=
Math
.
min
(
nextInterval
+
nextInterval
,
maxInterval
);
}
else
{
}
else
{
reject
(
new
Error
(
'
BACKOFF_TIMEOUT
'
));
reject
(
new
Error
(
'
BACKOFF_TIMEOUT
'
));
...
...
spec/javascripts/lib/utils/common_utils_spec.js
View file @
d4cb1ec9
...
@@ -266,6 +266,12 @@ import '~/lib/utils/common_utils';
...
@@ -266,6 +266,12 @@ import '~/lib/utils/common_utils';
});
});
describe
(
'
gl.utils.backOff
'
,
()
=>
{
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
)
=>
{
it
(
'
solves the promise from the callback
'
,
(
done
)
=>
{
const
expectedResponseValue
=
'
Success!
'
;
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
(
gl
.
utils
.
backOff
((
next
,
stop
)
=>
(
...
@@ -299,37 +305,33 @@ import '~/lib/utils/common_utils';
...
@@ -299,37 +305,33 @@ import '~/lib/utils/common_utils';
let
numberOfCalls
=
1
;
let
numberOfCalls
=
1
;
const
expectedResponseValue
=
'
Success!
'
;
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
(
gl
.
utils
.
backOff
((
next
,
stop
)
=>
(
new
Promise
((
resolve
)
=>
{
Promise
.
resolve
(
expectedResponseValue
)
resolve
(
expectedResponseValue
);
.
then
((
resp
)
=>
{
}).
then
((
resp
)
=>
{
if
(
numberOfCalls
<
3
)
{
if
(
numberOfCalls
<
3
)
{
numberOfCalls
+=
1
;
numberOfCalls
+=
1
;
next
();
next
();
}
else
{
}
else
{
stop
(
resp
);
stop
(
resp
);
}
}
})
})
)).
then
((
respBackoff
)
=>
{
)).
then
((
respBackoff
)
=>
{
const
timeouts
=
window
.
setTimeout
.
calls
.
allArgs
().
map
(([,
timeout
])
=>
timeout
);
expect
(
timeouts
).
toEqual
([
2000
,
4000
]);
expect
(
respBackoff
).
toBe
(
expectedResponseValue
);
expect
(
respBackoff
).
toBe
(
expectedResponseValue
);
expect
(
numberOfCalls
).
toBe
(
3
);
done
();
done
();
});
});
}
,
10000
);
});
it
(
'
rejects the backOff promise after timing out
'
,
(
done
)
=>
{
it
(
'
rejects the backOff promise after timing out
'
,
(
done
)
=>
{
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
(
next
=>
next
(),
64000
)
gl
.
utils
.
backOff
(
next
=>
(
.
catch
((
errBackoffResp
)
=>
{
new
Promise
((
resolve
)
=>
{
const
timeouts
=
window
.
setTimeout
.
calls
.
allArgs
().
map
(([,
timeout
])
=>
timeout
);
resolve
(
expectedResponseValue
);
expect
(
timeouts
).
toEqual
([
2000
,
4000
,
8000
,
16000
,
32000
,
32000
]);
}).
then
(()
=>
{
expect
(
errBackoffResp
instanceof
Error
).
toBe
(
true
);
setTimeout
(
next
(),
5000
);
// it will time out
expect
(
errBackoffResp
.
message
).
toBe
(
'
BACKOFF_TIMEOUT
'
);
})
done
();
),
3000
).
catch
((
errBackoffResp
)
=>
{
});
expect
(
errBackoffResp
instanceof
Error
).
toBe
(
true
);
});
expect
(
errBackoffResp
.
message
).
toBe
(
'
BACKOFF_TIMEOUT
'
);
done
();
});
},
10000
);
});
});
describe
(
'
gl.utils.setFavicon
'
,
()
=>
{
describe
(
'
gl.utils.setFavicon
'
,
()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment