commit
d1416cbe2c
|
@ -135,7 +135,7 @@ AsyncProxy.prototype.delegate = function(method, options) {
|
||||||
|
|
||||||
const id = this.getID();
|
const id = this.getID();
|
||||||
const requests = this.workers.map(worker => worker.requests);
|
const requests = this.workers.map(worker => worker.requests);
|
||||||
const minRequests = Math.min(requests);
|
const minRequests = Math.min(...requests);
|
||||||
let workerId = 0;
|
let workerId = 0;
|
||||||
for(; workerId < this.workers.length; workerId++) {
|
for(; workerId < this.workers.length; workerId++) {
|
||||||
if (this.workers[workerId].requests === minRequests) {
|
if (this.workers[workerId].requests === minRequests) {
|
||||||
|
|
|
@ -744,6 +744,40 @@ describe('OpenPGP.js public api tests', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Test multiple workers', async function() {
|
||||||
|
openpgp.config.show_version = false;
|
||||||
|
openpgp.config.commentstring = 'different';
|
||||||
|
if (!openpgp.getWorker()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const { workers } = openpgp.getWorker();
|
||||||
|
try {
|
||||||
|
await privateKey.keys[0].decrypt(passphrase)
|
||||||
|
openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 2});
|
||||||
|
|
||||||
|
const workerTest = (_, index) => {
|
||||||
|
const plaintext = input.createSomeMessage() + index + '\n한국어/조선말';
|
||||||
|
return openpgp.encrypt({
|
||||||
|
publicKeys: publicKey.keys,
|
||||||
|
data: plaintext
|
||||||
|
}).then(function (encrypted) {
|
||||||
|
expect(encrypted.data).to.exist;
|
||||||
|
expect(encrypted.data).not.to.match(/^Version:/);
|
||||||
|
expect(encrypted.data).to.match(/Comment: different/);
|
||||||
|
return openpgp.decrypt({
|
||||||
|
privateKeys: privateKey.keys[0],
|
||||||
|
message: openpgp.message.readArmored(encrypted.data)
|
||||||
|
});
|
||||||
|
}).then(function (decrypted) {
|
||||||
|
expect(decrypted.data).to.equal(plaintext);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
await Promise.all(Array(10).fill(null).map(workerTest));
|
||||||
|
} finally {
|
||||||
|
openpgp.initWorker({path: '../dist/openpgp.worker.js', workers, n: 1 });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
it('Calling decrypt with not decrypted key leads to exception', function() {
|
it('Calling decrypt with not decrypted key leads to exception', function() {
|
||||||
const encOpt = {
|
const encOpt = {
|
||||||
data: plaintext,
|
data: plaintext,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user