Bug 508128 - Additional diagnostics to report more data about test exceptions. r=waldo a=test-only

--HG--
extra : rebase_source : ececb0215cac3139336a67f429320ea4106e391f
This commit is contained in:
Robert O'Callahan 2009-11-05 15:06:00 -05:00
Родитель 5d9f3c0bfc
Коммит ee2cd851f2
3 изменённых файлов: 100 добавлений и 38 удалений

Просмотреть файл

@ -293,7 +293,7 @@ function runHttpTests(testArray, done)
} }
catch (e) catch (e)
{ {
do_throw("error running test-completion callback: " + e); do_report_unexpected_exception(e, "running test-completion callback");
} }
return; return;
} }
@ -310,9 +310,12 @@ function runHttpTests(testArray, done)
{ {
try try
{ {
do_throw("testArray[" + testIndex + "].initChannel(ch) failed: " + e); do_report_unexpected_exception(e, "testArray[" + testIndex + "].initChannel(ch)");
}
catch (e)
{
/* swallow and let tests continue */
} }
catch (e) { /* swallow and let tests continue */ }
} }
ch.asyncOpen(listener, null); ch.asyncOpen(listener, null);
@ -341,12 +344,12 @@ function runHttpTests(testArray, done)
} }
catch (e) catch (e)
{ {
do_throw("testArray[" + testIndex + "].onStartRequest: " + e); do_report_unexpected_exception(e, "testArray[" + testIndex + "].onStartRequest");
} }
} }
catch (e) catch (e)
{ {
dumpn("!!! swallowing onStartRequest exception so onStopRequest is " + do_note_exception(e, "!!! swallowing onStartRequest exception so onStopRequest is " +
"called..."); "called...");
} }
}, },
@ -464,7 +467,7 @@ function runRawTests(testArray, done)
} }
catch (e) catch (e)
{ {
do_throw("error running test-completion callback: " + e); do_report_unexpected_exception(e, "running test-completion callback");
} }
return; return;
} }
@ -519,20 +522,31 @@ function runRawTests(testArray, done)
{ {
onInputStreamReady: function(stream) onInputStreamReady: function(stream)
{ {
var bis = new BinaryInputStream(stream);
var av = 0;
try try
{ {
av = bis.available(); var bis = new BinaryInputStream(stream);
}
catch (e) { /* default to 0 */ }
if (av > 0) var av = 0;
try
{
av = bis.available();
}
catch (e)
{
/* default to 0 */
do_note_exception(e);
}
if (av > 0)
{
received += String.fromCharCode.apply(null, bis.readByteArray(av));
waitForMoreInput(stream);
return;
}
}
catch(e)
{ {
received += String.fromCharCode.apply(null, bis.readByteArray(av)); do_report_unexpected_exception(e);
waitForMoreInput(stream);
return;
} }
var rawTest = testArray[testIndex]; var rawTest = testArray[testIndex];
@ -542,12 +556,19 @@ function runRawTests(testArray, done)
} }
catch (e) catch (e)
{ {
do_throw("error thrown by responseCheck: " + e); do_report_unexpected_exception(e);
} }
finally finally
{ {
stream.close(); try
performNextTest(); {
stream.close();
performNextTest();
}
catch (e)
{
do_report_unexpected_exception(e);
}
} }
} }
}; };
@ -568,14 +589,25 @@ function runRawTests(testArray, done)
else else
testArray[testIndex].data[dataIndex] = str.substring(written); testArray[testIndex].data[dataIndex] = str.substring(written);
} }
catch (e) { /* stream could have been closed, just ignore */ } catch (e)
{
do_note_exception(e);
/* stream could have been closed, just ignore */
}
// Keep writing data while we can write and try
// until there's no more data to read {
if (written > 0 && dataIndex < testArray[testIndex].data.length) // Keep writing data while we can write and
waitToWriteOutput(stream); // until there's no more data to read
else if (written > 0 && dataIndex < testArray[testIndex].data.length)
stream.close(); waitToWriteOutput(stream);
else
stream.close();
}
catch (e)
{
do_report_unexpected_exception(e);
}
} }
}; };

