Skip to content

Commit

Permalink
test runtime UV_THREADPOOL_SIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
toyobayashi committed Aug 25, 2023
1 parent 523e4f9 commit e92ad8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
10 changes: 3 additions & 7 deletions packages/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ else()
endif()

if(DEFINED ENV{UV_THREADPOOL_SIZE})
set(EMNAPI_WORKER_POOL_SIZE $ENV{UV_THREADPOOL_SIZE})
set(UV_THREADPOOL_SIZE $ENV{UV_THREADPOOL_SIZE})
else()
set(EMNAPI_WORKER_POOL_SIZE "4")
set(UV_THREADPOOL_SIZE "4")
endif()

math(EXPR PTHREAD_POOL_SIZE "${EMNAPI_WORKER_POOL_SIZE} * 4")
math(EXPR PTHREAD_POOL_SIZE "${UV_THREADPOOL_SIZE} * 4")

if(IS_WASM)
include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../emnapi/include")
Expand Down Expand Up @@ -257,11 +257,7 @@ add_test("tsfn2" "./tsfn2/binding.c" OFF ON "")

if((NOT IS_WASM) OR IS_EMSCRIPTEN OR IS_WASI_THREADS)
add_test("string_mt" "./string/binding.c;./string/test_null.c" ON ON "")
if(IS_EMSCRIPTEN)
add_test("pool" "./pool/binding.c" OFF ON "--pre-js=${CMAKE_CURRENT_SOURCE_DIR}/pool/pre.js")
else()
add_test("pool" "./pool/binding.c" OFF ON "")
endif()
add_test("tsfn" "./tsfn/binding.c" OFF ON "")
add_test("async_cleanup_hook" "./async_cleanup_hook/binding.c" OFF ON "")
add_test("uv_threadpool_size" "./uv_threadpool_size/binding.c" OFF ON "")
Expand Down
5 changes: 4 additions & 1 deletion packages/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ function getEntry (targetName) {

exports.getEntry = getEntry

const RUNTIME_UV_THREADPOOL_SIZE = ('UV_THREADPOOL_SIZE' in process.env) ? Number(process.env.UV_THREADPOOL_SIZE) : 4

function loadPath (request, options) {
try {
if (process.env.EMNAPI_TEST_NATIVE) {
Expand Down Expand Up @@ -74,7 +76,7 @@ function loadPath (request, options) {
const { createNapiModule, loadNapiModule } = require('@emnapi/core')
const napiModule = createNapiModule({
context,
asyncWorkPoolSize: ('UV_THREADPOOL_SIZE' in process.env) ? Number(process.env.UV_THREADPOOL_SIZE) : 4,
asyncWorkPoolSize: RUNTIME_UV_THREADPOOL_SIZE,
onCreateWorker () {
return new Worker(join(__dirname, './worker.js'), {
env: process.env
Expand Down Expand Up @@ -127,6 +129,7 @@ function loadPath (request, options) {
try {
resolve(Module.emnapiInit({
context,
asyncWorkPoolSize: RUNTIME_UV_THREADPOOL_SIZE,
...(options || {})
}))
} catch (err) {
Expand Down

0 comments on commit e92ad8f

Please sign in to comment.