Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(621)

Unified Diff: Tools/GardeningServer/lib/network-simulator.html

Issue 536163002: Teach the network simulator to wait for Promises. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Tools/GardeningServer/lib/network-simulator.html
diff --git a/Tools/GardeningServer/lib/network-simulator.html b/Tools/GardeningServer/lib/network-simulator.html
index 9583bdc846b0f30f2507d08d90b38109e8fa5268..e20bbb6277c6e5933743253dd995ec0b79a9c279 100644
--- a/Tools/GardeningServer/lib/network-simulator.html
+++ b/Tools/GardeningServer/lib/network-simulator.html
@@ -44,14 +44,14 @@ NetworkSimulator.prototype.runTest = function(testCase) {
NetworkSimulator._testInProgress = true;
var self = this;
- return new Promise(function(resolve, reject) {
Jeffrey Yasskin 2014/09/03 22:11:50 I think it's an antipattern to use the resolve/rej
- var realNet = window.net;
+ var realNet = window.net;
- function reset() {
- window.net = realNet;
- NetworkSimulator._testInProgress = false;
- }
+ function reset() {
+ window.net = realNet;
+ NetworkSimulator._testInProgress = false;
+ }
+ return Promise.resolve().then(function() {
// All net.* methods should return promises. This watches all
// promises generated by test-overridden methods.
window.net = {};
@@ -63,23 +63,20 @@ NetworkSimulator.prototype.runTest = function(testCase) {
};
};
});
-
- try {
- testCase();
- } catch(e) {
- // Make sure errors thrown in the test case don't leave window.net in a bad state.
- reset();
- self._assert(false, "Test case threw an error:" + e);
- }
-
- self.resolvePromises().then(function() {
+ }).then(function() {
+ return testCase();
+ }).catch(function(e) {
+ // Make sure errors thrown in the test case don't leave window.net in a bad state.
+ reset();
+ throw e;
+ }).then(function() {
+ return self.resolvePromises().then(function() {
Jeffrey Yasskin 2014/09/03 22:11:50 I'm not sure we need the resolvePromises() step an
reset();
self._assert(window.net == realNet);
- resolve();
}).catch(function(e) {
reset();
- self._assert(false, "Failed to finish test: " + e);
- });
- });
+ self._assert(false, "Failed to finish test:" + e);
Jeffrey Yasskin 2014/09/03 22:11:50 I'm not sure if we want to throw a string here or
ojan 2014/09/04 18:26:53 I think this is fine for now. Or, we could just do
Jeffrey Yasskin 2014/09/04 18:48:11 Two _assert calls doesn't help: Chai uses exceptio
+ })
+ }).then(this._done, this._done);
Jeffrey Yasskin 2014/09/03 22:11:50 Mocha actually supports returning promises from th
ojan 2014/09/04 18:26:53 sgtm
Jeffrey Yasskin 2014/09/04 18:48:11 After experimenting a bit, it looks safer to keep
};
</script>

Powered by Google App Engine
This is Rietveld 408576698