Skip to content

Commit

Permalink
fix: do not show warnings when workers >= 10
Browse files Browse the repository at this point in the history
  • Loading branch information
simoneb committed Mar 3, 2021
1 parent f8b598e commit 2d17ef0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/progressTracker.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const defaults = {
renderResultsTable: true,
renderLatencyTable: false
}
let spinner

function track (instance, opts) {
if (!instance) {
Expand All @@ -34,7 +35,6 @@ function track (instance, opts) {
let durationProgressBar
let amountProgressBar
let addedListeners = false
let spinner

instance.on('start', () => {
if (opts.renderProgressBar && isMainThread) {
Expand Down Expand Up @@ -79,7 +79,9 @@ function track (instance, opts) {
})

function showSpinner () {
spinner = ora('running...')
if (!spinner) {
spinner = ora('running...')
}
spinner.start()
}

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"busboy": "^0.3.1",
"pre-commit": "^1.1.2",
"proxyquire": "^2.1.3",
"sinon": "^9.2.4",
"split2": "^3.2.2",
"standard": "^16.0.3",
"tap": "^14.10.8"
Expand Down
25 changes: 25 additions & 0 deletions test/progressTracker.test.stub.js → test/progressTracker.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

const helper = require('./helper')
const test = require('tap').test
const { defaultMaxListeners } = require('events')
const sinon = require('sinon')
const progressTracker = require('../lib/progressTracker')
const autocannon = require('../autocannon')
const { hasWorkerSupport } = require('../lib/util')

test('progress tracker should throw if no instance is provided', t => {
t.plan(1)
try {
Expand Down Expand Up @@ -94,3 +98,24 @@ test('should log resets', t => {
})
t.pass()
})

test(`should not emit warnings when using >= ${defaultMaxListeners} workers`, { skip: !hasWorkerSupport }, t => {
const server = helper.startServer()

const instance = autocannon({
url: `http://localhost:${server.address().port}`,
workers: defaultMaxListeners,
duration: 1
})

setTimeout(() => {
instance.stop()
t.false(emitWarningSpy.called)
emitWarningSpy.restore()
t.end()
}, 2000)

const emitWarningSpy = sinon.spy(process, 'emitWarning')

autocannon.track(instance)
})

0 comments on commit 2d17ef0

Please sign in to comment.