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 52fa9c1
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,11 @@ describe('compression()', function () {
var resp
var server = createServer({ threshold: 0 }, function (req, res) {
resp = res

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

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

function complete () {
if (--wait !== 0) return
assert.ok(drained)
done()
}

function pressure () {
if (!buf || !resp || !client) return

assert.ok(!drained)

while (resp.write(buf) !== false) {
resp.flush()
}

resp.on('drain', function () {
resp.write('end')
assert.ok(resp.write('end'))
resp.end()
})

resp.on('finish', complete)
client.resume()
}
Expand All @@ -218,9 +222,11 @@ describe('compression()', function () {
var resp
var server = createServer({ filter: function () { return false } }, function (req, res) {
resp = res

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

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

function complete () {
if (--wait !== 0) return
assert.ok(drained)
done()
}

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

resp.on('drain', function () {
resp.write('end')
assert.ok(drained)
assert.ok(resp.write('end'))
resp.end()
})
resp.on('finish', complete)
Expand Down

0 comments on commit 52fa9c1

Please sign in to comment.