Skip to content
This repository has been archived by the owner on Mar 11, 2020. It is now read-only.

Commit

Permalink
fix: improve the close test
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun committed Nov 9, 2018
1 parent f8569f2 commit d9c8681
Showing 1 changed file with 29 additions and 19 deletions.
48 changes: 29 additions & 19 deletions src/close-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ module.exports = (common) => {
})

it('closing underlying socket closes streams (tcp)', (done) => {
expect(2).checks(done)

const tcp = new Tcp()
const tcpListener = tcp.createListener((conn) => {
const listener = muxer.listener(conn)
Expand All @@ -45,26 +43,38 @@ module.exports = (common) => {
})
})

// Wait for the streams to open
expect(2).checks(() => {
// Once everything is closed, we're done
expect(3).checks(done)
tcpListener.close((err) => {
expect(err).to.not.exist.mark()
})
})

tcpListener.listen(mh, () => {
const dialerConn = tcp.dial(mh, tcpListener.close)
const dialerConn = tcp.dial(mh, () => {

const dialerMuxer = muxer.dialer(dialerConn)
const s1 = dialerMuxer.newStream(() => {
pull(
s1,
pull.onEnd((err) => {
expect(err).to.exist.mark()
})
)
})
const dialerMuxer = muxer.dialer(dialerConn)
const s1 = dialerMuxer.newStream((err) => {
expect(err).to.not.exist.mark()
pull(
s1,
pull.onEnd((err) => {
expect(err).to.exist.mark()
})
)
})

const s2 = dialerMuxer.newStream(() => {
pull(
s2,
pull.onEnd((err) => {
expect(err).to.exist.mark()
})
)
const s2 = dialerMuxer.newStream((err) => {
expect(err).to.not.exist.mark()
pull(
s2,
pull.onEnd((err) => {
expect(err).to.exist.mark()
})
)
})
})
})
})
Expand Down

0 comments on commit d9c8681

Please sign in to comment.