mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-13 01:01:23 +00:00
fix: start and stop error callback (#316)
* fix: ensure start and stop callbacks are called
This commit is contained in:
@ -26,6 +26,7 @@ describe('libp2p state machine (fsm)', () => {
|
||||
})
|
||||
afterEach(() => {
|
||||
node.removeAllListeners()
|
||||
sinon.restore()
|
||||
})
|
||||
after((done) => {
|
||||
node.stop(done)
|
||||
@ -64,6 +65,23 @@ describe('libp2p state machine (fsm)', () => {
|
||||
node.start()
|
||||
})
|
||||
|
||||
it('should callback with an error when it occurs on stop', (done) => {
|
||||
const error = new Error('some error starting')
|
||||
node.once('start', () => {
|
||||
node.once('error', (err) => {
|
||||
expect(err).to.eql(error).mark()
|
||||
})
|
||||
node.stop((err) => {
|
||||
expect(err).to.eql(error).mark()
|
||||
})
|
||||
})
|
||||
|
||||
expect(2).checks(done)
|
||||
|
||||
sinon.stub(node._switch, 'stop').callsArgWith(0, error)
|
||||
node.start()
|
||||
})
|
||||
|
||||
it('should noop when starting a started node', (done) => {
|
||||
node.once('start', () => {
|
||||
node.state.on('STARTING', () => {
|
||||
@ -116,9 +134,11 @@ describe('libp2p state machine (fsm)', () => {
|
||||
throw new Error('should not start')
|
||||
})
|
||||
|
||||
expect(2).checks(done)
|
||||
expect(3).checks(done)
|
||||
|
||||
node.start()
|
||||
node.start((err) => {
|
||||
expect(err).to.eql(error).mark()
|
||||
})
|
||||
})
|
||||
|
||||
it('should not dial when the node is stopped', (done) => {
|
||||
|
Reference in New Issue
Block a user