From f1734b4e0996fd94c9674578e802d7ae95cdc507 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 17 Aug 2023 10:18:53 -0400 Subject: [PATCH] test: improve `UV_THREADPOOL_SIZE` tests on `.env` --- test/fixtures/dotenv/uv-threadpool.env | 1 + .../test_uv_threadpool_size/node-options.js | 31 +++++++++++++++++++ test/parallel/test-dotenv-node-options.js | 13 -------- 3 files changed, 32 insertions(+), 13 deletions(-) create mode 100644 test/fixtures/dotenv/uv-threadpool.env create mode 100644 test/node-api/test_uv_threadpool_size/node-options.js diff --git a/test/fixtures/dotenv/uv-threadpool.env b/test/fixtures/dotenv/uv-threadpool.env new file mode 100644 index 00000000000000..462463da7b6f54 --- /dev/null +++ b/test/fixtures/dotenv/uv-threadpool.env @@ -0,0 +1 @@ +UV_THREADPOOL_SIZE=4 diff --git a/test/node-api/test_uv_threadpool_size/node-options.js b/test/node-api/test_uv_threadpool_size/node-options.js new file mode 100644 index 00000000000000..40610274acce4c --- /dev/null +++ b/test/node-api/test_uv_threadpool_size/node-options.js @@ -0,0 +1,31 @@ +'use strict'; + +const common = require('../../common'); +const assert = require('assert'); +const path = require('path'); +const { spawnSync } = require('child_process'); + +if (process.config.variables.node_without_node_options) { + common.skip('missing NODE_OPTIONS support'); +} + +const uvThreadPoolPath = '../../fixtures/dotenv/uv-threadpool.env'; + +// Should update UV_THREADPOOL_SIZE +let filePath = path.join(__dirname, `./build/${common.buildType}/test_uv_threadpool_size`); +if (common.isWindows) { + filePath = filePath.replaceAll('\\', '\\\\'); +} +const code = ` + const { test } = require('${filePath}'); + const size = parseInt(process.env.UV_THREADPOOL_SIZE, 10); + require('assert').strictEqual(size, 4); + test(size); + `.trim(); +const child = spawnSync( + process.execPath, + [ `--env-file=${uvThreadPoolPath}`, '--eval', code ], + { cwd: __dirname, encoding: 'utf-8' }, +); +assert.strictEqual(child.stderr, ''); +assert.strictEqual(child.status, 0); diff --git a/test/parallel/test-dotenv-node-options.js b/test/parallel/test-dotenv-node-options.js index d35d1eeaeb33db..8c53616fd17d23 100644 --- a/test/parallel/test-dotenv-node-options.js +++ b/test/parallel/test-dotenv-node-options.js @@ -62,17 +62,4 @@ describe('.env supports NODE_OPTIONS', () => { assert.strictEqual(child.code, 0); }); - it('should update UV_THREADPOOL_SIZE', async () => { - const code = ` - require('assert').strictEqual(process.env.UV_THREADPOOL_SIZE, '5') - `.trim(); - const child = await common.spawnPromisified( - process.execPath, - [ `--env-file=${relativePath}`, '--eval', code ], - { cwd: __dirname }, - ); - assert.strictEqual(child.stderr, ''); - assert.strictEqual(child.code, 0); - }); - });