2021-12-22 00:24:07 +09:00
|
|
|
import { join } from 'path'
|
|
|
|
import { Worker } from 'worker_threads'
|
|
|
|
|
|
|
|
import test from 'ava'
|
|
|
|
|
2022-03-05 15:14:32 +09:00
|
|
|
import { Animal, Kind, DEFAULT_COST } from '../index'
|
2021-12-22 00:24:07 +09:00
|
|
|
|
2022-10-31 22:13:11 +09:00
|
|
|
const t =
|
|
|
|
process.arch === 'arm64' && process.platform === 'linux' ? test.skip : test
|
|
|
|
|
|
|
|
t('should be able to require in worker thread', async (t) => {
|
2022-03-05 15:14:32 +09:00
|
|
|
await Promise.all(
|
|
|
|
Array.from({ length: 100 }).map(() => {
|
|
|
|
const w = new Worker(join(__dirname, 'worker.js'))
|
|
|
|
return new Promise<void>((resolve, reject) => {
|
|
|
|
w.on('message', (msg) => {
|
|
|
|
t.is(msg, Animal.withKind(Kind.Cat).whoami() + DEFAULT_COST)
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
w.on('error', (err) => {
|
|
|
|
reject(err)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.then(() => w.terminate())
|
|
|
|
.then(() => {
|
|
|
|
t.pass()
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
)
|
2021-12-22 00:24:07 +09:00
|
|
|
})
|