1 | import Piscina from '..';
|
---|
2 | import { cpus } from 'os';
|
---|
3 | import { test } from 'tap';
|
---|
4 | import { resolve } from 'path';
|
---|
5 |
|
---|
6 | test('will start with minThreads and max out at maxThreads', async ({ equal, rejects }) => {
|
---|
7 | const pool = new Piscina({
|
---|
8 | filename: resolve(__dirname, 'fixtures/eval.js'),
|
---|
9 | minThreads: 2,
|
---|
10 | maxThreads: 4
|
---|
11 | });
|
---|
12 | equal(pool.threads.length, 2);
|
---|
13 | rejects(pool.runTask('while(true) {}'));
|
---|
14 | equal(pool.threads.length, 2);
|
---|
15 | rejects(pool.runTask('while(true) {}'));
|
---|
16 | equal(pool.threads.length, 2);
|
---|
17 | rejects(pool.runTask('while(true) {}'));
|
---|
18 | equal(pool.threads.length, 3);
|
---|
19 | rejects(pool.runTask('while(true) {}'));
|
---|
20 | equal(pool.threads.length, 4);
|
---|
21 | rejects(pool.runTask('while(true) {}'));
|
---|
22 | equal(pool.threads.length, 4);
|
---|
23 | await pool.destroy();
|
---|
24 | });
|
---|
25 |
|
---|
26 | test('low maxThreads sets minThreads', async ({ equal }) => {
|
---|
27 | const pool = new Piscina({
|
---|
28 | filename: resolve(__dirname, 'fixtures/eval.js'),
|
---|
29 | maxThreads: 1
|
---|
30 | });
|
---|
31 | equal(pool.threads.length, 1);
|
---|
32 | equal(pool.options.minThreads, 1);
|
---|
33 | equal(pool.options.maxThreads, 1);
|
---|
34 | });
|
---|
35 |
|
---|
36 | test('high minThreads sets maxThreads', {
|
---|
37 | skip: cpus().length > 8
|
---|
38 | }, async ({ equal }) => {
|
---|
39 | const pool = new Piscina({
|
---|
40 | filename: resolve(__dirname, 'fixtures/eval.js'),
|
---|
41 | minThreads: 16
|
---|
42 | });
|
---|
43 | equal(pool.threads.length, 16);
|
---|
44 | equal(pool.options.minThreads, 16);
|
---|
45 | equal(pool.options.maxThreads, 16);
|
---|
46 | });
|
---|
47 |
|
---|
48 | test('conflicting min/max threads is error', async ({ throws }) => {
|
---|
49 | throws(() => new Piscina({
|
---|
50 | minThreads: 16,
|
---|
51 | maxThreads: 8
|
---|
52 | }), /options.minThreads and options.maxThreads must not conflict/);
|
---|
53 | });
|
---|