зеркало из https://github.com/mozilla/pjs.git
Bug 604697: Shared GUID between survey and study won't work if survey submitted before study starts. r+a=dtownsend DONTBUILD
This commit is contained in:
Родитель
4be3a50604
Коммит
228091c525
|
@ -249,6 +249,23 @@ var TestPilotTask = {
|
|||
}
|
||||
|
||||
this.onDetailPageOpened();
|
||||
},
|
||||
|
||||
getGuid: function TPS_getGuid(id) {
|
||||
// If there is a guid for the task with the given id (not neccessarily this one!)
|
||||
// then use it; if there isn't, generate it and store it.
|
||||
let guid = Application.prefs.getValue(GUID_PREF_PREFIX + id, "");
|
||||
if (guid == "") {
|
||||
let uuidGenerator =
|
||||
Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
||||
guid = uuidGenerator.generateUUID().toString();
|
||||
// remove the brackets from the generated UUID
|
||||
if (guid.indexOf("{") == 0) {
|
||||
guid = guid.substring(1, (guid.length - 1));
|
||||
}
|
||||
Application.prefs.setValue(GUID_PREF_PREFIX + id, guid);
|
||||
}
|
||||
return guid;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -635,14 +652,6 @@ TestPilotExperiment.prototype = {
|
|||
currentDate >= this._startDate &&
|
||||
currentDate <= this._endDate) {
|
||||
this._logger.info("Study now starting.");
|
||||
let uuidGenerator =
|
||||
Cc["@mozilla.org/uuid-generator;1"].getService(Ci.nsIUUIDGenerator);
|
||||
let uuid = uuidGenerator.generateUUID().toString();
|
||||
// remove the brackets from the generated UUID
|
||||
if (uuid.indexOf("{") == 0) {
|
||||
uuid = uuid.substring(1, (uuid.length - 1));
|
||||
}
|
||||
Application.prefs.setValue(GUID_PREF_PREFIX + this._id, uuid);
|
||||
// clear the data before starting.
|
||||
let self = this;
|
||||
this._dataStore.wipeAllData(function() {
|
||||
|
@ -742,8 +751,7 @@ TestPilotExperiment.prototype = {
|
|||
let self = this;
|
||||
MetadataCollector.getMetadata(function(md) {
|
||||
json.metadata = md;
|
||||
let guid = Application.prefs.getValue(GUID_PREF_PREFIX + self._id, "");
|
||||
json.metadata.task_guid = guid;
|
||||
json.metadata.task_guid = self.getGuid(self._id);
|
||||
json.metadata.event_headers = self._dataStore.getPropertyNames();
|
||||
self._dataStore.getJSONRows(function(rows) {
|
||||
json.events = rows;
|
||||
|
@ -962,13 +970,11 @@ TestPilotBuiltinSurvey.prototype = {
|
|||
let self = this;
|
||||
MetadataCollector.getMetadata(function(md) {
|
||||
json.metadata = md;
|
||||
// Include guid of the study that this survey is related to, so we
|
||||
// can match them up server-side.
|
||||
let guid = Application.prefs.getValue(GUID_PREF_PREFIX + self._studyId, "");
|
||||
/* TODO if the guid for that study ID hasn't been set yet, set it! And
|
||||
* then use it on the study. That way it won't matter whether the
|
||||
* study or the survey gets run first.*/
|
||||
json.metadata.task_guid = guid;
|
||||
if (self._studyId) {
|
||||
// Include guid of the study that this survey is related to, so we
|
||||
// can match them up server-side.
|
||||
json.metadata.task_guid = self.getGuid(self._studyId);
|
||||
}
|
||||
let pref = SURVEY_ANSWER_PREFIX + self._id;
|
||||
let surveyAnswers = JSON.parse(Application.prefs.getValue(pref, "{}"));
|
||||
json.survey_data = sanitizeJSONStrings(surveyAnswers);
|
||||
|
|
|
@ -403,6 +403,21 @@ StubHandlers.prototype = {
|
|||
}
|
||||
};
|
||||
|
||||
function clearAllPrefsForStudy(studyId) {
|
||||
dump("Looking for prefs to delete...\n");
|
||||
let prefService = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService)
|
||||
.QueryInterface(Ci.nsIPrefBranch2);
|
||||
let prefStem = "extensions.testpilot";
|
||||
let prefNames = prefService.getChildList(prefStem);
|
||||
for each (let prefName in prefNames) {
|
||||
if (prefName.indexOf(studyId) != -1) {
|
||||
dump("Clearing pref " + prefName + "\n");
|
||||
prefService.clearUserPref(prefName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function testRecurringStudyStateChange() {
|
||||
|
||||
|
@ -422,18 +437,7 @@ function testRecurringStudyStateChange() {
|
|||
versionNumber: 1
|
||||
};
|
||||
|
||||
dump("Looking for prefs to delete...\n");
|
||||
let prefService = Cc["@mozilla.org/preferences-service;1"]
|
||||
.getService(Ci.nsIPrefService)
|
||||
.QueryInterface(Ci.nsIPrefBranch2);
|
||||
let prefStem = "extensions.testpilot";
|
||||
let prefNames = prefService.getChildList(prefStem);
|
||||
for each (let prefName in prefNames) {
|
||||
if (prefName.indexOf("unit_test_recur_study") != -1) {
|
||||
dump("Clearing pref " + prefName + "\n");
|
||||
prefService.clearUserPref(prefName);
|
||||
}
|
||||
}
|
||||
clearAllPrefsForStudy("unit_test_recur_study");
|
||||
|
||||
const START_DATE = 1292629441000;
|
||||
let stubDate = START_DATE;
|
||||
|
@ -559,7 +563,8 @@ function runAllTests() {
|
|||
//testRemoteLoader();
|
||||
//testRemoteLoaderIndexCache();
|
||||
//testRecurringStudyStateChange();
|
||||
testKillSwitch();
|
||||
//testKillSwitch();
|
||||
testSameGUIDs();
|
||||
dump("TESTING COMPLETE. " + testsPassed + " out of " + testsRun +
|
||||
" tests passed.");
|
||||
}
|
||||
|
@ -691,4 +696,91 @@ function testKillSwitch() {
|
|||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// To test: The random subsample deployment... deployment when fx version or test pilot version
|
||||
// is or is not sufficient for study... deployment with arbitrary runOrNot func returning true
|
||||
// or false.
|
||||
|
||||
function testSameGUIDs() {
|
||||
|
||||
// make a study and survey that knows the study as 'related study'.
|
||||
|
||||
// start and submit study first, start and submit survey second: ensure that both have same
|
||||
// submission GUID.
|
||||
Cu.import("resource://testpilot/modules/tasks.js");
|
||||
|
||||
let expInfo = {
|
||||
startDate: null,
|
||||
duration: 7,
|
||||
testName: "Study w Survey n Guid",
|
||||
testId: "unit_test_guid_study",
|
||||
testInfoUrl: "https://testpilot.mozillalabs.com/",
|
||||
summary: "Be sure to wipe all prefs and the store in the setup/teardown",
|
||||
thumbnail: "",
|
||||
optInRequired: false,
|
||||
recursAutomatically: false,
|
||||
recurrenceInterval: 0,
|
||||
versionNumber: 1
|
||||
};
|
||||
|
||||
let surveyInfo = { surveyId: "unit_test_guid_survey",
|
||||
surveyName: "Survey with associated study",
|
||||
surveyUrl: "",
|
||||
summary: "",
|
||||
thumbnail: "",
|
||||
uploadWithExperiment: expInfo.testId,
|
||||
versionNumber: 1,
|
||||
surveyQuestions: {},
|
||||
surveyExplanation: ""
|
||||
};
|
||||
|
||||
clearAllPrefsForStudy("unit_test_guid_study");
|
||||
clearAllPrefsForStudy("unit_test_guid_survey");
|
||||
|
||||
let dataStore = new StubDataStore();
|
||||
let handlers = new StubHandlers();
|
||||
let webContent = new StubWebContent();
|
||||
let experiment = new TestPilotExperiment(expInfo, dataStore, handlers, webContent);
|
||||
let survey = new TestPilotBuiltinSurvey(surveyInfo);
|
||||
|
||||
// Start the study so it will generate a GUID
|
||||
experiment.changeStatus(TaskConstants.STATUS_STARTING, true);
|
||||
experiment.checkDate();
|
||||
|
||||
// Get GUIDs from study and from survey, compare:
|
||||
experiment._prependMetadataToJSON(function(jsonString) {
|
||||
let expGuid = JSON.parse(jsonString).metadata.task_guid;
|
||||
survey._prependMetadataToJSON(function(jsonString) {
|
||||
let surveyGuid = JSON.parse(jsonString).metadata.task_guid;
|
||||
dump("expGuid is " + expGuid + ", surveyGuid is " + surveyGuid + "\n");
|
||||
cheapAssertEqual(expGuid, surveyGuid, "guids should match");
|
||||
cheapAssertEqual((expGuid != ""), true, "guid should be non-empty");
|
||||
|
||||
// Clear everything for next part of test:
|
||||
clearAllPrefsForStudy("unit_test_guid_study");
|
||||
clearAllPrefsForStudy("unit_test_guid_survey");
|
||||
|
||||
let experiment2 = new TestPilotExperiment(expInfo, dataStore, handlers, webContent);
|
||||
let survey2 = new TestPilotBuiltinSurvey(surveyInfo);
|
||||
|
||||
// this time we query the survey for the GUID first, without starting the study:
|
||||
survey2._prependMetadataToJSON(function(jsonString) {
|
||||
let survey2Guid = JSON.parse(jsonString).metadata.task_guid;
|
||||
// after that, start the study:
|
||||
experiment2.changeStatus(TaskConstants.STATUS_STARTING, true);
|
||||
experiment2.checkDate();
|
||||
// experiment and survey should have same GUID again:
|
||||
experiment2._prependMetadataToJSON(function(jsonString) {
|
||||
let exp2Guid = JSON.parse(jsonString).metadata.task_guid;
|
||||
dump("exp2Guid is " + exp2Guid + ", survey2Guid is " + survey2Guid + "\n");
|
||||
cheapAssertEqual(exp2Guid, survey2Guid, "guids should match");
|
||||
cheapAssertEqual((exp2Guid != ""), true, "guid should be non-empty");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// TODO test for continuity of GUID with recurring study (longitudinal) - i don't think this
|
||||
// has actually been working so far because a new GUID is generted every time the study starts up...
|
Загрузка…
Ссылка в новой задаче