Skip to content

Commit

Permalink
tests: fix backpressure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Mar 20, 2018
1 parent cd957aa commit d7bb81b
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions test/compression.js
Expand Up @@ -158,13 +158,15 @@ describe('compression()', function () {
it('should back-pressure when compressed', function (done) {
var buf
var client
var drained = false
var drained = []
var resp
var server = createServer({ threshold: 0 }, function (req, res) {
resp = res

res.on('drain', function () {
drained = true
drained.push('first')
})

res.setHeader('Content-Type', 'text/plain')
res.write('start')
pressure()
Expand All @@ -179,7 +181,11 @@ describe('compression()', function () {

function complete () {
if (--wait !== 0) return
assert.ok(drained)
assert.deepEqual(drained, [
'first',
'second',
'true'
])
done()
}

Expand All @@ -191,9 +197,11 @@ describe('compression()', function () {
}

resp.on('drain', function () {
resp.write('end')
drained.push('second')
drained.push(String(resp.write('end')))
resp.end()
})

resp.on('finish', complete)
client.resume()
}
Expand All @@ -214,13 +222,15 @@ describe('compression()', function () {
it('should back-pressure when uncompressed', function (done) {
var buf
var client
var drained = false
var drained = []
var resp
var server = createServer({ filter: function () { return false } }, function (req, res) {
resp = res

res.on('drain', function () {
drained = true
drained.push('first')
})

res.setHeader('Content-Type', 'text/plain')
res.write('start')
pressure()
Expand All @@ -235,7 +245,11 @@ describe('compression()', function () {

function complete () {
if (--wait !== 0) return
assert.ok(drained)
assert.deepEqual(drained, [
'first',
'second',
'true'
])
done()
}

Expand All @@ -247,7 +261,8 @@ describe('compression()', function () {
}

resp.on('drain', function () {
resp.write('end')
drained.push('second')
drained.push(String(resp.write('end')))
resp.end()
})
resp.on('finish', complete)
Expand Down

0 comments on commit d7bb81b

Please sign in to comment.