source: trip-planner-front/node_modules/piscina/test/option-validation.ts@ fa375fe

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

initial commit

  • Property mode set to 100644
File size: 4.1 KB
Line 
1import Piscina from '..';
2import { test } from 'tap';
3
4test('filename cannot be non-null/non-string', async ({ throws }) => {
5 throws(() => new Piscina(({
6 filename: 12
7 }) as any), /options.filename must be a string or null/);
8});
9
10test('name cannot be non-null/non-string', async ({ throws }) => {
11 throws(() => new Piscina(({
12 name: 12
13 }) as any), /options.name must be a string or null/);
14});
15
16test('minThreads must be non-negative integer', async ({ throws }) => {
17 throws(() => new Piscina(({
18 minThreads: -1
19 }) as any), /options.minThreads must be a non-negative integer/);
20
21 throws(() => new Piscina(({
22 minThreads: 'string'
23 }) as any), /options.minThreads must be a non-negative integer/);
24});
25
26test('maxThreads must be positive integer', async ({ throws }) => {
27 throws(() => new Piscina(({
28 maxThreads: -1
29 }) as any), /options.maxThreads must be a positive integer/);
30
31 throws(() => new Piscina(({
32 maxThreads: 0
33 }) as any), /options.maxThreads must be a positive integer/);
34
35 throws(() => new Piscina(({
36 maxThreads: 'string'
37 }) as any), /options.maxThreads must be a positive integer/);
38});
39
40test('concurrentTasksPerWorker must be positive integer', async ({ throws }) => {
41 throws(() => new Piscina(({
42 concurrentTasksPerWorker: -1
43 }) as any), /options.concurrentTasksPerWorker must be a positive integer/);
44
45 throws(() => new Piscina(({
46 concurrentTasksPerWorker: 0
47 }) as any), /options.concurrentTasksPerWorker must be a positive integer/);
48
49 throws(() => new Piscina(({
50 concurrentTasksPerWorker: 'string'
51 }) as any), /options.concurrentTasksPerWorker must be a positive integer/);
52});
53
54test('idleTimeout must be non-negative integer', async ({ throws }) => {
55 throws(() => new Piscina(({
56 idleTimeout: -1
57 }) as any), /options.idleTimeout must be a non-negative integer/);
58
59 throws(() => new Piscina(({
60 idleTimeout: 'string'
61 }) as any), /options.idleTimeout must be a non-negative integer/);
62});
63
64test('maxQueue must be non-negative integer', async ({ throws, equal }) => {
65 throws(() => new Piscina(({
66 maxQueue: -1
67 }) as any), /options.maxQueue must be a non-negative integer/);
68
69 throws(() => new Piscina(({
70 maxQueue: 'string'
71 }) as any), /options.maxQueue must be a non-negative integer/);
72
73 const p = new Piscina({ maxQueue: 'auto', maxThreads: 2 });
74 equal(p.options.maxQueue, 4);
75});
76
77test('useAtomics must be a boolean', async ({ throws }) => {
78 throws(() => new Piscina(({
79 useAtomics: -1
80 }) as any), /options.useAtomics must be a boolean/);
81
82 throws(() => new Piscina(({
83 useAtomics: 'string'
84 }) as any), /options.useAtomics must be a boolean/);
85});
86
87test('resourceLimits must be an object', async ({ throws }) => {
88 throws(() => new Piscina(({
89 resourceLimits: 0
90 }) as any), /options.resourceLimits must be an object/);
91});
92
93test('taskQueue must be a TaskQueue object', async ({ throws }) => {
94 throws(() => new Piscina(({
95 taskQueue: 0
96 }) as any), /options.taskQueue must be a TaskQueue object/);
97 throws(() => new Piscina(({
98 taskQueue: 'test'
99 }) as any), /options.taskQueue must be a TaskQueue object/);
100 throws(() => new Piscina(({
101 taskQueue: null
102 }) as any), /options.taskQueue must be a TaskQueue object/);
103 throws(() => new Piscina(({
104 taskQueue: new Date()
105 }) as any), /options.taskQueue must be a TaskQueue object/);
106 throws(() => new Piscina(({
107 taskQueue: { } as any
108 }) as any), /options.taskQueue must be a TaskQueue object/);
109});
110
111test('niceIncrement must be non-negative integer', async ({ throws }) => {
112 throws(() => new Piscina(({
113 niceIncrement: -1
114 }) as any), /options.niceIncrement must be a non-negative integer/);
115
116 throws(() => new Piscina(({
117 niceIncrement: 'string'
118 }) as any), /options.niceIncrement must be a non-negative integer/);
119});
120
121test('trackUnmanagedFds must be a boolean', async ({ throws }) => {
122 throws(() => new Piscina(({
123 trackUnmanagedFds: -1
124 }) as any), /options.trackUnmanagedFds must be a boolean/);
125
126 throws(() => new Piscina(({
127 trackUnmanagedFds: 'string'
128 }) as any), /options.trackUnmanagedFds must be a boolean/);
129});
Note: See TracBrowser for help on using the repository browser.