Bug 1599160 - Allow waiting for less expected requests in a complicated netmonitor test. r=bomsy,perftest-reviewers,sparky

The complicated test loads a lot of iframes. Now that with my changes we
coalesce stylesheet loads across documents it's expected to have way
less network loads for this test, which has a lot of facebook iframes
that load multiple stylesheets each.

The value is the one that made it reliably pass on my machine.

Differential Revision: https://phabricator.services.mozilla.com/D79394
This commit is contained in:
Emilio Cobos Álvarez 2020-06-15 13:15:35 +00:00
Родитель 88493a8db6
Коммит 421c78970d
2 изменённых файлов: 41 добавлений и 10 удалений

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

@ -18,7 +18,10 @@ const {
openResponseDetailsPanel,
} = require("./netmonitor-helpers");
const EXPECTED_REQUESTS = 280;
const EXPECTED_REQUESTS = {
min: 230,
max: 280,
};
module.exports = async function() {
await testSetup(COMPLICATED_URL);
@ -30,7 +33,8 @@ module.exports = async function() {
const requestsDone = waitForNetworkRequests(
"complicated.netmonitor",
toolbox,
EXPECTED_REQUESTS
EXPECTED_REQUESTS.min,
EXPECTED_REQUESTS.max
);
await reloadPageAndLog("complicated.netmonitor", toolbox);
await requestsDone;

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

@ -22,28 +22,54 @@ const { getToolbox, runTest } = require("../head");
* - the request start and end times are overlapping. If a new request starts a moment
* after the previous one was finished, the wait will be ended in the "interim"
* period.
*
* We might need to allow a range of requests because even though we run with
* cache disabled, different loads can still be coalesced, and whether they're
* coalesced or not depends on timing.
*
* @returns a promise that resolves when the wait is done.
*/
async function waitForAllRequestsFinished(expectedRequests) {
async function waitForAllRequestsFinished(
minExpectedRequests,
maxExpectedRequests
) {
let toolbox = await getToolbox();
let window = toolbox.getCurrentPanel().panelWin;
return new Promise(resolve => {
// Explicitly waiting for specific number of requests arrived
let payloadReady = 0;
let resolveWithLessThanMaxRequestsTimer = null;
function onPayloadReady(_, id) {
payloadReady++;
dump(`Waiting for ${maxExpectedRequests - payloadReady} requests\n`);
maybeResolve();
}
function doResolve() {
// All requests are done - unsubscribe from events and resolve!
window.api.off(EVENTS.PAYLOAD_READY, onPayloadReady);
// Resolve after current frame
setTimeout(resolve, 1);
}
function maybeResolve() {
if (resolveWithLessThanMaxRequestsTimer) {
clearTimeout(resolveWithLessThanMaxRequestsTimer);
resolveWithLessThanMaxRequestsTimer = null;
}
// Have all the requests finished yet?
if (payloadReady >= expectedRequests) {
// All requests are done - unsubscribe from events and resolve!
window.api.off(EVENTS.PAYLOAD_READY, onPayloadReady);
// Resolve after current frame
setTimeout(resolve, 1);
if (payloadReady >= maxExpectedRequests) {
doResolve();
return;
}
// If we're past the minimum threshold, wait to see if more requests come
// up, but resolve otherwise.
if (payloadReady >= minExpectedRequests) {
resolveWithLessThanMaxRequestsTimer = setTimeout(doResolve, 1000);
}
}
@ -96,10 +122,11 @@ function mouseDownElement(el, win) {
exports.waitForNetworkRequests = async function(
label,
toolbox,
expectedRequests
minExpectedRequests,
maxExpectedRequests = minExpectedRequests
) {
let test = runTest(label + ".requestsFinished.DAMP");
await waitForAllRequestsFinished(expectedRequests);
await waitForAllRequestsFinished(minExpectedRequests, maxExpectedRequests);
test.done();
};