Reviewers: felix8a,

Description:
assertAsynchronousRequirement will now always wait (number of tests * 2)
iterations of the event loop before giving up.

This fixes meta-test.js testCaseAsyncPass being flaky due to its iframed
test page's turns getting interleaved between other pages' loading.

Please review this at https://codereview.appspot.com/9233043/

Affected files:
  M     tests/com/google/caja/plugin/browser-test-case.js


Index: tests/com/google/caja/plugin/browser-test-case.js
===================================================================
--- tests/com/google/caja/plugin/browser-test-case.js   (revision 5400)
+++ tests/com/google/caja/plugin/browser-test-case.js   (working copy)
@@ -336,8 +336,9 @@
    * Start checking the asynchronous requirements.
    * @param {function (boolean) : void} handler called with the value
    *     {@code true} when and if all requirements are satisfied.
-   *     Called with false if more than TIMEOUT_MILLIS time passes
-   *     and requirements still aren't satisfied.
+   *     Called with false if more than TIMEOUT_MILLIS time and (number
+   *     of registered tests * 2) turns pass and requirements still
+   *     aren't satisfied.
    */
   var evaluate = function (handler) {
     if (!handler) {
@@ -347,8 +348,12 @@
     if (req.length === 0) {
       handler(true);
     } else {
-      var timeoutTime = (new Date).getTime() + TIMEOUT_MILLIS;
+      var asyncStartTime = (new Date).getTime();
+      var timeoutTime = asyncStartTime + TIMEOUT_MILLIS;
+      var timeoutTurns = jsunit.testCount * 2;
+      var turn = 0;
       intervalId = setInterval(function () {
+        turn++;
         for (var i = req.length; --i >= 0;) {
           var record = req[i];
           try {
@@ -371,18 +376,22 @@
             --req.length;
           }
         }
-        if (req.length === 0 || (new Date).getTime() >= timeoutTime) {
+        var now = (new Date).getTime();
+ if (req.length === 0 || now >= timeoutTime && turn > timeoutTurns) {
           clearInterval(intervalId);
           intervalId = null;

+ var timeoutDesc = 'async test timeout after ' + (now - asyncStartTime) + + '/' + (timeoutTime - asyncStartTime) + ' ms and ' + turn + '/' +
+              timeoutTurns + ' turns: ';
+
           var failures = req.length !== 0;
           if (failures) {
             for (var i = req.length; --i >= 0;) {
               var record = req[i];
               (function(record) {
                 setTimeout(jsunitCallback(function() {
-                  throw new Error('async test timeout: ' +
-                      record.message);
+                  throw new Error(timeoutDesc + record.message);
                 }, record.id), 0);
               })(record);
             }


--

--- You received this message because you are subscribed to the Google Groups "Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to