3 Checkes if the concurrent cache read/write works when the write is interrupted because of max-entry-size limits.
4 This is enhancement of 29a test, this test checks that cocurrency is resumed when the first channel is interrupted
5 in the middle of reading and the second channel already consumed some content from the cache entry.
6 This test is using a resumable response.
7 - with a profile, set max-entry-size to 1 (=1024 bytes)
8 - first channel makes a request for a resumable response
9 - second channel makes a request for the same resource, concurrent read happens
10 - first channel sets predicted data size on the entry with every chunk, it's doomed on 1024
11 - second channel now must engage interrupted concurrent write algorithm and read the rest of the content from the network
12 - both channels must deliver full content w/o errors
18 const { HttpServer
} = ChromeUtils
.importESModule(
19 "resource://testing-common/httpd.sys.mjs"
22 var httpProtocolHandler
= Cc
[
23 "@mozilla.org/network/protocol;1?name=http"
24 ].getService(Ci
.nsIHttpProtocolHandler
);
26 ChromeUtils
.defineLazyGetter(this, "URL", function () {
27 return "http://localhost:" + httpServer
.identity
.primaryPort
;
30 var httpServer
= null;
32 function make_channel(url
) {
33 return NetUtil
.newChannel({ uri
: url
, loadUsingSystemPrincipal
: true });
36 // need something bigger than 1024 bytes
38 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
39 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
40 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
41 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
42 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
43 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
44 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
45 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
46 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
47 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef" +
48 "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef";
50 function contentHandler(metadata
, response
) {
51 response
.processAsync();
52 do_timeout(500, () => {
53 response
.setHeader("Content-Type", "text/plain");
54 response
.setHeader("ETag", "Just testing");
55 response
.setHeader("Cache-Control", "max-age=99999");
56 response
.setHeader("Accept-Ranges", "bytes");
57 response
.setHeader("Content-Length", "" + responseBody
.length
);
58 if (metadata
.hasHeader("If-Range")) {
59 response
.setStatusLine(metadata
.httpVersion
, 206, "Partial Content");
61 let len
= responseBody
.length
;
62 response
.setHeader("Content-Range", "0-" + (len
- 1) + "/" + len
);
64 response
.bodyOutputStream
.write(responseBody
, responseBody
.length
);
72 Assert
.ok(responseBody
.length
> 1024);
76 Services
.prefs
.setIntPref("browser.cache.disk.max_entry_size", 1);
77 Services
.prefs
.setBoolPref("network.http.rcwn.enabled", false);
79 httpServer
= new HttpServer();
80 httpServer
.registerPathHandler("/content", contentHandler
);
83 httpProtocolHandler
.EnsureHSTSDataReady().then(function () {
84 var chan1
= make_channel(URL
+ "/content");
86 new ChannelListener(firstTimeThrough
, null, CL_IGNORE_DELAYS
)
88 var chan2
= make_channel(URL
+ "/content");
90 .QueryInterface(Ci
.nsIRaceCacheWithNetwork
)
91 .test_delayCacheEntryOpeningBy(200);
92 chan2
.QueryInterface(Ci
.nsIRaceCacheWithNetwork
).test_triggerNetwork(50);
94 new ChannelListener(secondTimeThrough
, null, CL_IGNORE_DELAYS
)
101 function firstTimeThrough(request
, buffer
) {
102 Assert
.equal(buffer
, responseBody
);
105 function secondTimeThrough(request
, buffer
) {
106 Assert
.equal(buffer
, responseBody
);
107 httpServer
.stop(do_test_finished
);