Skip to content

Commit 0fd6091

Browse files
committed
Fixes flaky saucelabs tests which are timing out. The fix will allow
for 2 more retrials when the browser script execution times out. Change-Id: I16732aee4501cb1b64cb91eb7f18ff7b325e6a02
1 parent 30fb017 commit 0fd6091

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

protractor_spec.js

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,43 @@ describe('Run all Closure unit tests', function() {
5656
*/
5757
var executeTest = function(testPath) {
5858
it('runs ' + testPath + ' with success', function(done) {
59-
browser.navigate()
60-
.to(TEST_SERVER + '/' + testPath)
61-
.then(function() {
62-
waitForTest(function(status) {
63-
expect(status).toBeSuccess();
64-
done();
59+
/**
60+
* Runs the test routines for a given test path and retries up to a
61+
* certain number of times on timeout.
62+
* @param {number} tries The number of times to retry on timeout.
63+
* @param {function} done The function to run on completion.
64+
*/
65+
var runRoutine = function(tries, done) {
66+
browser.navigate()
67+
.to(TEST_SERVER + '/' + testPath)
68+
.then(function() {
69+
waitForTest(function(status) {
70+
expect(status).toBeSuccess();
71+
done();
72+
}, function(err) {
73+
// If browser test execution times out try up to trial times.
74+
if (err.message &&
75+
err.message.indexOf('ETIMEDOUT') != -1 &&
76+
tries > 0) {
77+
runRoutine(tries - 1, done);
78+
} else {
79+
done.fail(err);
80+
}
81+
});
6582
}, function(err) {
66-
done.fail(err);
83+
// If browser test execution times out try up to trial times.
84+
if (err.message &&
85+
err.message.indexOf('ETIMEOUT') != -1 &&
86+
trial > 0) {
87+
runRoutine(tries - 1, done);
88+
} else {
89+
done.fail(err);
90+
}
6791
});
68-
});
92+
};
93+
// Run test routine. Set timeout retrial to 2 times, eg. test will try
94+
// 2 more times before giving up.
95+
runRoutine(2, done);
6996
});
7097
};
7198

0 commit comments

Comments
 (0)