Bug 1938866 - Fix intermittent test_rcwn_interrupted.js r=necko-reviewers,sunil
I think this is intermittent if the second request (with RCWN) happens to be opened before the first one. In this change, we only open the second request in the onStartRequest of the first one, thus hopefully eliminating the race. Differential Revision: https://phabricator.services.mozilla.com/D246743
This commit is contained in:
@@ -49,24 +49,44 @@ const responseBody =
|
|||||||
|
|
||||||
function contentHandler(metadata, response) {
|
function contentHandler(metadata, response) {
|
||||||
response.processAsync();
|
response.processAsync();
|
||||||
do_timeout(500, () => {
|
response.setHeader("Content-Type", "text/plain");
|
||||||
response.setHeader("Content-Type", "text/plain");
|
response.setHeader("ETag", "Just testing");
|
||||||
response.setHeader("ETag", "Just testing");
|
response.setHeader("Cache-Control", "max-age=99999");
|
||||||
response.setHeader("Cache-Control", "max-age=99999");
|
response.setHeader("Accept-Ranges", "bytes");
|
||||||
response.setHeader("Accept-Ranges", "bytes");
|
response.setHeader("Content-Length", "" + responseBody.length);
|
||||||
response.setHeader("Content-Length", "" + responseBody.length);
|
if (metadata.hasHeader("If-Range")) {
|
||||||
if (metadata.hasHeader("If-Range")) {
|
response.setStatusLine(metadata.httpVersion, 206, "Partial Content");
|
||||||
response.setStatusLine(metadata.httpVersion, 206, "Partial Content");
|
|
||||||
|
|
||||||
let len = responseBody.length;
|
let len = responseBody.length;
|
||||||
response.setHeader("Content-Range", "0-" + (len - 1) + "/" + len);
|
response.setHeader("Content-Range", "0-" + (len - 1) + "/" + len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
do_timeout(500, () => {
|
||||||
response.bodyOutputStream.write(responseBody, responseBody.length);
|
response.bodyOutputStream.write(responseBody, responseBody.length);
|
||||||
|
|
||||||
response.finish();
|
response.finish();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CustomChannelListener extends ChannelListener {
|
||||||
|
constructor(closure, ctx, flags) {
|
||||||
|
super(closure, ctx, flags);
|
||||||
|
|
||||||
|
this._onStartPromise = new Promise(resolve => {
|
||||||
|
this._onStartResolve = resolve;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
onStartRequest(request) {
|
||||||
|
this._onStartResolve();
|
||||||
|
|
||||||
|
// Call the original ChannelListener's onStartRequest method
|
||||||
|
if (typeof ChannelListener.prototype.onStartRequest === "function") {
|
||||||
|
ChannelListener.prototype.onStartRequest.call(this, request);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function run_test() {
|
function run_test() {
|
||||||
// Static check
|
// Static check
|
||||||
Assert.ok(responseBody.length > 1024);
|
Assert.ok(responseBody.length > 1024);
|
||||||
@@ -82,17 +102,22 @@ function run_test() {
|
|||||||
|
|
||||||
httpProtocolHandler.EnsureHSTSDataReady().then(function () {
|
httpProtocolHandler.EnsureHSTSDataReady().then(function () {
|
||||||
var chan1 = make_channel(URL + "/content");
|
var chan1 = make_channel(URL + "/content");
|
||||||
chan1.asyncOpen(
|
let chan1listener = new CustomChannelListener(
|
||||||
new ChannelListener(firstTimeThrough, null, CL_IGNORE_DELAYS)
|
firstTimeThrough,
|
||||||
);
|
null,
|
||||||
var chan2 = make_channel(URL + "/content");
|
CL_IGNORE_DELAYS
|
||||||
chan2
|
|
||||||
.QueryInterface(Ci.nsIRaceCacheWithNetwork)
|
|
||||||
.test_delayCacheEntryOpeningBy(200);
|
|
||||||
chan2.QueryInterface(Ci.nsIRaceCacheWithNetwork).test_triggerNetwork(50);
|
|
||||||
chan2.asyncOpen(
|
|
||||||
new ChannelListener(secondTimeThrough, null, CL_IGNORE_DELAYS)
|
|
||||||
);
|
);
|
||||||
|
chan1listener._onStartPromise.then(() => {
|
||||||
|
var chan2 = make_channel(URL + "/content");
|
||||||
|
chan2
|
||||||
|
.QueryInterface(Ci.nsIRaceCacheWithNetwork)
|
||||||
|
.test_delayCacheEntryOpeningBy(200);
|
||||||
|
chan2.QueryInterface(Ci.nsIRaceCacheWithNetwork).test_triggerNetwork(50);
|
||||||
|
chan2.asyncOpen(
|
||||||
|
new ChannelListener(secondTimeThrough, null, CL_IGNORE_DELAYS)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
chan1.asyncOpen(chan1listener);
|
||||||
});
|
});
|
||||||
|
|
||||||
do_test_pending();
|
do_test_pending();
|
||||||
|
|||||||
Reference in New Issue
Block a user