Skip to content

Commit

Permalink
Bug 1400467 - Ensure services/common/logmanager.js awaits it's cleanu…
Browse files Browse the repository at this point in the history
…p function r=markh

MozReview-Commit-ID: thQph1UUA0
  • Loading branch information
Thom Chiovoloni committed Sep 22, 2017
1 parent f515f5d commit 3280466
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 36 deletions.
19 changes: 12 additions & 7 deletions services/common/logmanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,18 @@ LogManager.prototype = {
// logs are grouped in about:sync-log.
let filename = reasonPrefix + "-" + this.logFilePrefix + "-" + Date.now() + ".txt";
await this._fileAppender.flushToFile(this._logFileSubDirectoryEntries, filename, this._log);

// It's not completely clear to markh why we only do log cleanups
// for errors, but for now the Sync semantics have been copied...
// (one theory is that only cleaning up on error makes it less
// likely old error logs would be removed, but that's not true if
// there are occasional errors - let's address this later!)
if (reason == this.ERROR_LOG_WRITTEN && !this._cleaningUpFileLogs) {
this._log.trace("Scheduling cleanup.");
// Note we don't return/await or otherwise wait on this promise - it
// continues in the background
this.cleanupLogs().catch(err => {
this._log.trace("Running cleanup.");
try {
await this.cleanupLogs();
} catch (err) {
this._log.error("Failed to cleanup logs", err);
});
}
}
return reason;
} catch (ex) {
Expand Down Expand Up @@ -321,7 +320,13 @@ LogManager.prototype = {
+ entry.name, ex);
}
});
iterator.close();
// Wait for this to close if we need to (but it might fail if OS.File has
// shut down)
try {
await iterator.close();
} catch (e) {
this._log.warn("Failed to close directory iterator", e);
}
this._cleaningUpFileLogs = false;
this._log.debug("Done deleting files.");
// This notification is used only for tests.
Expand Down
33 changes: 4 additions & 29 deletions services/sync/tests/unit/test_errorhandler_filelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,13 +162,6 @@ add_test(function test_sync_error_logOnError_true() {
const MESSAGE = "this WILL show up";
log.info(MESSAGE);

// We need to wait until the log cleanup started by this test is complete
// or the next test will fail as it is ongoing.
Svc.Obs.add("services-tests:common:log-manager:cleanup-logs", function onCleanupLogs() {
Svc.Obs.remove("services-tests:common:log-manager:cleanup-logs", onCleanupLogs);
run_next_test();
});

Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);

Expand All @@ -194,6 +187,7 @@ add_test(function test_sync_error_logOnError_true() {
}

Svc.Prefs.resetBranch("");
run_next_test();
});
});

Expand Down Expand Up @@ -229,13 +223,6 @@ add_test(function test_login_error_logOnError_true() {
const MESSAGE = "this WILL show up";
log.info(MESSAGE);

// We need to wait until the log cleanup started by this test is complete
// or the next test will fail as it is ongoing.
Svc.Obs.add("services-tests:common:log-manager:cleanup-logs", function onCleanupLogs() {
Svc.Obs.remove("services-tests:common:log-manager:cleanup-logs", onCleanupLogs);
run_next_test();
});

Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);

Expand All @@ -261,6 +248,7 @@ add_test(function test_login_error_logOnError_true() {
}

Svc.Prefs.resetBranch("");
run_next_test();
});
});

Expand Down Expand Up @@ -301,13 +289,6 @@ add_test(function test_newFailed_errorLog() {
const MESSAGE = "this WILL show up 2";
log.info(MESSAGE);

// We need to wait until the log cleanup started by this test is complete
// or the next test will fail as it is ongoing.
Svc.Obs.add("services-tests:common:log-manager:cleanup-logs", function onCleanupLogs() {
Svc.Obs.remove("services-tests:common:log-manager:cleanup-logs", onCleanupLogs);
run_next_test();
});

Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);

Expand All @@ -333,7 +314,7 @@ add_test(function test_newFailed_errorLog() {
}

Svc.Prefs.resetBranch("");

run_next_test();
});
});
// newFailed is nonzero -- should write a log.
Expand All @@ -352,13 +333,6 @@ add_test(function test_newFailed_errorLog() {
add_test(function test_errorLog_dumpAddons() {
Svc.Prefs.set("log.appender.file.logOnError", true);

// We need to wait until the log cleanup started by this test is complete
// or the next test will fail as it is ongoing.
Svc.Obs.add("services-tests:common:log-manager:cleanup-logs", function onCleanupLogs() {
Svc.Obs.remove("services-tests:common:log-manager:cleanup-logs", onCleanupLogs);
run_next_test();
});

Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);

Expand All @@ -383,6 +357,7 @@ add_test(function test_errorLog_dumpAddons() {
}

Svc.Prefs.resetBranch("");
run_next_test();
});
});

Expand Down

0 comments on commit 3280466

Please sign in to comment.