From daf330505849a8c9a4bce6ed4236fb48e450a8d9 Mon Sep 17 00:00:00 2001 From: Georg Fritzsche Date: Mon, 24 Mar 2014 09:58:57 +0100 Subject: [PATCH] Bug 985670 - Telemetry experiments: Don't schedule incorrect timer when there is no pending experiment. r=felipe --- browser/experiments/Experiments.jsm | 18 ++++-- browser/experiments/test/xpcshell/test_api.js | 56 +++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/browser/experiments/Experiments.jsm b/browser/experiments/Experiments.jsm index 5af89c345478..f5360fb87c3d 100644 --- a/browser/experiments/Experiments.jsm +++ b/browser/experiments/Experiments.jsm @@ -888,22 +888,32 @@ Experiments.Experiments.prototype = { */ _scheduleExperimentEvaluation: function () { this._checkForShutdown(); + + if (this._timer) { + this._timer.clear(); + } + if (!gExperimentsEnabled || this._experiments.length == 0) { return; } - let time = new Date(90000, 0, 1, 12).getTime(); + let time = null; let now = this._policy.now().getTime(); for (let [id, experiment] of this._experiments) { let scheduleTime = experiment.getScheduleTime(); if (scheduleTime > now) { - time = Math.min(time, scheduleTime); + if (time !== null) { + time = Math.min(time, scheduleTime); + } else { + time = scheduleTime; + } } } - if (this._timer) { - this._timer.clear(); + if (time === null) { + // No schedule time found. + return; } gLogger.trace("Experiments::scheduleExperimentEvaluation() - scheduling for "+time+", now: "+now); diff --git a/browser/experiments/test/xpcshell/test_api.js b/browser/experiments/test/xpcshell/test_api.js index 3b34f9f7d7bf..ed01ec9e222c 100644 --- a/browser/experiments/test/xpcshell/test_api.js +++ b/browser/experiments/test/xpcshell/test_api.js @@ -1144,6 +1144,62 @@ add_task(function* test_removeActiveExperiment() { yield removeCacheFile(); }); +// Test that we correctly handle experiment start & install failures. + +add_task(function* test_invalidUrl() { + const OBSERVER_TOPIC = "experiments-changed"; + let observerFireCount = 0; + let expectedObserverFireCount = 0; + let observer = () => ++observerFireCount; + Services.obs.addObserver(observer, OBSERVER_TOPIC, false); + + // Dates the following tests are based on. + + let baseDate = new Date(2014, 5, 1, 12); + let startDate = futureDate(baseDate, 100 * MS_IN_ONE_DAY); + let endDate = futureDate(baseDate, 10000 * MS_IN_ONE_DAY); + + // The manifest data we test with. + + gManifestObject = { + "version": 1, + experiments: [ + { + id: EXPERIMENT1_ID, + xpiURL: gDataRoot + EXPERIMENT1_XPI_NAME + ".invalid", + xpiHash: EXPERIMENT1_XPI_SHA1, + startTime: 0, + endTime: dateToSeconds(endDate), + maxActiveSeconds: 10 * SEC_IN_ONE_DAY, + appName: ["XPCShell"], + channel: ["nightly"], + }, + ], + }; + + let experiments = new Experiments.Experiments(gPolicy); + + // Trigger update, clock set for the experiment to start. + + let now = futureDate(startDate, 10 * MS_IN_ONE_DAY); + defineNow(gPolicy, now); + gTimerScheduleOffset = null; + + yield experiments.updateManifest(); + Assert.equal(observerFireCount, expectedObserverFireCount, + "Experiments observer should not have been called."); + Assert.equal(gTimerScheduleOffset, null, "No new timer should have been scheduled."); + + let list = yield experiments.getExperiments(); + Assert.equal(list.length, 0, "Experiment list should be empty."); + + // Cleanup. + + Services.obs.removeObserver(observer, OBSERVER_TOPIC); + yield experiments.uninit(); + yield removeCacheFile(); +}); + add_task(function* shutdown() { yield gReporter._shutdown(); yield removeCacheFile();