|
1 | 1 | import type DBTransaction from '#DBTransaction.js';
|
2 | 2 | import type { KeyPath } from '#types.js';
|
3 | 3 | import type { ResourceRelease } from '@matrixai/resources';
|
4 |
| -import type { DBWorkerModule } from './workers/dbWorkerModule.js'; |
| 4 | +import type { DBWorker } from './workers/dbWorker.js'; |
5 | 5 | import os from 'node:os';
|
6 | 6 | import path from 'node:path';
|
7 | 7 | import fs from 'node:fs';
|
8 | 8 | import nodeCrypto from 'node:crypto';
|
| 9 | +import { Worker } from 'node:worker_threads'; |
9 | 10 | import Logger, { LogLevel, StreamHandler } from '@matrixai/logger';
|
10 |
| -// import { WorkerManager } from '@matrixai/workers'; |
11 |
| -import matrixaiWorkers from '@matrixai/workers'; |
| 11 | +import { WorkerManager } from '@matrixai/workers'; |
12 | 12 | import { withF } from '@matrixai/resources';
|
13 |
| -import { spawn, Worker } from 'threads'; |
| 13 | +import * as testsUtils from './utils.js'; |
| 14 | +import dbWorker from './workers/dbWorker.js'; |
14 | 15 | import DB from '#DB.js';
|
15 | 16 | import * as errors from '#errors.js';
|
16 | 17 | import * as utils from '#utils.js';
|
17 |
| -import * as testsUtils from './utils.js'; |
18 |
| - |
19 |
| -const { WorkerManager } = matrixaiWorkers; |
20 | 18 |
|
21 | 19 | describe(DB.name, () => {
|
22 | 20 | const logger = new Logger(`${DB.name} Test`, LogLevel.WARN, [
|
23 | 21 | new StreamHandler(),
|
24 | 22 | ]);
|
25 | 23 | const crypto = {
|
26 | 24 | key: testsUtils.generateKeySync(256),
|
27 |
| - ops: { |
28 |
| - encrypt: testsUtils.encrypt, |
29 |
| - decrypt: testsUtils.decrypt, |
30 |
| - }, |
| 25 | + ops: dbWorker, |
31 | 26 | };
|
32 | 27 | let dataDir: string;
|
33 | 28 | beforeEach(async () => {
|
@@ -346,12 +341,12 @@ describe(DB.name, () => {
|
346 | 341 | test('parallelized get and put and del', async () => {
|
347 | 342 | const dbPath = `${dataDir}/db`;
|
348 | 343 | const db = await DB.createDB({ dbPath, crypto, logger });
|
349 |
| - const workerManager = |
350 |
| - await WorkerManager.createWorkerManager<DBWorkerModule>({ |
351 |
| - workerFactory: () => spawn(new Worker('./workers/dbWorker')), |
352 |
| - cores: 1, |
353 |
| - logger, |
354 |
| - }); |
| 344 | + const workerManager = await WorkerManager.createWorkerManager<DBWorker>({ |
| 345 | + workerFactory: () => new Worker('./workers/dbWorker'), |
| 346 | + cores: 1, |
| 347 | + manifest: dbWorker, |
| 348 | + logger, |
| 349 | + }); |
355 | 350 | db.setWorkerManager(workerManager);
|
356 | 351 | await db.start();
|
357 | 352 | await db.put('a', 'value0');
|
@@ -408,12 +403,12 @@ describe(DB.name, () => {
|
408 | 403 | test('parallelized batch put and del', async () => {
|
409 | 404 | const dbPath = `${dataDir}/db`;
|
410 | 405 | const db = await DB.createDB({ dbPath, crypto, logger });
|
411 |
| - const workerManager = |
412 |
| - await WorkerManager.createWorkerManager<DBWorkerModule>({ |
413 |
| - workerFactory: () => spawn(new Worker('./workers/dbWorker')), |
414 |
| - cores: 4, |
415 |
| - logger, |
416 |
| - }); |
| 406 | + const workerManager = await WorkerManager.createWorkerManager<DBWorker>({ |
| 407 | + workerFactory: () => new Worker('./workers/dbWorker'), |
| 408 | + cores: 4, |
| 409 | + manifest: dbWorker, |
| 410 | + logger, |
| 411 | + }); |
417 | 412 | db.setWorkerManager(workerManager);
|
418 | 413 | await db.start();
|
419 | 414 | await db.batch([
|
|
0 commit comments