forked from piscinajs/piscina
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnice.ts
49 lines (41 loc) · 1.59 KB
/
nice.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Piscina from '..';
import { getCurrentProcessPriority, WindowsThreadPriority } from '@napi-rs/nice';
import { resolve } from 'path';
import { test } from 'tap';
test('niceness - Linux:', { skip: process.platform !== 'linux' }, scope => {
scope.plan(2);
scope.test('can set niceness for threads on Linux', async ({ equal }) => {
const worker = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js'),
niceIncrement: 5
});
// ts-ignore because the dependency is not installed on Windows.
// @ts-ignore
const currentNiceness = getCurrentProcessPriority();
const result = await worker.run('require("@napi-rs/nice").getCurrentProcessPriority()');
// niceness is capped to 19 on Linux.
const expected = Math.min(currentNiceness + 5, 19);
equal(result, expected);
});
scope.test('setting niceness never does anything bad', async ({ equal }) => {
const worker = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js'),
niceIncrement: 5
});
const result = await worker.run('42');
equal(result, 42);
});
});
test('niceness - Windows', {
skip: process.platform !== 'win32'
}, scope => {
scope.plan(1);
scope.test('can set niceness for threads on Windows', async ({ equal }) => {
const worker = new Piscina({
filename: resolve(__dirname, 'fixtures/eval.js'),
niceIncrement: WindowsThreadPriority.ThreadPriorityAboveNormal
});
const result = await worker.run('require("@napi-rs/nice").getCurrentProcessPriority()');
equal(result, WindowsThreadPriority.ThreadPriorityAboveNormal);
});
});