Bug 937181 - coalesce log messages from SimpleTest; r=jmaher
authorNathan Froyd <froydnj@mozilla.com>
Fri, 31 Jan 2014 17:08:33 -0500
changeset 166813 c8abc650f217bf737ba0c4e0cf60b028d0f420e2
parent 166812 73caaea5844f87837d7cb9adcbc152e1b7857fd9
child 166814 06e99d1896ce003326d24eebd7854104748d8f3a
push id26152
push usercbook@mozilla.com
push dateWed, 05 Feb 2014 12:20:14 +0000
treeherdermozilla-central@8f7033c595b9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjmaher
bugs937181
milestone30.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 937181 - coalesce log messages from SimpleTest; r=jmaher
testing/mochitest/tests/SimpleTest/SimpleTest.js
--- a/testing/mochitest/tests/SimpleTest/SimpleTest.js
+++ b/testing/mochitest/tests/SimpleTest/SimpleTest.js
@@ -1,8 +1,10 @@
+/* -*- js-indent-level: 4; tab-width: 4; indent-tabs-mode: nil -*- */
+/* vim:set ts=4 sw=4 sts=4 et: */
 /**
  * SimpleTest, a partial Test.Simple/Test.More API compatible test library.
  *
  * Why?
  *
  * Test.Simple doesn't work on IE < 6.
  * TODO:
  *  * Support the Test.Simple API used by MochiKit, to be able to test MochiKit
@@ -305,35 +307,62 @@ SimpleTest.getTestFileURL = function(pat
 };
 
 SimpleTest._getCurrentTestURL = function() {
     return parentRunner && parentRunner.currentTestURL ||
            typeof gTestPath == "string" && gTestPath ||
            "unknown test url";
 };
 
-SimpleTest._logResult = function(test, passString, failString) {
-    var isError = !test.result == !test.todo;
-    var resultString = test.result ? passString : failString;
-    var url = SimpleTest._getCurrentTestURL();
-    var diagnostic = test.name + (test.diag ? " - " + test.diag : "");
-    var msg = [resultString, url, diagnostic].join(" | ");
-    if (parentRunner) {
-        if (isError) {
-            parentRunner.addFailedTest(url);
-            parentRunner.error(msg);
+SimpleTest._logResult = (function () {
+    var numCoalescedMessages = 1;
+    var coalesceThreshold = 100;
+
+    function logResult(test, passString, failString) {
+        var isError = !test.result == !test.todo;
+        var outputCoalescedMessage = numCoalescedMessages == coalesceThreshold;
+
+        // We want to eliminate mundane TEST-PASS/TEST-KNOWN-FAIL output,
+        // since some tests produce tens of thousands of
+        // TEST-PASS/TEST-KNOWN-FAIL messages.  But we always want to log
+        // errors and informative messages.  We also want to output messages
+        // every so often to let the user know the test is still running.
+        var shouldLog = (isError ||
+                         passString == "TEST-INFO" ||
+                         outputCoalescedMessage);
+
+        if (!shouldLog) {
+            ++numCoalescedMessages;
+            return;
+        }
+
+        var resultString = test.result ? passString : failString;
+        var url = SimpleTest._getCurrentTestURL();
+        var diagnostic = test.name + (test.diag ? " - " + test.diag : "");
+        if (outputCoalescedMessage) {
+            diagnostic += " (elided " + numCoalescedMessages + " passes or known failures)";
+            numCoalescedMessages = 1;
+        }
+        var msg = [resultString, url, diagnostic].join(" | ");
+        if (parentRunner) {
+            if (isError) {
+                parentRunner.addFailedTest(url);
+                parentRunner.error(msg);
+            } else {
+                parentRunner.log(msg);
+            }
+        } else if (typeof dump === "function") {
+            dump(msg + "\n");
         } else {
-            parentRunner.log(msg);
+            // Non-Mozilla browser?  Just do nothing.
         }
-    } else if (typeof dump === "function") {
-        dump(msg + "\n");
-    } else {
-        // Non-Mozilla browser?  Just do nothing.
     }
-};
+
+    return logResult;
+})();
 
 SimpleTest.info = function(name, message) {
     SimpleTest._logResult({result:true, name:name, diag:message}, "TEST-INFO");
 };
 
 /**
  * Copies of is and isnot with the call to ok replaced by a call to todo.
 **/