Refactor of test-case

This commit is contained in:
Victor Bjelkholm 2017-01-19 14:07:37 +01:00
parent 148fcde17e
commit 127be58017

View File

@ -14,13 +14,11 @@ const multiaddr = require('multiaddr')
const mh = multiaddr('/ip4/127.0.0.1/tcp/10000') const mh = multiaddr('/ip4/127.0.0.1/tcp/10000')
function closeAndWait (stream) { function closeAndWait (stream, callback) {
pull( pull(
pull.empty(), pull.empty(),
stream, stream,
pull.onEnd((err) => { pull.onEnd(() => callback())
expect(err).to.not.exist.mark()
})
) )
} }
@ -36,38 +34,37 @@ module.exports = (common) => {
}) })
}) })
it('closing underlying closes streams (tcp)', (done) => { it('closing underlying socket closes streams (tcp)', (done) => {
expect(2).checks(done) expect(2).checks(done)
const tcp = new Tcp() const tcp = new Tcp()
const tcpListener = tcp.createListener((socket) => { const tcpListener = tcp.createListener((conn) => {
const listener = muxer.listener(socket) const listener = muxer.listener(conn)
listener.on('stream', (stream) => { listener.on('stream', (stream) => {
pull(stream, stream) pull(stream, stream)
}) })
}) })
tcpListener.listen(mh, () => { tcpListener.listen(mh, () => {
const dialer = muxer.dialer(tcp.dial(mh, () => { const dialerConn = tcp.dial(mh, tcpListener.close)
tcpListener.close()
}))
const s1 = dialer.newStream(() => { const dialerMuxer = muxer.dialer(dialerConn)
const s1 = dialerMuxer.newStream(() => {
pull( pull(
s1, s1,
pull.onEnd((err) => { pull.onEnd((err) => {
expect(err).to.exist.mark() expect(err).to.exist.mark()
}) })
) )
})
const s2 = dialer.newStream(() => { const s2 = dialerMuxer.newStream(() => {
pull( pull(
s2, s2,
pull.onEnd((err) => { pull.onEnd((err) => {
expect(err).to.exist.mark() expect(err).to.exist.mark()
}) })
) )
})
}) })
}) })
}) })
@ -91,8 +88,10 @@ module.exports = (common) => {
} }
conns.forEach((conn, i) => { conns.forEach((conn, i) => {
if (i === 2) { if (i === 1) {
closeAndWait(conn) closeAndWait(conn, (err) => {
expect(err).to.not.exist.mark()
})
} else { } else {
pull( pull(
conn, conn,