Wait for previous pdfDocument(s) to be destroyed before running the next reference test
Refactors `Driver._cleanup` to return a `Promise` which is resolved once all opened documents have been destroyed. This is then used in `Driver._nextTask` to ensure that we wait for everything to be cleaned up, such that the tests run sequentially.
This commit is contained in:
parent
52998c5fe1
commit
b5775af716
@ -334,66 +334,67 @@ var Driver = (function DriverClosure() { // eslint-disable-line no-unused-vars
|
|||||||
}, this.delay);
|
}, this.delay);
|
||||||
},
|
},
|
||||||
|
|
||||||
_nextTask: function Driver_nextTask() {
|
_nextTask() {
|
||||||
var self = this;
|
let failure = '';
|
||||||
var failure = '';
|
|
||||||
|
|
||||||
this._cleanup();
|
|
||||||
|
|
||||||
|
this._cleanup().then(() => {
|
||||||
if (this.currentTask === this.manifest.length) {
|
if (this.currentTask === this.manifest.length) {
|
||||||
this._done();
|
this._done();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var task = this.manifest[this.currentTask];
|
let task = this.manifest[this.currentTask];
|
||||||
task.round = 0;
|
task.round = 0;
|
||||||
task.pageNum = task.firstPage || 1;
|
task.pageNum = task.firstPage || 1;
|
||||||
task.stats = { times: [] };
|
task.stats = { times: [] };
|
||||||
|
|
||||||
this._log('Loading file "' + task.file + '"\n');
|
this._log('Loading file "' + task.file + '"\n');
|
||||||
|
|
||||||
var absoluteUrl = new URL(task.file, window.location).href;
|
let absoluteUrl = new URL(task.file, window.location).href;
|
||||||
PDFJS.disableRange = task.disableRange;
|
PDFJS.disableRange = task.disableRange;
|
||||||
PDFJS.disableAutoFetch = !task.enableAutoFetch;
|
PDFJS.disableAutoFetch = !task.enableAutoFetch;
|
||||||
try {
|
try {
|
||||||
PDFJS.getDocument({
|
PDFJS.getDocument({
|
||||||
url: absoluteUrl,
|
url: absoluteUrl,
|
||||||
password: task.password
|
password: task.password,
|
||||||
}).then(function(doc) {
|
}).then((doc) => {
|
||||||
task.pdfDoc = doc;
|
task.pdfDoc = doc;
|
||||||
self._nextPage(task, failure);
|
this._nextPage(task, failure);
|
||||||
}, function(e) {
|
}, (err) => {
|
||||||
failure = 'Loading PDF document: ' + e;
|
failure = 'Loading PDF document: ' + err;
|
||||||
self._nextPage(task, failure);
|
this._nextPage(task, failure);
|
||||||
});
|
});
|
||||||
return;
|
return;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
failure = 'Loading PDF document: ' + this._exceptionToString(e);
|
failure = 'Loading PDF document: ' + this._exceptionToString(e);
|
||||||
}
|
}
|
||||||
this._nextPage(task, failure);
|
this._nextPage(task, failure);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
_cleanup: function Driver_cleanup() {
|
_cleanup() {
|
||||||
// Clear out all the stylesheets since a new one is created for each font.
|
// Clear out all the stylesheets since a new one is created for each font.
|
||||||
while (document.styleSheets.length > 0) {
|
while (document.styleSheets.length > 0) {
|
||||||
var styleSheet = document.styleSheets[0];
|
let styleSheet = document.styleSheets[0];
|
||||||
while (styleSheet.cssRules.length > 0) {
|
while (styleSheet.cssRules.length > 0) {
|
||||||
styleSheet.deleteRule(0);
|
styleSheet.deleteRule(0);
|
||||||
}
|
}
|
||||||
var ownerNode = styleSheet.ownerNode;
|
let ownerNode = styleSheet.ownerNode;
|
||||||
ownerNode.parentNode.removeChild(ownerNode);
|
ownerNode.parentNode.removeChild(ownerNode);
|
||||||
}
|
}
|
||||||
var body = document.body;
|
let body = document.body;
|
||||||
while (body.lastChild !== this.end) {
|
while (body.lastChild !== this.end) {
|
||||||
body.removeChild(body.lastChild);
|
body.removeChild(body.lastChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let destroyedPromises = [];
|
||||||
// Wipe out the link to the pdfdoc so it can be GC'ed.
|
// Wipe out the link to the pdfdoc so it can be GC'ed.
|
||||||
for (var i = 0; i < this.manifest.length; i++) {
|
for (let i = 0; i < this.manifest.length; i++) {
|
||||||
if (this.manifest[i].pdfDoc) {
|
if (this.manifest[i].pdfDoc) {
|
||||||
this.manifest[i].pdfDoc.destroy();
|
destroyedPromises.push(this.manifest[i].pdfDoc.destroy());
|
||||||
delete this.manifest[i].pdfDoc;
|
delete this.manifest[i].pdfDoc;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return Promise.all(destroyedPromises);
|
||||||
},
|
},
|
||||||
|
|
||||||
_exceptionToString: function Driver_exceptionToString(e) {
|
_exceptionToString: function Driver_exceptionToString(e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user