mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-02 20:37:21 +02:00
Fix intermittent issue with a unit test
Avoid to rely on timing in the test, which can cause intermittent failures. Instead, we check that the image is cached at the document/page level.
This commit is contained in:
parent
55c371d97c
commit
ed390c06a1
@ -4905,15 +4905,10 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
}
|
}
|
||||||
const { NUM_PAGES_THRESHOLD } = GlobalImageCache;
|
const { NUM_PAGES_THRESHOLD } = GlobalImageCache;
|
||||||
|
|
||||||
const loadingTask = getDocument(
|
const loadingTask = getDocument(buildGetDocumentParams("issue11518.pdf"));
|
||||||
buildGetDocumentParams("issue11518.pdf", {
|
|
||||||
pdfBug: true,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
const pdfDoc = await loadingTask.promise;
|
const pdfDoc = await loadingTask.promise;
|
||||||
const { canvasFactory } = pdfDoc;
|
const { canvasFactory } = pdfDoc;
|
||||||
let checkedCopyLocalImage = false,
|
let checkedCopyLocalImage = false;
|
||||||
firstStatsOverall = null;
|
|
||||||
|
|
||||||
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
for (let i = 1; i <= pdfDoc.numPages; i++) {
|
||||||
const pdfPage = await pdfDoc.getPage(i);
|
const pdfPage = await pdfDoc.getPage(i);
|
||||||
@ -4929,29 +4924,32 @@ have written that much by now. So, here’s to squashing bugs.`);
|
|||||||
});
|
});
|
||||||
|
|
||||||
await renderTask.promise;
|
await renderTask.promise;
|
||||||
|
const opList = renderTask.getOperatorList();
|
||||||
// The canvas is no longer necessary, since we only care about
|
// The canvas is no longer necessary, since we only care about
|
||||||
// the stats below.
|
// the operator list below.
|
||||||
canvasFactory.destroy(canvasAndCtx);
|
canvasFactory.destroy(canvasAndCtx);
|
||||||
|
|
||||||
const [statsOverall] = pdfPage.stats.times
|
const { commonObjs, objs } = pdfPage;
|
||||||
.filter(time => time.name === "Overall")
|
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
|
||||||
.map(time => time.end - time.start);
|
const [objId] = opList.argsArray[imgIndex];
|
||||||
|
|
||||||
if (i === 1) {
|
if (i < NUM_PAGES_THRESHOLD) {
|
||||||
firstStatsOverall = statsOverall;
|
// Image decoded in the worker-thread; stored as a page-level object.
|
||||||
|
expect(objs.has(objId)).toEqual(true);
|
||||||
|
expect(commonObjs.has(objId)).toEqual(false);
|
||||||
} else if (i === NUM_PAGES_THRESHOLD) {
|
} else if (i === NUM_PAGES_THRESHOLD) {
|
||||||
checkedCopyLocalImage = true;
|
checkedCopyLocalImage = true;
|
||||||
// Ensure that the images were copied in the main-thread, rather
|
// Ensure that the image was copied in the main-thread (into
|
||||||
// than being re-parsed in the worker-thread (which is slower).
|
// commonObjs), rather than being re-parsed in the worker-thread.
|
||||||
expect(statsOverall).toBeLessThan(firstStatsOverall / 2);
|
expect(objs.has(objId)).toEqual(false);
|
||||||
} else if (i > NUM_PAGES_THRESHOLD) {
|
expect(commonObjs.has(objId)).toEqual(true);
|
||||||
|
} else {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
expect(checkedCopyLocalImage).toBeTruthy();
|
expect(checkedCopyLocalImage).toBeTruthy();
|
||||||
|
|
||||||
await loadingTask.destroy();
|
await loadingTask.destroy();
|
||||||
firstStatsOverall = null;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("caches image resources at the document/page level, with corrupt images (issue 18042)", async function () {
|
it("caches image resources at the document/page level, with corrupt images (issue 18042)", async function () {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user