Bug 700540 - Intermittent test_jpakeclient.js | Shouldn't have aborted with jpake.error.timeout! r=gps

This commit is contained in:
Richard Newman 2012-02-19 12:02:01 -08:00
parent 23a5e04f8e
commit 19cf7c7eba

View File

@ -66,6 +66,11 @@ function server_report(request, response) {
response.setStatusLine(request.httpVersion, 200, "OK");
}
// Hook for test code.
let hooks = {
onGET: function onGET(request) {}
}
function ServerChannel() {
this.data = "";
this.etag = "";
@ -83,6 +88,7 @@ ServerChannel.prototype = {
let etag = request.getHeader("If-None-Match");
if (etag == this.etag) {
response.setStatusLine(request.httpVersion, 304, "Not Modified");
hooks.onGET(request);
return;
}
}
@ -95,6 +101,7 @@ ServerChannel.prototype = {
if (this.getCount == SERVER_MAX_GETS) {
this.clear();
}
hooks.onGET(request);
},
PUT: function PUT(request, response) {
@ -294,9 +301,15 @@ add_test(function test_lastMsgMaxTries() {
// to 2 times for other exchanges). So let's pretend it took
// 150ms to come up with the final payload, which should require
// 3 polls.
_("Pairing successful, waiting 150ms to send final payload.");
Utils.namedTimer(function() { snd.sendAndComplete(DATA); },
150, this, "_sendTimer");
// Rather than using an imprecise timer, we hook into the channel's
// GET handler to know how long to wait.
let count = 0;
hooks.onGET = function onGET(request) {
if (++count == 3) {
_("Third GET. Triggering send.");
Utils.nextTick(function() { snd.sendAndComplete(DATA); });
}
};
},
onComplete: function onComplete() {}
});
@ -314,6 +327,9 @@ add_test(function test_lastMsgMaxTries() {
// Ensure channel was cleared, no error report.
do_check_eq(channels[this.cid].data, undefined);
do_check_eq(error_report, undefined);
// Clean up.
hooks.onGET = function onGET(request) {};
run_next_test();
}
});