Bug 486996 - xpcshell-tests: test_compose/unit/test_sendMessageLater2.js hangs often; r=bienvenu
--- a/mailnews/compose/test/unit/test_sendMessageLater2.js
+++ b/mailnews/compose/test/unit/test_sendMessageLater2.js
@@ -90,32 +90,23 @@ msll.prototype = {
// Check that the send later service now thinks we don't have messages to
// send.
do_check_eq(msgSendLater.hasUnsentMessages(identity), false);
this.checkMessageSend(gLastSentMessage);
} catch (e) {
dump(e);
do_throw(e);
- } finally {
- server.resetTest();
- server.stop();
-
- var thread = gThreadManager.currentThread;
- while (thread.hasPendingEvents())
- thread.processNextEvent(true);
}
- if (gMessageSendStatus == 0) {
- dump("gMessageSendStatus to 1\n");
- gMessageSendStatus = 1;
- }
- else if (gMessageSendStatus == 2) {
- dump("next driver\n");
- async_driver();
- }
+ // The extra timeout here is to work around an issue where sometimes
+ // the sendUnsentMessages is completely synchronous up until onStopSending
+ // and sometimes it isn't. This protects us for the synchronous case to
+ // allow the sendUnsentMessages function to complete and exit before we
+ // call async_driver.
+ do_timeout(0, async_driver);
}
};
// This function is used to find out when the copying of the message to the
// unsent message folder is completed, and hence can fire off the actual
// sending of the message.
function OnStopCopy(aStatus)
{
@@ -173,27 +164,18 @@ function sendUnsentMessages()
// Start the fake SMTP server
server.start(SMTP_PORT);
// Send the unsent message
msgSendLater.sendUnsentMessages(identity);
server.performTest();
} catch (e) {
do_throw(e);
- } finally {
- server.stop();
-
- var thread = gThreadManager.currentThread;
- while (thread.hasPendingEvents())
- thread.processNextEvent(true);
}
- if (!gMessageSendStatus)
- gMessageSendStatus = 2;
-
- return gMessageSendStatus == 1;
+ return false;
}
function runServerTest()
{
server.performTest();
}
function actually_run_test() {
@@ -203,16 +185,20 @@ function actually_run_test() {
yield async_run({func: sendMessageLater, args: [0]});
dump("Send unsent message\n");
yield async_run({func: sendUnsentMessages});
// Check sent folder is now empty.
do_check_eq(gSentFolder.getTotalMessages(false), 0);
+ // Reset the server
+ server.stop();
+ server.resetTest();
+
// and reset counts
resetCounts();
dump("Copy more messages\n");
yield async_run({func: sendMessageLater, args: [1]});
// XXX Only do one the second time round, as described at the start of the
// file.