Bug 1379145 - Use Policy in TelemetrySend.jsm to set up/reset custom timeout. r=gfritzsche

--HG--
extra : rebase_source : 71e52a397bc6ad8218f9d53a754ce4009f647652
This commit is contained in:
Kate Ustiuzhanina 2017-08-07 17:51:07 +01:00
Родитель 3cfadb8e23
Коммит 4db629f8f6
2 изменённых файлов: 10 добавлений и 13 удалений

Просмотреть файл

@ -106,6 +106,7 @@ const XHR_ERROR_TYPE = [
var Policy = {
now: () => new Date(),
midnightPingFuzzingDelay: () => MIDNIGHT_FUZZING_DELAY_MS,
pingSubmissionTimeout: () => PING_SUBMIT_TIMEOUT_MS,
setSchedulerTickTimeout: (callback, delayMs) => setTimeout(callback, delayMs),
clearSchedulerTickTimeout: (id) => clearTimeout(id),
};
@ -180,14 +181,6 @@ this.TelemetrySend = {
return TelemetrySendImpl.pendingPingCount;
},
testSetTimeoutForPingSubmit(timeoutInMS) {
TelemetrySendImpl._pingSubmissionTimeout = timeoutInMS;
},
testResetTimeOutToDefault() {
TelemetrySendImpl._pingSubmissionTimeout = PING_SUBMIT_TIMEOUT_MS;
},
/**
* Partial setup that runs immediately at startup. This currently triggers
* the crash report annotations.
@ -594,8 +587,6 @@ var TelemetrySendImpl = {
// Count of pending pings that were overdue.
_overduePingCount: 0,
_pingSubmissionTimeout: PING_SUBMIT_TIMEOUT_MS,
OBSERVER_TOPICS: [
TOPIC_IDLE_DAILY,
TOPIC_QUIT_APPLICATION_GRANTED,
@ -1093,7 +1084,7 @@ var TelemetrySendImpl = {
let request = new ServiceRequest();
request.mozBackgroundRequest = true;
request.timeout = this._pingSubmissionTimeout;
request.timeout = Policy.pingSubmissionTimeout();
request.open("POST", url, true);
request.overrideMimeType("text/plain");

Просмотреть файл

@ -43,6 +43,11 @@ async function waitForConditionWithPromise(promiseFn, timeoutMsg, tryCount = 30)
throw new Error(timeoutMsg);
}
function fakeSendSubmissionTimeout(timeOut) {
let telemetryHealthPing = Cu.import("resource://gre/modules/TelemetrySend.jsm", {});
telemetryHealthPing.Policy.pingSubmissionTimeout = () => timeOut;
}
add_task(async function setup() {
// Trigger a proper telemetry init.
do_get_profile(true);
@ -155,7 +160,7 @@ add_task(async function test_sendOnTimeout() {
fakePingSendTimer(() => {}, () => {});
// Set up small ping submission timeout to always have timeout error.
TelemetrySend.testSetTimeoutForPingSubmit(2);
fakeSendSubmissionTimeout(2);
await TelemetryController.submitExternalPing(PING_TYPE, {});
@ -178,7 +183,8 @@ add_task(async function test_sendOnTimeout() {
response.finish();
}
TelemetrySend.testResetTimeOutToDefault();
let telemetryHealthPing = Cu.import("resource://gre/modules/TelemetrySend.jsm", {});
fakeSendSubmissionTimeout(telemetryHealthPing.PING_SUBMIT_TIMEOUT_MS);
PingServer.resetPingHandler();
TelemetrySend.notifyCanUpload();