source: trip-planner-front/node_modules/piscina/test/test-resourcelimits.ts

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

initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import Piscina from '..';
2import { test } from 'tap';
3import { resolve } from 'path';
4
5test('resourceLimits causes task to reject', async ({ equal, rejects }) => {
6 const worker = new Piscina({
7 filename: resolve(__dirname, 'fixtures/resource-limits.js'),
8 resourceLimits: {
9 maxOldGenerationSizeMb: 16,
10 maxYoungGenerationSizeMb: 4,
11 codeRangeSizeMb: 16
12 }
13 });
14 worker.on('error', () => {
15 // Ignore any additional errors that may occur.
16 // This may happen because when the Worker is
17 // killed a new worker is created that may hit
18 // the memory limits immediately. When that
19 // happens, there is no associated Promise to
20 // reject so we emit an error event instead.
21 // We don't care so much about that here. We
22 // could potentially avoid the issue by setting
23 // higher limits above but rather than try to
24 // guess at limits that may work consistently,
25 // let's just ignore the additional error for
26 // now.
27 });
28 const limits : any = worker.options.resourceLimits;
29 equal(limits.maxOldGenerationSizeMb, 16);
30 equal(limits.maxYoungGenerationSizeMb, 4);
31 equal(limits.codeRangeSizeMb, 16);
32 rejects(worker.runTask(null),
33 /Worker terminated due to reaching memory limit: JS heap out of memory/);
34});
Note: See TracBrowser for help on using the repository browser.