Skip to content

Commit

Permalink
cover github issue in test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
StarpTech committed Feb 19, 2017
1 parent 8391785 commit 99ed1ce
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions test/hemera/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,87 @@ describe('public interface', function () {
})
})

describe('Timeouts', function () {
var PORT = 6242
var flags = ['--user', 'derek', '--pass', 'foobar']
var authUrl = 'nats://derek:foobar@localhost:' + PORT
var server

// Start up our own nats-server
before(function (done) {
server = HemeraTestsuite.start_server(PORT, flags, done)
})

// Shutdown our server after we are done
after(function () {
server.kill()
})

it('Issue #39 - Should get the correct results even when the answers are responded after a timeout', function (done) {
const nats = require('nats').connect(authUrl)

const hemera = new Hemera(nats)

let aError = 0
let bError = 0
let aResult = 0
let bResult = 0

hemera.ready(() => {
hemera.add({
topic: 'test',
cmd: 'A'
}, (resp, cb) => {
setTimeout(() => {
cb(null, {
ok: true
})
}, 250)
})

hemera.add({
topic: 'test',
cmd: 'B'
}, function (resp, cb) {
this.act({
topic: 'test',
cmd: 'A',
timeout$: 100
}, function (err, res) {
if (err) {
aError++
cb(err)
} else {
aResult++
cb(null, res)
}
})
})

hemera.act({
topic: 'test',
cmd: 'B',
timeout$: 150
}, function (err, resp) {
if (err) {
bError++
} else {
bResult++
}
})

setTimeout(() => {
expect(aError).to.be.equals(1)
expect(aResult).to.be.equals(1)
expect(bError).to.be.equals(1)
expect(bResult).to.be.equals(1)
hemera.close()
done()
}, 300)
})
})
})

describe('Timeouts', function () {
var PORT = 6242
var flags = ['--user', 'derek', '--pass', 'foobar']
Expand Down

0 comments on commit 99ed1ce

Please sign in to comment.