Remove warmup workers function
This commit is contained in:
parent
69c3408964
commit
7d9aebd3fe
|
@ -1,10 +1,12 @@
|
||||||
import {expect} from "chai";
|
import {expect} from "chai";
|
||||||
import {IBls, PublicKey, Signature} from "../../../../src";
|
import {IBls, PublicKey, Signature} from "../../../../src";
|
||||||
import {BlsMultiThreadNaive} from "./index";
|
import {BlsMultiThreadNaive} from "./index";
|
||||||
import {warmUpWorkers} from "./utils";
|
|
||||||
|
|
||||||
export function runMultithreadTests(bls: IBls): void {
|
export function runMultithreadTests(bls: IBls): void {
|
||||||
describe("bls pool naive", function () {
|
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 nodeJsSemver = process.versions.node;
|
||||||
const nodeJsMajorVer = parseInt(nodeJsSemver.split(".")[0]);
|
const nodeJsMajorVer = parseInt(nodeJsSemver.split(".")[0]);
|
||||||
if (!nodeJsMajorVer) {
|
if (!nodeJsMajorVer) {
|
||||||
|
@ -18,14 +20,10 @@ export function runMultithreadTests(bls: IBls): void {
|
||||||
let pool: BlsMultiThreadNaive;
|
let pool: BlsMultiThreadNaive;
|
||||||
|
|
||||||
before("Create pool and warm-up wallets", async function () {
|
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);
|
pool = new BlsMultiThreadNaive(bls.implementation);
|
||||||
await warmUpWorkers(bls, pool);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after("Destroy pool", async function () {
|
after("Destroy pool", async function () {
|
||||||
this.timeout(20 * 1000);
|
|
||||||
await pool.destroy();
|
await pool.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -36,8 +34,12 @@ export function runMultithreadTests(bls: IBls): void {
|
||||||
const sig = sk.sign(msg);
|
const sig = sk.sign(msg);
|
||||||
|
|
||||||
it("verify", async () => {
|
it("verify", async () => {
|
||||||
const valid = await pool.verify(pk, msg, sig);
|
const validArr = await Promise.all(
|
||||||
expect(valid).to.equal(true);
|
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}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -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<void> {
|
|
||||||
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<T>(arr: T[], chunkCount: number): T[][] {
|
export function chunkify<T>(arr: T[], chunkCount: number): T[][] {
|
||||||
const chunkSize = Math.round(arr.length / chunkCount);
|
const chunkSize = Math.round(arr.length / chunkCount);
|
||||||
const arrArr: T[][] = [];
|
const arrArr: T[][] = [];
|
||||||
|
|
Reference in New Issue