Revision: 5401
Author: [email protected]
Date: Mon May 6 11:45:14 2013
Log: Give assertAsynchronousRequirement a minimum turn count.
https://codereview.appspot.com/9233043
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.
[email protected]
http://code.google.com/p/google-caja/source/detail?r=5401
Modified:
/trunk/tests/com/google/caja/plugin/browser-test-case.js
=======================================
--- /trunk/tests/com/google/caja/plugin/browser-test-case.js Wed May 1
10:22:42 2013
+++ /trunk/tests/com/google/caja/plugin/browser-test-case.js Mon May 6
11:45:14 2013
@@ -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.