# HG changeset patch # User Jorg K # Date 1524249086 -7200 # Node ID bb98b2c207be926079d98ca85e374479e45541fa # Parent 187eb9c49e34783f6af36096599dcf9134ffb88c Bug 1455536 - Port bug 1453881: add_task() doesn't accept generators any more (chat part, take 2). r=florian diff --git a/chat/components/src/test/test_logger.js b/chat/components/src/test/test_logger.js --- a/chat/components/src/test/test_logger.js +++ b/chat/components/src/test/test_logger.js @@ -316,46 +316,46 @@ var test_logging = async function () { displayMessage: "Nothing much!", incoming: true } ]; } let firstDayMsgs = getMsgsForConv(dummyConv); let secondDayMsgs = getMsgsForConv(dummyConv2); - let logMessagesForConv = Task.async(async function (aConv, aMessages) { + let logMessagesForConv = async function (aConv, aMessages) { let logWriter = gLogger.getLogWriter(aConv); for (let message of aMessages) logWriter.logMessage(message); // If we don't wait for the messages to get written, we have no guarantee // later in the test that the log files were created, and getConversation // will return an EmptyEnumerator. Logging the messages is queued on the // _initialized promise, so we need to await on that first. await logWriter._initialized; await gLogger.gFilePromises.get(logWriter.currentPath); // Ensure two different files for the different dates. gLogger.closeLogWriter(aConv); - }); + }; await logMessagesForConv(dummyConv, firstDayMsgs); await logMessagesForConv(dummyConv2, secondDayMsgs); // Write a zero-length file and a file with incorrect JSON for each day // to ensure they are handled correctly. let logDir = OS.Path.dirname( gLogger.getLogFilePathForConversation(dummyConv, "json")); - let createBadFiles = Task.async(async function (aConv) { + let createBadFiles = async function (aConv) { let blankFile = OS.Path.join(logDir, gLogger.getNewLogFileName("json", (aConv.startDate + oneSec) / 1000)); let invalidJSONFile = OS.Path.join(logDir, gLogger.getNewLogFileName("json", (aConv.startDate + (2 * oneSec)) / 1000)); let file = await OS.File.open(blankFile, {truncate: true}); await file.close(); await OS.File.writeAtomic(invalidJSONFile, new TextEncoder().encode("This isn't JSON!")); - }); + }; await createBadFiles(dummyConv); await createBadFiles(dummyConv2); let testMsgs = function (aMsgs, aExpectedMsgs, aExpectedSessions) { // Ensure the number of session messages is correct. let sessions = aMsgs.filter(aMsg => aMsg.who == "sessionstart").length; equal(sessions, aExpectedSessions); @@ -404,22 +404,22 @@ var test_logging = async function () { let conv = await log.getConversation(); let date = reduceTimeToDate(log.time); // 3 session messages - for daily logs, bad files are included. testMsgs(conv.getMessages(), messagesByDay.get(date), 3); } // Remove the created log files, testing forEach in the process. await logger.forEach({ - processLog: Task.async(async function (aLog) { + async processLog(aLog) { let info = await OS.File.stat(aLog); ok(!info.isDir); ok(aLog.endsWith(".json")); await OS.File.remove(aLog); - }) + } }); let logFolder = OS.Path.dirname(gLogger.getLogFilePathForConversation(dummyConv)); // The folder should now be empty - this will throw if it isn't. await OS.File.removeEmptyDir(logFolder, {ignoreAbsent: false}); } var test_logFileSplitting = async function () { // Start clean, remove the log directory. @@ -430,35 +430,35 @@ var test_logFileSplitting = async functi let oldPath = logWriter.currentPath; let message = { time: startTime, who: "John Doe", originalMessage: "Hello, world!", outgoing: true }; - let logMessage = Task.async(async function (aMessage) { + let logMessage = async function (aMessage) { logWriter.logMessage(aMessage); await logWriter._initialized; await gLogger.gFilePromises.get(logWriter.currentPath); - }); + }; await logMessage(message); message.time += (logWriter.kInactivityLimit / 1000) + 1; // This should go in a new log file. await logMessage(message); notEqual(logWriter.currentPath, oldPath); // The log writer's new start time should be the time of the message. equal(message.time * 1000, logWriter._startTime); - let getCurrentHeader = Task.async(async function () { + let getCurrentHeader = async function () { return JSON.parse(new TextDecoder() .decode(await OS.File.read(logWriter.currentPath)) .split("\n")[0]); - }); + }; // The header of the new log file should not have the continuedSession flag set. ok(!(await getCurrentHeader()).continuedSession); // Set the start time sufficiently before midnight, and the last message time // to just before midnight. A new log file should be created at midnight. logWriter._startTime = new Date(logWriter._startTime) .setHours(24, 0, 0, -(logWriter.kDayOverlapLimit + 1));