mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-28 12:45:27 +00:00
Bug 1348626 - Retry when isPinged() failed to avoid false alarm. r=francois
MozReview-Commit-ID: BOdJZReICxZ --HG-- extra : rebase_source : 16e0b0b1a65d0bc1249ff0583947acd39defb5d9
This commit is contained in:
parent
9ebde30215
commit
c6fa23934d
@ -21,6 +21,7 @@
|
||||
const host_track = "http://trackertest.org/";
|
||||
const path_ping = "tests/toolkit/components/url-classifier/tests/mochitest/ping.sjs";
|
||||
const TP_ENABLE_PREF = "privacy.trackingprotection.enabled";
|
||||
const RETRY_TIMEOUT_MS = 200;
|
||||
|
||||
var testData = [
|
||||
{ url: "trackertest.org/",
|
||||
@ -37,9 +38,8 @@
|
||||
ping(id, host_nottrack);
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
setTimeout(function() {
|
||||
isPinged(id, expectPing, msg, resolve);
|
||||
}, timeout);
|
||||
// Retry at most 30 seconds.
|
||||
isPingedWithRetry(id, expectPing, msg, resolve, 30 * 1000 / RETRY_TIMEOUT_MS);
|
||||
});
|
||||
}
|
||||
|
||||
@ -85,19 +85,30 @@
|
||||
document.body.removeChild(elm);
|
||||
}
|
||||
|
||||
function isPinged(id, expected, msg, callback) {
|
||||
function isPingedWithRetry(id, expected, msg, callback, retryCnt) {
|
||||
var url = "http://mochi.test:8888/" + path_ping;
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', url + "?id=" + id);
|
||||
xhr.onload = function() {
|
||||
var isPinged = xhr.response === "ping";
|
||||
is(expected, isPinged, msg);
|
||||
|
||||
callback();
|
||||
let success = isPinged === expected;
|
||||
if (success || 0 === retryCnt) {
|
||||
is(expected, isPinged, msg);
|
||||
callback();
|
||||
return;
|
||||
}
|
||||
// Retry on failure.
|
||||
setTimeout(() => {
|
||||
isPingedWithRetry(id, expected, msg, callback, retryCnt - 1);
|
||||
}, RETRY_TIMEOUT_MS);
|
||||
};
|
||||
xhr.send();
|
||||
}
|
||||
|
||||
function isPinged(id, expected, msg, callback) {
|
||||
isPingedWithRetry(id, expected, msg, callback, 0);
|
||||
}
|
||||
|
||||
function cleanup() {
|
||||
SpecialPowers.clearUserPref(TP_ENABLE_PREF);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user