mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1054397 - automated test for the racy while setting experiment branches, followup to bug 1052545 and bug 1038174
, r=gfritzsche
--HG-- extra : rebase_source : 80df2293e21f7f7a0d13856cd7d609d5e26b83e0
This commit is contained in:
parent
7721d15401
commit
3004de192b
@ -324,6 +324,14 @@ Experiments.Policy.prototype = {
|
|||||||
telemetryPayload: function () {
|
telemetryPayload: function () {
|
||||||
return TelemetryPing.getPayload();
|
return TelemetryPing.getPayload();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For testing a race condition, one of the tests delays the callback of
|
||||||
|
* writing the cache by replacing this policy function.
|
||||||
|
*/
|
||||||
|
delayCacheWrite: function(promise) {
|
||||||
|
return promise;
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
function AlreadyShutdownError(message="already shut down") {
|
function AlreadyShutdownError(message="already shut down") {
|
||||||
@ -1001,7 +1009,7 @@ Experiments.Experiments.prototype = {
|
|||||||
let encoder = new TextEncoder();
|
let encoder = new TextEncoder();
|
||||||
let data = encoder.encode(textData);
|
let data = encoder.encode(textData);
|
||||||
let options = { tmpPath: path + ".tmp", compression: "lz4" };
|
let options = { tmpPath: path + ".tmp", compression: "lz4" };
|
||||||
yield OS.File.writeAtomic(path, data, options);
|
yield this._policy.delayCacheWrite(OS.File.writeAtomic(path, data, options));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// We failed to write the cache, it's still dirty.
|
// We failed to write the cache, it's still dirty.
|
||||||
this._dirty = true;
|
this._dirty = true;
|
||||||
|
33
browser/experiments/test/addons/experiment-racybranch/bootstrap.js
vendored
Normal file
33
browser/experiments/test/addons/experiment-racybranch/bootstrap.js
vendored
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
let {classes: Cc, interfaces: Ci, utils: Cu} = Components;
|
||||||
|
|
||||||
|
Cu.import("resource:///modules/experiments/Experiments.jsm");
|
||||||
|
|
||||||
|
let gStarted = false;
|
||||||
|
|
||||||
|
function startup(data, reasonCode) {
|
||||||
|
if (gStarted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
gStarted = true;
|
||||||
|
|
||||||
|
// delay realstartup to trigger the race condition
|
||||||
|
Cc['@mozilla.org/thread-manager;1'].getService(Ci.nsIThreadManager)
|
||||||
|
.mainThread.dispatch(realstartup, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
function realstartup() {
|
||||||
|
let experiments = Experiments.instance();
|
||||||
|
let experiment = experiments._getActiveExperiment();
|
||||||
|
if (experiment.branch) {
|
||||||
|
Cu.reportError("Found pre-existing branch: " + experiment.branch);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let branch = "racy-set";
|
||||||
|
experiments.setExperimentBranch(experiment.id, branch)
|
||||||
|
.then(null, Cu.reportError);
|
||||||
|
}
|
||||||
|
|
||||||
|
function shutdown() { }
|
||||||
|
function install() { }
|
||||||
|
function uninstall() { }
|
@ -0,0 +1,16 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
|
||||||
|
<RDF xmlns="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:em="http://www.mozilla.org/2004/em-rdf#">
|
||||||
|
|
||||||
|
<Description about="urn:mozilla:install-manifest">
|
||||||
|
<em:id>test-experiment-racybranch@tests.mozilla.org</em:id>
|
||||||
|
<em:version>1</em:version>
|
||||||
|
<em:type>128</em:type>
|
||||||
|
|
||||||
|
<!-- Front End MetaData -->
|
||||||
|
<em:name>Test experiment racybranch</em:name>
|
||||||
|
<em:description>An experiment that sets the experiment branch in a potentially racy way.</em:description>
|
||||||
|
|
||||||
|
</Description>
|
||||||
|
</RDF>
|
@ -7,7 +7,6 @@ Cu.import("resource://testing-common/httpd.js");
|
|||||||
XPCOMUtils.defineLazyModuleGetter(this, "Experiments",
|
XPCOMUtils.defineLazyModuleGetter(this, "Experiments",
|
||||||
"resource:///modules/experiments/Experiments.jsm");
|
"resource:///modules/experiments/Experiments.jsm");
|
||||||
|
|
||||||
const FILE_MANIFEST = "experiments.manifest";
|
|
||||||
const MANIFEST_HANDLER = "manifests/handler";
|
const MANIFEST_HANDLER = "manifests/handler";
|
||||||
|
|
||||||
const SEC_IN_ONE_DAY = 24 * 60 * 60;
|
const SEC_IN_ONE_DAY = 24 * 60 * 60;
|
||||||
|
111
browser/experiments/test/xpcshell/test_cacherace.js
Normal file
111
browser/experiments/test/xpcshell/test_cacherace.js
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
/* Any copyright is dedicated to the Public Domain.
|
||||||
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
Cu.import("resource://testing-common/httpd.js");
|
||||||
|
Cu.import("resource://gre/modules/Timer.jsm");
|
||||||
|
|
||||||
|
const MANIFEST_HANDLER = "manifests/handler";
|
||||||
|
|
||||||
|
const SEC_IN_ONE_DAY = 24 * 60 * 60;
|
||||||
|
const MS_IN_ONE_DAY = SEC_IN_ONE_DAY * 1000;
|
||||||
|
|
||||||
|
let gProfileDir = null;
|
||||||
|
let gHttpServer = null;
|
||||||
|
let gHttpRoot = null;
|
||||||
|
let gDataRoot = null;
|
||||||
|
let gReporter = null;
|
||||||
|
let gPolicy = null;
|
||||||
|
let gManifestObject = null;
|
||||||
|
let gManifestHandlerURI = null;
|
||||||
|
|
||||||
|
function run_test() {
|
||||||
|
run_next_test();
|
||||||
|
}
|
||||||
|
|
||||||
|
add_task(function* test_setup() {
|
||||||
|
loadAddonManager();
|
||||||
|
gProfileDir = do_get_profile();
|
||||||
|
yield removeCacheFile();
|
||||||
|
|
||||||
|
gHttpServer = new HttpServer();
|
||||||
|
gHttpServer.start(-1);
|
||||||
|
let port = gHttpServer.identity.primaryPort;
|
||||||
|
gHttpRoot = "http://localhost:" + port + "/";
|
||||||
|
gDataRoot = gHttpRoot + "data/";
|
||||||
|
gManifestHandlerURI = gHttpRoot + MANIFEST_HANDLER;
|
||||||
|
gHttpServer.registerDirectory("/data/", do_get_cwd());
|
||||||
|
gHttpServer.registerPathHandler("/" + MANIFEST_HANDLER, (request, response) => {
|
||||||
|
response.setStatusLine(null, 200, "OK");
|
||||||
|
response.write(JSON.stringify(gManifestObject));
|
||||||
|
response.processAsync();
|
||||||
|
response.finish();
|
||||||
|
});
|
||||||
|
do_register_cleanup(() => gHttpServer.stop(() => {}));
|
||||||
|
|
||||||
|
Services.prefs.setBoolPref(PREF_EXPERIMENTS_ENABLED, true);
|
||||||
|
Services.prefs.setIntPref(PREF_LOGGING_LEVEL, 0);
|
||||||
|
Services.prefs.setBoolPref(PREF_LOGGING_DUMP, true);
|
||||||
|
Services.prefs.setCharPref(PREF_MANIFEST_URI, gManifestHandlerURI);
|
||||||
|
Services.prefs.setIntPref(PREF_FETCHINTERVAL, 0);
|
||||||
|
|
||||||
|
gReporter = yield getReporter("json_payload_simple");
|
||||||
|
yield gReporter.collectMeasurements();
|
||||||
|
let payload = yield gReporter.getJSONPayload(true);
|
||||||
|
do_register_cleanup(() => gReporter._shutdown());
|
||||||
|
|
||||||
|
let ExperimentsScope = Cu.import("resource:///modules/experiments/Experiments.jsm");
|
||||||
|
let Experiments = ExperimentsScope.Experiments;
|
||||||
|
|
||||||
|
gPolicy = new Experiments.Policy();
|
||||||
|
patchPolicy(gPolicy, {
|
||||||
|
updatechannel: () => "nightly",
|
||||||
|
healthReportPayload: () => "{}",
|
||||||
|
delayCacheWrite: (promise) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
promise.then(
|
||||||
|
(result) => { setTimeout(() => resolve(result), 500); },
|
||||||
|
(err) => { reject(err); }
|
||||||
|
);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
let now = new Date(2014, 5, 1, 12);
|
||||||
|
defineNow(gPolicy, now);
|
||||||
|
|
||||||
|
let experimentName = "experiment-racybranch.xpi";
|
||||||
|
let experimentPath = getExperimentPath(experimentName);
|
||||||
|
let experimentHash = "sha1:" + sha1File(experimentPath);
|
||||||
|
|
||||||
|
gManifestObject = {
|
||||||
|
version: 1,
|
||||||
|
experiments: [
|
||||||
|
{
|
||||||
|
id: "test-experiment-racybranch@tests.mozilla.org",
|
||||||
|
xpiURL: gDataRoot + "experiment-racybranch.xpi",
|
||||||
|
xpiHash: experimentHash,
|
||||||
|
maxActiveSeconds: 10 * SEC_IN_ONE_DAY,
|
||||||
|
appName: ["XPCShell"],
|
||||||
|
channel: ["nightly"],
|
||||||
|
startTime: dateToSeconds(futureDate(now, -MS_IN_ONE_DAY)),
|
||||||
|
endTime: dateToSeconds(futureDate(now, MS_IN_ONE_DAY)),
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
do_print("gManifestObject: " + JSON.stringify(gManifestObject));
|
||||||
|
|
||||||
|
// In order for the addon manager to work properly, we hack
|
||||||
|
// Experiments.instance which is used by the XPIProvider
|
||||||
|
let experiments = new Experiments.Experiments(gPolicy);
|
||||||
|
Assert.strictEqual(ExperimentsScope.gExperiments, null);
|
||||||
|
ExperimentsScope.gExperiments = experiments;
|
||||||
|
|
||||||
|
yield experiments.updateManifest();
|
||||||
|
let active = experiments._getActiveExperiment();
|
||||||
|
Assert.ok(active);
|
||||||
|
Assert.equal(active.branch, "racy-set");
|
||||||
|
Assert.ok(!experiments._dirty);
|
||||||
|
});
|
@ -7,14 +7,17 @@ support-files =
|
|||||||
experiment-1.xpi
|
experiment-1.xpi
|
||||||
experiment-1a.xpi
|
experiment-1a.xpi
|
||||||
experiment-2.xpi
|
experiment-2.xpi
|
||||||
|
experiment-racybranch.xpi
|
||||||
generated-files =
|
generated-files =
|
||||||
experiment-1.xpi
|
experiment-1.xpi
|
||||||
experiment-1a.xpi
|
experiment-1a.xpi
|
||||||
experiment-2.xpi
|
experiment-2.xpi
|
||||||
|
experiment-racybranch.xpi
|
||||||
|
|
||||||
[test_activate.js]
|
[test_activate.js]
|
||||||
[test_api.js]
|
[test_api.js]
|
||||||
[test_cache.js]
|
[test_cache.js]
|
||||||
|
[test_cacherace.js]
|
||||||
[test_conditions.js]
|
[test_conditions.js]
|
||||||
[test_disableExperiments.js]
|
[test_disableExperiments.js]
|
||||||
[test_fetch.js]
|
[test_fetch.js]
|
||||||
|
Loading…
Reference in New Issue
Block a user