I'm having problems writing tests for my service due to not knowing when a socket has really been closed and thus the port can be reused (so that I can bring up new instances over and over again in my tests)
The following coffeescript/mocha test illustrates the problem
describe 'When re-using ports', ->
it 'should be able to bind to a new 0MQ socket immediately after closing an old one', (done) ->
socket1 = zmq.socket 'pub'
socket1.setsockopt 'linger', 0
socket1.bind 'tcp://*:8000', (error) =>
expect(error).to.not.be.ok
socket1.close()
socket2 = zmq.socket 'pub'
socket2.setsockopt 'linger', 0
socket2.bind 'tcp://*:8000', (error) =>
expect(error).to.not.be.ok
socket2.close()
done()
which results in the following error
Fatal error: expected [Error: Address already in use] to be falsy
I can workaround it with a timeout (which is a bit arbitrary as slower machines may take longer, plus it will slow my tests down if they all contain timeouts) or by cycling through ports, which is likely to be a pain to manage unless I write a library to manage it (which seems like overkill)
Ideally I would like an event once the socket has really been closed so that I can design my tests to run fast and look sensible.
Apologies if I missed something in the API
I'm having problems writing tests for my service due to not knowing when a socket has really been closed and thus the port can be reused (so that I can bring up new instances over and over again in my tests)
The following coffeescript/mocha test illustrates the problem
which results in the following error
I can workaround it with a timeout (which is a bit arbitrary as slower machines may take longer, plus it will slow my tests down if they all contain timeouts) or by cycling through ports, which is likely to be a pain to manage unless I write a library to manage it (which seems like overkill)
Ideally I would like an event once the socket has really been closed so that I can design my tests to run fast and look sensible.
Apologies if I missed something in the API