mirror of
https://github.com/fluencelabs/js-libp2p-interfaces
synced 2025-04-24 23:12:23 +00:00
fix: improve the close test
This commit is contained in:
parent
f8569f2586
commit
d9c868195a
@ -35,8 +35,6 @@ module.exports = (common) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('closing underlying socket closes streams (tcp)', (done) => {
|
it('closing underlying socket closes streams (tcp)', (done) => {
|
||||||
expect(2).checks(done)
|
|
||||||
|
|
||||||
const tcp = new Tcp()
|
const tcp = new Tcp()
|
||||||
const tcpListener = tcp.createListener((conn) => {
|
const tcpListener = tcp.createListener((conn) => {
|
||||||
const listener = muxer.listener(conn)
|
const listener = muxer.listener(conn)
|
||||||
@ -45,26 +43,38 @@ module.exports = (common) => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
tcpListener.listen(mh, () => {
|
// Wait for the streams to open
|
||||||
const dialerConn = tcp.dial(mh, tcpListener.close)
|
expect(2).checks(() => {
|
||||||
|
// Once everything is closed, we're done
|
||||||
const dialerMuxer = muxer.dialer(dialerConn)
|
expect(3).checks(done)
|
||||||
const s1 = dialerMuxer.newStream(() => {
|
tcpListener.close((err) => {
|
||||||
pull(
|
expect(err).to.not.exist.mark()
|
||||||
s1,
|
|
||||||
pull.onEnd((err) => {
|
|
||||||
expect(err).to.exist.mark()
|
|
||||||
})
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
|
|
||||||
const s2 = dialerMuxer.newStream(() => {
|
tcpListener.listen(mh, () => {
|
||||||
pull(
|
const dialerConn = tcp.dial(mh, () => {
|
||||||
s2,
|
|
||||||
pull.onEnd((err) => {
|
const dialerMuxer = muxer.dialer(dialerConn)
|
||||||
expect(err).to.exist.mark()
|
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((err) => {
|
||||||
|
expect(err).to.not.exist.mark()
|
||||||
|
pull(
|
||||||
|
s2,
|
||||||
|
pull.onEnd((err) => {
|
||||||
|
expect(err).to.exist.mark()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user