Skip to content

Commit ecb0f57

Browse files
authored
Merge pull request #20773 from calixteman/try_to_fix_intermittent
Fix intermittent issue with a unit test
2 parents 973add8 + ed390c0 commit ecb0f57

1 file changed

Lines changed: 16 additions & 18 deletions

File tree

test/unit/api_spec.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4905,15 +4905,10 @@ have written that much by now. So, here’s to squashing bugs.`);
49054905
}
49064906
const { NUM_PAGES_THRESHOLD } = GlobalImageCache;
49074907

4908-
const loadingTask = getDocument(
4909-
buildGetDocumentParams("issue11518.pdf", {
4910-
pdfBug: true,
4911-
})
4912-
);
4908+
const loadingTask = getDocument(buildGetDocumentParams("issue11518.pdf"));
49134909
const pdfDoc = await loadingTask.promise;
49144910
const { canvasFactory } = pdfDoc;
4915-
let checkedCopyLocalImage = false,
4916-
firstStatsOverall = null;
4911+
let checkedCopyLocalImage = false;
49174912

49184913
for (let i = 1; i <= pdfDoc.numPages; i++) {
49194914
const pdfPage = await pdfDoc.getPage(i);
@@ -4929,29 +4924,32 @@ have written that much by now. So, here’s to squashing bugs.`);
49294924
});
49304925

49314926
await renderTask.promise;
4927+
const opList = renderTask.getOperatorList();
49324928
// The canvas is no longer necessary, since we only care about
4933-
// the stats below.
4929+
// the operator list below.
49344930
canvasFactory.destroy(canvasAndCtx);
49354931

4936-
const [statsOverall] = pdfPage.stats.times
4937-
.filter(time => time.name === "Overall")
4938-
.map(time => time.end - time.start);
4932+
const { commonObjs, objs } = pdfPage;
4933+
const imgIndex = opList.fnArray.indexOf(OPS.paintImageXObject);
4934+
const [objId] = opList.argsArray[imgIndex];
49394935

4940-
if (i === 1) {
4941-
firstStatsOverall = statsOverall;
4936+
if (i < NUM_PAGES_THRESHOLD) {
4937+
// Image decoded in the worker-thread; stored as a page-level object.
4938+
expect(objs.has(objId)).toEqual(true);
4939+
expect(commonObjs.has(objId)).toEqual(false);
49424940
} else if (i === NUM_PAGES_THRESHOLD) {
49434941
checkedCopyLocalImage = true;
4944-
// Ensure that the images were copied in the main-thread, rather
4945-
// than being re-parsed in the worker-thread (which is slower).
4946-
expect(statsOverall).toBeLessThan(firstStatsOverall / 2);
4947-
} else if (i > NUM_PAGES_THRESHOLD) {
4942+
// Ensure that the image was copied in the main-thread (into
4943+
// commonObjs), rather than being re-parsed in the worker-thread.
4944+
expect(objs.has(objId)).toEqual(false);
4945+
expect(commonObjs.has(objId)).toEqual(true);
4946+
} else {
49484947
break;
49494948
}
49504949
}
49514950
expect(checkedCopyLocalImage).toBeTruthy();
49524951

49534952
await loadingTask.destroy();
4954-
firstStatsOverall = null;
49554953
});
49564954

49574955
it("caches image resources at the document/page level, with corrupt images (issue 18042)", async function () {

0 commit comments

Comments
 (0)