source: trip-planner-front/node_modules/piscina/test/thread-count.ts@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.5 KB
Line 
1import Piscina from '..';
2import { cpus } from 'os';
3import { test } from 'tap';
4import { resolve } from 'path';
5
6test('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
26test('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
36test('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
48test('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});
Note: See TracBrowser for help on using the repository browser.