Просмотреть файл

@ -26,6 +26,7 @@ TracingListener.prototype = {
var newListener = new TracingListener(); var newListener = new TracingListener();
newListener.listener = request.setNewListener(newListener); newListener.listener = request.setNewListener(newListener);
} catch(e) { } catch(e) {
dump("TracingListener.onStartRequest swallowing exception: " + e + "\n");
return; // OK return; // OK
} }
do_throw("replaced channel's listener during onStartRequest."); do_throw("replaced channel's listener during onStartRequest.");
@ -35,21 +36,25 @@ TracingListener.prototype = {
dump("*** tracing listener onStopRequest\n"); dump("*** tracing listener onStopRequest\n");
do_check_eq(gotOnStartRequest, true); do_check_eq(gotOnStartRequest, true);
var sin = Components.classes["@mozilla.org/scriptableinputstream;1"].
createInstance(Ci.nsIScriptableInputStream);
streamSink.close(); try {
var input = pipe.inputStream; var sin = Components.classes["@mozilla.org/scriptableinputstream;1"].
sin.init(input); createInstance(Ci.nsIScriptableInputStream);
do_check_eq(sin.available(), originalBody.length);
streamSink.close();
var input = pipe.inputStream;
sin.init(input);
do_check_eq(sin.available(), originalBody.length);
var result = sin.read(originalBody.length); var result = sin.read(originalBody.length);
do_check_eq(result, originalBody); do_check_eq(result, originalBody);
input.close(); input.close();
} catch (e) {
httpserver.stop(do_test_finished); dump("TracingListener.onStopRequest swallowing exception: " + e + "\n");
} finally {
httpserver.stop(do_test_finished);
}
}, },
QueryInterface: function(iid) { QueryInterface: function(iid) {
@ -71,10 +76,12 @@ HttpResponseExaminer.prototype = {
Cc["@mozilla.org/observer-service;1"]. Cc["@mozilla.org/observer-service;1"].
getService(Components.interfaces.nsIObserverService). getService(Components.interfaces.nsIObserverService).
addObserver(this, "http-on-examine-response", true); addObserver(this, "http-on-examine-response", true);
dump("Did HttpResponseExaminer.register\n");
}, },
// Replace channel's listener. // Replace channel's listener.
observe: function(subject, topic, data) { observe: function(subject, topic, data) {
dump("In HttpResponseExaminer.observe\n");
try { try {
subject.QueryInterface(Components.interfaces.nsITraceableChannel); subject.QueryInterface(Components.interfaces.nsITraceableChannel);
@ -90,6 +97,7 @@ HttpResponseExaminer.prototype = {
} catch(e) { } catch(e) {
do_throw("can't replace listener " + e); do_throw("can't replace listener " + e);
} }
dump("Did HttpResponseExaminer.observe\n");
}, },
QueryInterface: function(iid) { QueryInterface: function(iid) {

Просмотреть файл

@ -427,6 +427,28 @@ function do_throw(text, stack) {
throw Components.results.NS_ERROR_ABORT; throw Components.results.NS_ERROR_ABORT;
} }
function do_report_unexpected_exception(ex, text) {
var caller_stack = Components.stack.caller;
text = text ? text + " - " : "";
_passed = false;
dump("TEST-UNEXPECTED-FAIL | " + caller_stack.filename + " | " + text +
"Unexpected exception " + ex + ", see following stack:\n" + ex.stack +
"\n");
_do_quit();
throw Components.results.NS_ERROR_ABORT;
}
function do_note_exception(ex, text) {
var caller_stack = Components.stack.caller;
text = text ? text + " - " : "";
dump("TEST-INFO | " + caller_stack.filename + " | " + text +
"Swallowed exception " + ex + ", see following stack:\n" + ex.stack +
"\n");
}
function do_check_neq(left, right, stack) { function do_check_neq(left, right, stack) {
if (!stack) if (!stack)
stack = Components.stack.caller; stack = Components.stack.caller;