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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
f64fbf0e
Commit
f64fbf0e
authored
7 years ago
by
Jose Ivan Vargas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added unit tests for the w.gl.utils.backOff promise
parent
b26d4d2a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
changelogs/unreleased/add-test-backoff-util.yml
changelogs/unreleased/add-test-backoff-util.yml
+4
-0
spec/javascripts/lib/utils/common_utils_spec.js
spec/javascripts/lib/utils/common_utils_spec.js
+68
-0
No files found.
changelogs/unreleased/add-test-backoff-util.yml
0 → 100644
View file @
f64fbf0e
---
title
:
Added tests for the w.gl.utils.backOff promise
merge_request
:
author
:
This diff is collapsed.
Click to expand it.
spec/javascripts/lib/utils/common_utils_spec.js
View file @
f64fbf0e
/* eslint-disable arrow-body-style*/
require
(
'
~/lib/utils/common_utils
'
);
(()
=>
{
...
...
@@ -163,5 +164,72 @@ require('~/lib/utils/common_utils');
expect
(
gl
.
utils
.
isMetaClick
(
e
)).
toBe
(
true
);
});
});
describe
(
'
gl.utils.backOff
'
,
()
=>
{
it
(
'
solves the promise from the callback
'
,
(
done
)
=>
{
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
{
return
new
Promise
((
resolve
)
=>
{
resolve
(
expectedResponseValue
);
}).
then
((
resp
)
=>
{
stop
(
resp
);
});
}).
then
((
respBackoff
)
=>
{
expect
(
respBackoff
).
toBe
(
expectedResponseValue
);
done
();
});
});
it
(
'
catches the rejected promise from the callback
'
,
(
done
)
=>
{
const
errorMessage
=
'
Mistakes were made!
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
reject
(
new
Error
(
errorMessage
));
}).
then
((
resp
)
=>
{
stop
(
resp
);
}).
catch
(
err
=>
stop
(
err
));
}).
catch
((
errBackoffResp
)
=>
{
expect
(
errBackoffResp
instanceof
Error
).
toBe
(
true
);
expect
(
errBackoffResp
.
message
).
toBe
(
errorMessage
);
done
();
});
});
it
(
'
solves the promise correctly after retrying a third time
'
,
(
done
)
=>
{
let
numberOfCalls
=
1
;
const
expectedResponseValue
=
'
Success!
'
;
gl
.
utils
.
backOff
((
next
,
stop
)
=>
{
return
new
Promise
((
resolve
)
=>
{
resolve
(
expectedResponseValue
);
}).
then
((
resp
)
=>
{
if
(
numberOfCalls
<
3
)
{
numberOfCalls
+=
1
;
next
();
}
else
{
stop
(
resp
);
}
});
}).
then
((
respBackoff
)
=>
{
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
)
=>
{
return
new
Promise
((
resolve
)
=>
{
resolve
(
expectedResponseValue
);
}).
then
((
resp
)
=>
{
setTimeout
(
next
(
resp
),
5000
);
// it will time out
});
},
3000
).
catch
((
errBackoffResp
)
=>
{
expect
(
errBackoffResp
instanceof
Error
).
toBe
(
true
);
expect
(
errBackoffResp
.
message
).
toBe
(
'
BACKOFF_TIMEOUT
'
);
done
();
});
},
10000
);
});
});
})();
This diff is collapsed.
Click to expand it.
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