Skip to content
This repository has been archived by the owner on Jun 26, 2023. It is now read-only.

Commit

Permalink
fix(connection): tracks streams properly (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobheun authored Feb 4, 2020
1 parent f6871af commit 5c88d77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/connection/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ class Connection {

const { stream, protocol } = await this._newStream(protocols)

this.addStream(stream, protocol)
this.addStream(stream, { protocol })

return {
stream,
Expand Down
13 changes: 13 additions & 0 deletions src/connection/tests/connection.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,19 @@ module.exports = (test) => {
expect(connection.stat.status).to.equal(Status.CLOSED)
})

it('should properly track streams', async () => {
// Open stream
const protocol = '/echo/0.0.1'
const { stream } = await connection.newStream(protocol)
const trackedStream = connection.registry.get(stream.id)
expect(trackedStream).to.have.property('protocol', protocol)

// Close stream
await stream.close()

expect(connection.registry.get(stream.id)).to.not.exist()
})

it('should support a proxy on the timeline', async () => {
sinon.spy(proxyHandler, 'set')
expect(connection.stat.timeline.close).to.not.exist()
Expand Down
8 changes: 6 additions & 2 deletions test/connection/compliance.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('compliance tests', () => {
const openStreams = []
let streamId = 0

return new Connection({
const connection = new Connection({
localPeer,
remotePeer,
localAddr,
Expand All @@ -43,7 +43,10 @@ describe('compliance tests', () => {
const id = streamId++
const stream = pair()

stream.close = () => stream.sink([])
stream.close = async () => {
await stream.sink([])
connection.removeStream(stream.id)
}
stream.id = id

openStreams.push(stream)
Expand All @@ -57,6 +60,7 @@ describe('compliance tests', () => {
getStreams: () => openStreams,
...properties
})
return connection
},
async teardown () {
// cleanup resources created by setup()
Expand Down

0 comments on commit 5c88d77

Please sign in to comment.