зеркало из https://github.com/mozilla/gecko-dev.git
Bug 878458 - improve error handling behavior of telemetry ping tests; r=vladan
This commit is contained in:
Родитель
ed62f84e19
Коммит
8cc535909e
|
@ -56,18 +56,38 @@ function dummyHandler(request, response) {
|
|||
return p;
|
||||
}
|
||||
|
||||
function wrapWithExceptionHandler(f) {
|
||||
function wrapper() {
|
||||
try {
|
||||
f.apply(null, arguments);
|
||||
} catch (ex if typeof(ex) == 'object') {
|
||||
dump("Caught exception: " + ex.message + "\n");
|
||||
dump(ex.stack);
|
||||
do_test_finished();
|
||||
}
|
||||
}
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
function addWrappedObserver(f, topic) {
|
||||
let wrappedObserver = wrapWithExceptionHandler(f);
|
||||
Services.obs.addObserver(function g(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(g, aTopic);
|
||||
wrappedObserver(aSubject, aTopic, aData);
|
||||
}, topic, false);
|
||||
}
|
||||
|
||||
function registerPingHandler(handler) {
|
||||
httpserver.registerPathHandler(TelemetryPing.submissionPath(), handler);
|
||||
httpserver.registerPathHandler(TelemetryPing.submissionPath(),
|
||||
wrapWithExceptionHandler(handler));
|
||||
}
|
||||
|
||||
function nonexistentServerObserver(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(nonexistentServerObserver, aTopic);
|
||||
|
||||
httpserver.start(4444);
|
||||
|
||||
// Provide a dummy function so it returns 200 instead of 404 to telemetry.
|
||||
registerPingHandler(dummyHandler);
|
||||
Services.obs.addObserver(telemetryObserver, "telemetry-test-xhr-complete", false);
|
||||
addWrappedObserver(telemetryObserver, "telemetry-test-xhr-complete");
|
||||
telemetry_ping();
|
||||
}
|
||||
|
||||
|
@ -98,7 +118,6 @@ function getSavedHistogramsFile(basename) {
|
|||
}
|
||||
|
||||
function telemetryObserver(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(telemetryObserver, aTopic);
|
||||
registerPingHandler(checkHistogramsSync);
|
||||
let histogramsFile = getSavedHistogramsFile("saved-histograms.dat");
|
||||
setupTestData();
|
||||
|
@ -275,7 +294,7 @@ function checkPersistedHistogramsSync(request, response) {
|
|||
// saved.
|
||||
checkPayload(request, "saved-session", 1);
|
||||
|
||||
Services.obs.addObserver(runAsyncTestObserver, "telemetry-test-xhr-complete", false);
|
||||
addWrappedObserver(runAsyncTestObserver, "telemetry-test-xhr-complete");
|
||||
}
|
||||
|
||||
function checkHistogramsSync(request, response) {
|
||||
|
@ -284,20 +303,16 @@ function checkHistogramsSync(request, response) {
|
|||
}
|
||||
|
||||
function runAsyncTestObserver(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(runAsyncTestObserver, aTopic);
|
||||
registerPingHandler(checkHistogramsAsync);
|
||||
let histogramsFile = getSavedHistogramsFile("saved-histograms2.dat");
|
||||
|
||||
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee, aTopic);
|
||||
|
||||
Services.obs.addObserver(function(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(arguments.callee, aTopic);
|
||||
addWrappedObserver(function(aSubject, aTopic, aData) {
|
||||
addWrappedObserver(function(aSubject, aTopic, aData) {
|
||||
telemetry_ping();
|
||||
}, "telemetry-test-load-complete", false);
|
||||
}, "telemetry-test-load-complete");
|
||||
|
||||
TelemetryPing.testLoadHistograms(histogramsFile, false);
|
||||
}, "telemetry-test-save-complete", false);
|
||||
}, "telemetry-test-save-complete");
|
||||
TelemetryPing.saveHistograms(histogramsFile, false);
|
||||
}
|
||||
|
||||
|
@ -309,9 +324,9 @@ function checkPersistedHistogramsAsync(request, response) {
|
|||
// saved.
|
||||
checkPayload(request, "saved-session", 3);
|
||||
|
||||
gFinished = true;
|
||||
|
||||
runOldPingFileTest();
|
||||
|
||||
gFinished = true;
|
||||
}
|
||||
|
||||
function checkHistogramsAsync(request, response) {
|
||||
|
@ -501,12 +516,12 @@ function run_test() {
|
|||
});
|
||||
});
|
||||
|
||||
Telemetry.asyncFetchTelemetryData(function () {
|
||||
actualTest();
|
||||
});
|
||||
Telemetry.asyncFetchTelemetryData(wrapWithExceptionHandler(actualTest));
|
||||
}
|
||||
|
||||
function actualTest() {
|
||||
// ensure that test runs to completion
|
||||
do_register_cleanup(function () do_check_true(gFinished));
|
||||
// try to make LightweightThemeManager do stuff
|
||||
let gInternalManager = Cc["@mozilla.org/addons/integration;1"]
|
||||
.getService(Ci.nsIObserver)
|
||||
|
@ -520,11 +535,9 @@ function actualTest() {
|
|||
|
||||
runInvalidJSONTest();
|
||||
|
||||
Services.obs.addObserver(nonexistentServerObserver, "telemetry-test-xhr-complete", false);
|
||||
addWrappedObserver(nonexistentServerObserver, "telemetry-test-xhr-complete");
|
||||
telemetry_ping();
|
||||
// spin the event loop
|
||||
do_test_pending();
|
||||
// ensure that test runs to completion
|
||||
do_register_cleanup(function () do_check_true(gFinished));
|
||||
do_test_finished();
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче