Bug 1024672 - Part 2: Convert submission details stored in separate crash records to crash metadata. r=gps

This commit is contained in:
Birunthan Mohanathas 2014-08-21 15:43:46 -07:00
parent 6d02b6ce50
commit 1c081f8552
3 changed files with 136 additions and 0 deletions

View File

@ -408,6 +408,39 @@ this.CrashManager.prototype = Object.freeze({
return store.addCrash(process, submission_type, id, date);
},
/**
* Record the occurrence of a submission attempt for a crash.
*
* @param crashID (string) Crash ID. Likely a UUID.
* @param submissionID (string) Submission ID. Likely a UUID.
* @param date (Date) When the attempt occurred.
*
* @return boolean True if the attempt was recorded and false if not.
*/
addSubmissionAttempt: Task.async(function* (crashID, submissionID, date) {
let store = yield this._getStore();
if (store.addSubmissionAttempt(crashID, submissionID, date)) {
yield store.save();
}
}),
/**
* Record the occurrence of a submission result for a crash.
*
* @param crashID (string) Crash ID. Likely a UUID.
* @param submissionID (string) Submission ID. Likely a UUID.
* @param date (Date) When the submission result was obtained.
* @param result (string) One of the SUBMISSION_RESULT constants.
*
* @return boolean True if the result was recorded and false if not.
*/
addSubmissionResult: Task.async(function* (crashID, submissionID, date, result) {
let store = yield this._getStore();
if (store.addSubmissionResult(crashID, submissionID, date, result)) {
yield store.save();
}
}),
/**
* Obtain the paths of all unprocessed events files.
*
@ -697,7 +730,22 @@ CrashStore.prototype = Object.freeze({
// days stored in the payload matches up to actual data.
let actualCounts = new Map();
// In the past, submissions were stored as separate crash records
// with an id of e.g. "someID-submission". If we find IDs ending
// with "-submission", we will need to convert the data to be stored
// as actual submissions.
//
// TODO: The old way of storing submissions was used from FF33 - FF34.
// We should drop the conversion code after a few releases. See bug
// 1056157.
let hasSubmissionsStoredAsCrashes = false;
for (let id in data.crashes) {
if (id.endsWith("-submission")) {
hasSubmissionsStoredAsCrashes = true;
continue;
}
let crash = data.crashes[id];
let denormalized = this._denormalize(crash);
@ -716,6 +764,32 @@ CrashStore.prototype = Object.freeze({
actualCounts.set(key, (actualCounts.get(key) || 0) + 1);
}
if (hasSubmissionsStoredAsCrashes) {
for (let id in data.crashes) {
if (!id.endsWith("-submission")) {
continue;
}
// This type of record will contain e.g.:
// {
// "id": "crash1-submission",
// "type": "main-crash-submission-succeeded",
// "crashDate": "...",
// }
let submissionData = this._denormalize(data.crashes[id]);
let crashID = id.replace(/-submission$/, "");
let result = submissionData.type.endsWith("-succeeded") ?
CrashManager.prototype.SUBMISSION_RESULT_OK :
CrashManager.prototype.SUBMISSION_RESULT_FAILED;
this.addSubmissionAttempt(crashID, "converted",
submissionData.crashDate);
this.addSubmissionResult(crashID, "converted",
submissionData.crashDate, result);
}
}
// The validation in this loop is arguably not necessary. We perform
// it as a defense against unknown bugs.
for (let dayKey in data.countsByDay) {

View File

@ -367,3 +367,27 @@ add_task(function* test_addSubmission() {
});
add_task(function* test_addSubmissionAttemptAndResult() {
let m = yield getManager();
let crashes = yield m.getCrashes();
Assert.equal(crashes.length, 0);
yield m.addCrash(m.PROCESS_TYPE_MAIN, m.CRASH_TYPE_CRASH,
"main-crash", DUMMY_DATE);
yield m.addSubmissionAttempt("main-crash", "submission", DUMMY_DATE);
yield m.addSubmissionResult("main-crash", "submission", DUMMY_DATE_2,
m.SUBMISSION_RESULT_OK);
crashes = yield m.getCrashes();
Assert.equal(crashes.length, 1);
let submissions = crashes[0].submissions;
Assert.ok(!!submissions);
let submission = submissions.get("submission");
Assert.ok(!!submission);
Assert.equal(submission.requestDate.getTime(), DUMMY_DATE.getTime());
Assert.equal(submission.responseDate.getTime(), DUMMY_DATE_2.getTime());
Assert.equal(submission.result, m.SUBMISSION_RESULT_OK);
});

View File

@ -557,3 +557,41 @@ add_task(function* test_addSubmission() {
Assert.ok(!!submission);
Assert.equal(submission.result, SUBMISSION_RESULT_OK);
});
add_task(function* test_convertSubmissionsStoredAsCrashes() {
let s = yield getStore();
let addSubmissionAsCrash = (processType, crashType, succeeded, id, date) => {
id = id + "-submission";
let process = processType + "-" + crashType + "-submission";
let submissionType = succeeded ? "succeeded" : "failed";
return s.addCrash(process, submissionType, id, date);
};
Assert.ok(s.addCrash(PROCESS_TYPE_MAIN, CRASH_TYPE_CRASH, "crash1",
new Date()));
Assert.ok(addSubmissionAsCrash(PROCESS_TYPE_MAIN, CRASH_TYPE_CRASH, true,
"crash1", DUMMY_DATE));
Assert.ok(s.addCrash(PROCESS_TYPE_PLUGIN, CRASH_TYPE_HANG, "hang1",
new Date()));
Assert.ok(addSubmissionAsCrash(PROCESS_TYPE_PLUGIN, CRASH_TYPE_HANG, false,
"hang1", DUMMY_DATE_2));
Assert.equal(s.crashes.length, 4);
yield s.save();
yield s.load();
Assert.equal(s.crashes.length, 2);
let submission = s.getSubmission("crash1", "converted");
Assert.ok(!!submission);
Assert.equal(submission.result, SUBMISSION_RESULT_OK);
Assert.equal(submission.requestDate.getTime(), DUMMY_DATE.getTime());
Assert.equal(submission.responseDate.getTime(), DUMMY_DATE.getTime());
submission = s.getSubmission("hang1", "converted");
Assert.ok(!!submission);
Assert.equal(submission.result, SUBMISSION_RESULT_FAILED);
Assert.equal(submission.requestDate.getTime(), DUMMY_DATE_2.getTime());
Assert.equal(submission.responseDate.getTime(), DUMMY_DATE_2.getTime());
});