Skip to content

Commit

Permalink
Test that scheduler eventually returns a consumer when all consumers …
Browse files Browse the repository at this point in the history
…are in use
  • Loading branch information
alanshaw committed Jun 15, 2013
1 parent ec1cdb1 commit 07059ab
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/round-robin.js
Expand Up @@ -424,4 +424,43 @@ describe("RoundRobin", function () {
})
})
})

it("should eventually return a consumer when all consumers are in use", function (done) {

var scheduler = new RoundRobin({
spinUp: function (cb) {
var consumer = {returnCount: 0}
cb(null, consumer)
},
spinDown: function (consumer, cb) {
cb()
},
maxUp: 2
})

// Create 2 consumers
scheduler.get(function (er, c1) {
assert.ifError(er)
assert(c1)

scheduler.get(function (er, c2) {
assert.ifError(er)
assert(c2)

var c1Returned = false

// Because c1 and c2 have not been returned, c3 should not be "got" until c1 or c2 are returned
scheduler.get(function (er, c3) {
assert(c1Returned)
assert.strictEqual(c1, c3)
done()
})

setTimeout(function () {
c1Returned = true
scheduler.ret(c1)
}, 500)
})
})
})
})

0 comments on commit 07059ab

Please sign in to comment.