diff --git a/test/unit/multithread/naive/naive.test.ts b/test/unit/multithread/naive/naive.test.ts index 93e4276..f522ade 100644 --- a/test/unit/multithread/naive/naive.test.ts +++ b/test/unit/multithread/naive/naive.test.ts @@ -1,10 +1,12 @@ import {expect} from "chai"; import {IBls, PublicKey, Signature} from "../../../../src"; import {BlsMultiThreadNaive} from "./index"; -import {warmUpWorkers} from "./utils"; export function runMultithreadTests(bls: IBls): void { describe("bls pool naive", function () { + // Starting all threads may take a while due to ts-node compilation + this.timeout(20 * 1000); + const nodeJsSemver = process.versions.node; const nodeJsMajorVer = parseInt(nodeJsSemver.split(".")[0]); if (!nodeJsMajorVer) { @@ -18,14 +20,10 @@ export function runMultithreadTests(bls: IBls): void { let pool: BlsMultiThreadNaive; before("Create pool and warm-up wallets", async function () { - // Starting all threads may take a while due to ts-node compilation - this.timeout(20 * 1000); pool = new BlsMultiThreadNaive(bls.implementation); - await warmUpWorkers(bls, pool); }); after("Destroy pool", async function () { - this.timeout(20 * 1000); await pool.destroy(); }); @@ -36,8 +34,12 @@ export function runMultithreadTests(bls: IBls): void { const sig = sk.sign(msg); it("verify", async () => { - const valid = await pool.verify(pk, msg, sig); - expect(valid).to.equal(true); + const validArr = await Promise.all( + Array.from({length: 32}, (i) => i).map(async () => pool.verify(pk, msg, sig)) + ); + for (const [i, valid] of validArr.entries()) { + expect(valid).to.equal(true, `Invalid ${i}`); + } }); }); diff --git a/test/unit/multithread/naive/utils.ts b/test/unit/multithread/naive/utils.ts index 9d8e223..53a5bdf 100644 --- a/test/unit/multithread/naive/utils.ts +++ b/test/unit/multithread/naive/utils.ts @@ -1,16 +1,3 @@ -import os from "os"; -import {IBls} from "../../../../src"; -import {BlsMultiThreadNaive} from "./index"; - -export async function warmUpWorkers(bls: IBls, pool: BlsMultiThreadNaive): Promise { - const msg = Buffer.alloc(32, 1); - const sk = bls.SecretKey.fromKeygen(Buffer.alloc(32, 1)); - const pk = sk.toPublicKey(); - const sig = sk.sign(msg); - - await Promise.all(Array.from({length: os.cpus().length}, (_, i) => i).map(() => pool.verify(pk, msg, sig))); -} - export function chunkify(arr: T[], chunkCount: number): T[][] { const chunkSize = Math.round(arr.length / chunkCount); const arrArr: T[][] = [];