Permalink
Browse files

New feature: break stuck tests after a timeout (this allows to finish…

… a test-suits that contains never ending tests).
  • Loading branch information...
1 parent 0d47621 commit 7d8ded691ec1d91c7a6d8781d137697c06a59d26 @janodvarko janodvarko committed Jan 19, 2009
Showing with 40 additions and 7 deletions.
  1. +38 −7 chrome/content/fireunit/fireunit.js
  2. +1 −0 chrome/locale/en-US/fireunit.properties
  3. +1 −0 defaults/preferences/prefs.js
@@ -19,6 +19,8 @@ var server; // HTTP local server
var uuid = 1;
var serverPort = 7080;
var winID;
+var testTimeoutID = 0; // Timeout ID for breaking stuck tests.
+var testTimeout = 0; // Disabled by default. Must be set from within a test or user preferences.
// Services
var cache = Cc["@mozilla.org/network/cache-service;1"].getService(Ci.nsICacheService);
@@ -42,6 +44,9 @@ Firebug.FireUnitModule = extend(Firebug.Module,
// Add listener for log customization
Firebug.TraceModule.addListener(this);
+
+ // Get time for break timeout from preferences.
+ testTimeout = Firebug.getPref(Firebug.prefDomain, "fireunit.testTimeout");
},
shutdown: function()
@@ -66,16 +71,37 @@ Firebug.FireUnitModule = extend(Firebug.Module,
watchWindow: function(context, win)
{
- if (win.wrappedJSObject && win.wrappedJSObject.fireunit)
+ win = win.wrappedJSObject;
+ if (win && win.fireunit)
return;
// Inject "fireunit" object into the test page. This object
// provides all necessary APIs to write a unit test.
- win.wrappedJSObject.fireunit = new this.Fireunit(context, win);
+ win.fireunit = new this.Fireunit(context, win);
if (FBTrace.DBG_FIREUNIT)
FBTrace.sysout("fireunit.FireUnitModule.watchWindow: fireunit initialized for: " +
- win.wrappedJSObject.location.href);
+ win.location.href);
+
+ if (testQueue) {
+ // Start test-timeout that launches next test if the current one freezes.
+ // This allows to continue the current test-suite (testQueue).
+ // The timeout is registered after the test page is loaded, which allows
+ // to change the timeout value from within the test page.
+ // If testTimeout is set to 0 (default value), the functionality is disabled.
+ win.addEventListener("load", function() {
+ if (win.fireunit.testTimeout) {
+ testTimeoutID = setTimeout(function() {
+ if (FBTrace.DBG_FIREUNIT)
+ FBTrace.sysout("fireunit.testTimeout TEST FAILED: " + win.location);
+
+ win.fireunit.ok(false, $FU_STR("fireunit.label.Timeout") + " (" +
+ formatTime(win.fireunit.testTimeout) + "): " + win.location);
+ win.fireunit.testDone();
+ }, win.fireunit.testTimeout);
+ }
+ }, true);
+ }
},
unWatchWindow: function()
@@ -130,10 +156,9 @@ Firebug.FireUnitModule = extend(Firebug.Module,
* provider necessary APIs for test implementation.
*/
Firebug.FireUnitModule.Fireunit = function(context, win) {
- win = win.wrappedJSObject;
-
// Define fireunit APIs.
var fireunit = {
+ testTimeout: testTimeout,
forceHttp: function() {
cache.evictEntries(Ci.nsICache.STORE_ON_DISK);
cache.evictEntries(Ci.nsICache.STORE_IN_MEMORY);
@@ -149,7 +174,7 @@ Firebug.FireUnitModule.Fireunit = function(context, win) {
getServer().registerDirectory(path, dir);
if (FBTrace.DBG_FIREUNIT)
- FBTrace.sysout("fireunit.forceHttp server directory registered : "
+ FBTrace.sysout("fireunit.forceHttp server directory registered: "
+ dir.path + " => " + path);
win.location = getTestURL(winID, file.leafName);
@@ -171,6 +196,12 @@ Firebug.FireUnitModule.Fireunit = function(context, win) {
if (FBTrace.DBG_FIREUNIT)
FBTrace.sysout("fireunit.testDone: " + win.location);
+ // Test is done so, cleare break-timeout.
+ if (testTimeoutID) {
+ clearTimeout(testTimeoutID);
+ testTimeoutID = 0;
+ }
+
var panel = context.getPanel(panelName);
if ( testQueue ) {
if ( testQueue.length ) {
@@ -380,7 +411,7 @@ function $FU_STR(name)
{
if (FBTrace.DBG_FIREUNIT)
{
- FBTrace.sysout("fireunit.Missing translation for: " + name + "\n");
+ FBTrace.sysout("fireunit.Missing translation for: " + name);
FBTrace.sysout("fireunit.getString FAILS ", err);
}
}
@@ -15,3 +15,4 @@ fireunit.item.Copy_All=Copy All
fireunit.test.Line=Line
fireunit.label.Pass=Pass
fireunit.label.Fail=Fail
+fireunit.label.Timeout=Timeout
@@ -1,5 +1,6 @@
pref("extensions.firebug.fireunit.showPass", true);
pref("extensions.firebug.fireunit.showFail", true);
+pref("extensions.firebug.fireunit.testTimeout", 0); // Break timeout for stuck unit test. Disabled by default.
// Support for tracing console
pref("extensions.firebug.DBG_FIREUNIT", false);

0 comments on commit 7d8ded6

Please sign in to comment.