Skip to content

Commit

Permalink
#16 enable back worker pool testing, based on dynamic host config
Browse files Browse the repository at this point in the history
  • Loading branch information
wilk committed Nov 13, 2018
1 parent 99deb44 commit b06711c
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions __tests__/worker-pool.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { job, start, stop } from '../src/job'
import os from 'os'

const MAX_THREADS = os.cpus().length

beforeAll(async () => await start())
afterAll(async () => await stop())

describe('Worker Pool Testing', () => {
// todo: find a better way to test worker pool
xit('should execute at most 4 jobs at a time', async () => {
it(`should execute at most ${MAX_THREADS} jobs at a time`, async () => {
let error
let diff

const task = () => new Promise(resolve => setTimeout(() => resolve(), 20))

try {
const start = Date.now()
await Promise.all([job(task), job(task), job(task), job(task), job(task)])
const promises = []
for (let i = 0; i < MAX_THREADS; i++) promises.push(job(task))
promises.push(job(task))
await Promise.all(promises)
diff = Date.now() - start
} catch (err) {
error = err
Expand Down

0 comments on commit b06711c

Please sign in to comment.