Skip to content

Commit

Permalink
Retry license request on timeouts and errors
Browse files Browse the repository at this point in the history
Also removes the retry limit so that it will retry on failures until the test framework stops the test.

BUG=418952

Review URL: https://codereview.chromium.org/614423002

Cr-Commit-Position: refs/heads/master@{#297741}
  • Loading branch information
jrummell-chromium authored and Commit bot committed Oct 1, 2014
1 parent 2a859c8 commit a65005b
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions media/test/data/eme_player_js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,21 +214,21 @@ Utils.resetTitleChange = function() {
Utils.sendRequest = function(requestType, responseType, message, serverURL,
onSuccessCallbackFn, forceInvalidResponse) {
var requestAttemptCount = 0;
var MAXIMUM_REQUEST_ATTEMPTS = 3;
var REQUEST_RETRY_DELAY_MS = 3000;
var REQUEST_TIMEOUT_MS = 1000;

function sendRequestAttempt() {
// No limit on the number of retries. This will retry on failures
// until the test framework stops the test.
requestAttemptCount++;
if (requestAttemptCount == MAXIMUM_REQUEST_ATTEMPTS) {
Utils.failTest('FAILED: Exceeded maximum license request attempts.');
return;
}
var xmlhttp = new XMLHttpRequest();
xmlhttp.responseType = responseType;
xmlhttp.open(requestType, serverURL, true);
xmlhttp.onerror = function(e) {
Utils.timeLog('Request status: ' + this.statusText);
Utils.failTest('FAILED: License request XHR failed with network error.');
Utils.timeLog('FAILED: License request XHR failed with network error.');
Utils.timeLog('Retrying request in ' + REQUEST_RETRY_DELAY_MS + 'ms');
setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS);
};
xmlhttp.onload = function(e) {
if (this.status == 200) {
Expand All @@ -237,11 +237,16 @@ Utils.sendRequest = function(requestType, responseType, message, serverURL,
} else {
Utils.timeLog('Bad response status: ' + this.status);
Utils.timeLog('Bad response: ' + this.response);
Utils.timeLog('Retrying request if possible in ' +
REQUEST_RETRY_DELAY_MS + 'ms');
Utils.timeLog('Retrying request in ' + REQUEST_RETRY_DELAY_MS + 'ms');
setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS);
}
};
xmlhttp.timeout = REQUEST_TIMEOUT_MS;
xmlhttp.ontimeout = function(e) {
Utils.timeLog('Request timeout');
Utils.timeLog('Retrying request in ' + REQUEST_RETRY_DELAY_MS + 'ms');
setTimeout(sendRequestAttempt, REQUEST_RETRY_DELAY_MS);
}
Utils.timeLog('Attempt (' + requestAttemptCount +
'): sending request to server: ' + serverURL);
xmlhttp.send(message);
Expand Down

0 comments on commit a65005b

Please sign in to comment.