mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 735768 - Part 3 - add tests for persistent telemetry; r=taras
This commit is contained in:
parent
046e3b1fb4
commit
9ecebcf230
@ -1464,10 +1464,15 @@ private:
|
||||
|
||||
NS_IMETHODIMP
|
||||
TelemetryImpl::LoadHistograms(nsIFile *file,
|
||||
nsITelemetryLoadSessionDataCallback *callback)
|
||||
nsITelemetryLoadSessionDataCallback *callback,
|
||||
bool isSynchronous)
|
||||
{
|
||||
nsCOMPtr<nsIRunnable> event = new LoadHistogramEvent(file, callback);
|
||||
return NS_DispatchToCurrentThread(event);
|
||||
if (isSynchronous) {
|
||||
return event ? event->Run() : NS_ERROR_FAILURE;
|
||||
} else {
|
||||
return NS_DispatchToCurrentThread(event);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
|
@ -635,12 +635,15 @@ TelemetryPing.prototype = {
|
||||
delete self._timer
|
||||
}
|
||||
this._timer.initWithCallback(timerCallback, TELEMETRY_DELAY, Ci.nsITimer.TYPE_ONE_SHOT);
|
||||
this.loadHistograms(this.savedHistogramsFile(), false);
|
||||
},
|
||||
|
||||
// Load data from the previous session.
|
||||
loadHistograms: function loadHistograms(file, sync) {
|
||||
let self = this;
|
||||
let loadCallback = function(data) {
|
||||
self._prevSession = data;
|
||||
}
|
||||
Telemetry.loadHistograms(this.savedHistogramsFile(), loadCallback);
|
||||
Telemetry.loadHistograms(file, loadCallback, sync);
|
||||
},
|
||||
|
||||
/**
|
||||
@ -715,6 +718,14 @@ TelemetryPing.prototype = {
|
||||
|
||||
aSubject.QueryInterface(Ci.nsISupportsString).data = data.payload;
|
||||
break;
|
||||
case "test-save-histograms":
|
||||
Telemetry.saveHistograms(aSubject.QueryInterface(Ci.nsILocalFile),
|
||||
aData, function (success) success,
|
||||
/*isSynchronous=*/true);
|
||||
break;
|
||||
case "test-load-histograms":
|
||||
this.loadHistograms(aSubject.QueryInterface(Ci.nsILocalFile), true);
|
||||
break;
|
||||
case "test-ping":
|
||||
server = aData;
|
||||
// fall through
|
||||
|
@ -192,7 +192,8 @@ interface nsITelemetry : nsISupports
|
||||
* @param callback - function to process histogram information
|
||||
*/
|
||||
void loadHistograms(in nsIFile file,
|
||||
in nsITelemetryLoadSessionDataCallback callback);
|
||||
in nsITelemetryLoadSessionDataCallback callback,
|
||||
in bool isSynchronous);
|
||||
|
||||
/**
|
||||
* Set this to false to disable gathering of telemetry statistics.
|
||||
|
@ -12,7 +12,9 @@ do_load_httpd_js();
|
||||
Cu.import("resource://gre/modules/Services.jsm");
|
||||
Cu.import("resource://gre/modules/LightweightThemeManager.jsm");
|
||||
|
||||
const gTestUUID = "3512c938-d9d2-4722-a575-a7f67086d3b2";
|
||||
const PATH = "/submit/telemetry/test-ping";
|
||||
const SAVED_PATH = "/submit/telemetry/" + gTestUUID;
|
||||
const SERVER = "http://localhost:4444";
|
||||
const IGNORE_HISTOGRAM = "test::ignore_me";
|
||||
const IGNORE_HISTOGRAM_TO_CLONE = "MEMORY_HEAP_ALLOCATED";
|
||||
@ -46,16 +48,26 @@ function nonexistentServerObserver(aSubject, aTopic, aData) {
|
||||
|
||||
function telemetryObserver(aSubject, aTopic, aData) {
|
||||
Services.obs.removeObserver(telemetryObserver, aTopic);
|
||||
httpserver.registerPathHandler(PATH, checkHistograms);
|
||||
httpserver.registerPathHandler(PATH, checkPersistedHistograms);
|
||||
Telemetry.newHistogram(IGNORE_HISTOGRAM, 1, 2, 3, Telemetry.HISTOGRAM_BOOLEAN);
|
||||
Telemetry.histogramFrom(IGNORE_CLONED_HISTOGRAM, IGNORE_HISTOGRAM_TO_CLONE);
|
||||
Services.startup.interrupted = true;
|
||||
let dirService = Cc["@mozilla.org/file/directory_service;1"]
|
||||
.getService(Ci.nsIProperties);
|
||||
let tmpDir = dirService.get("TmpD", Ci.nsILocalFile);
|
||||
let histogramsFile = tmpDir.clone();
|
||||
histogramsFile.append("saved-histograms.dat");
|
||||
if (histogramsFile.exists()) {
|
||||
histogramsFile.remove(true);
|
||||
}
|
||||
do_register_cleanup(function () histogramsFile.remove(true));
|
||||
const TelemetryPing = Cc["@mozilla.org/base/telemetry-ping;1"].getService(Ci.nsIObserver);
|
||||
TelemetryPing.observe(histogramsFile, "test-save-histograms", gTestUUID);
|
||||
TelemetryPing.observe(histogramsFile, "test-load-histograms", null);
|
||||
telemetry_ping();
|
||||
}
|
||||
|
||||
function checkHistograms(request, response) {
|
||||
// do not need the http server anymore
|
||||
httpserver.stop(do_test_finished);
|
||||
function decodeRequestPayload(request) {
|
||||
let s = request.bodyInputStream;
|
||||
let payload = null;
|
||||
let decoder = Cc["@mozilla.org/dom/json;1"].createInstance(Ci.nsIJSON)
|
||||
@ -83,12 +95,12 @@ function checkHistograms(request, response) {
|
||||
payload = decoder.decodeFromStream(s, s.available());
|
||||
}
|
||||
|
||||
do_check_eq(request.getHeader("content-type"), "application/json; charset=UTF-8");
|
||||
do_check_true(payload.simpleMeasurements.uptime >= 0);
|
||||
do_check_true(payload.simpleMeasurements.startupInterrupted === 1);
|
||||
return payload;
|
||||
}
|
||||
|
||||
function checkPayloadInfo(payload, reason) {
|
||||
// get rid of the non-deterministic field
|
||||
const expected_info = {
|
||||
reason: "test-ping",
|
||||
OS: "XPCShell",
|
||||
appID: "xpcshell@tests.mozilla.org",
|
||||
appVersion: "1",
|
||||
@ -101,6 +113,7 @@ function checkHistograms(request, response) {
|
||||
do_check_eq(payload.info[f], expected_info[f]);
|
||||
}
|
||||
|
||||
do_check_eq(payload.info.reason, reason);
|
||||
do_check_true("appUpdateChannel" in payload.info);
|
||||
do_check_true("locale" in payload.info);
|
||||
|
||||
@ -118,6 +131,24 @@ function checkHistograms(request, response) {
|
||||
}
|
||||
catch (x) {
|
||||
}
|
||||
}
|
||||
|
||||
function checkPersistedHistograms(request, response) {
|
||||
let payload = decodeRequestPayload(request);
|
||||
|
||||
checkPayloadInfo(payload, "saved-session");
|
||||
httpserver.registerPathHandler(PATH, checkHistograms);
|
||||
}
|
||||
|
||||
function checkHistograms(request, response) {
|
||||
// do not need the http server anymore
|
||||
httpserver.stop(do_test_finished);
|
||||
let payload = decodeRequestPayload(request);
|
||||
|
||||
checkPayloadInfo(payload, "test-ping");
|
||||
do_check_eq(request.getHeader("content-type"), "application/json; charset=UTF-8");
|
||||
do_check_true(payload.simpleMeasurements.uptime >= 0);
|
||||
do_check_true(payload.simpleMeasurements.startupInterrupted === 1);
|
||||
|
||||
const TELEMETRY_PING = "TELEMETRY_PING";
|
||||
const TELEMETRY_SUCCESS = "TELEMETRY_SUCCESS";
|
||||
|
@ -256,7 +256,7 @@ function test_loadSave()
|
||||
};
|
||||
let saveCallback = function(success) {
|
||||
do_check_true(success);
|
||||
Telemetry.loadHistograms(tmpFile, loadCallback);
|
||||
Telemetry.loadHistograms(tmpFile, loadCallback, false);
|
||||
saveFinished = true;
|
||||
};
|
||||
do_test_pending();
|
||||
|
Loading…
Reference in New Issue
Block a user