Skip to content
This repository was archived by the owner on Apr 29, 2020. It is now read-only.

fixes socket hang by adding timeout to close #28

Merged
merged 1 commit into from
May 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const rawPeer = require('./test/peer.json')
const id = Id.createFromPrivKey(rawPeer.privKey)

gulp.task('libnode:start', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
const peer = new Peer(id)
peer.multiaddr.add(mh)

Expand All @@ -25,7 +25,9 @@ gulp.task('libnode:start', (done) => {
})

gulp.task('libnode:stop', (done) => {
node.swarm.close(done)
setTimeout(() => {
node.swarm.close(done)
}, 2000)
})

gulp.task('test:browser:before', ['libnode:start'])
Expand Down
30 changes: 16 additions & 14 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,21 @@ const id = Id.createFromPrivKey(rawPeer.privKey)
describe('libp2p-ipfs-browser', function () {
this.timeout(10000)
let node
let peer

before((done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
peer = new Peer(id)
peer.multiaddr.add(mh)
done()
})

it('start', (done) => {
node = new Node()
node.start(done)
})

it('echo', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
const peer = new Peer(id)
peer.multiaddr.add(mh)

const message = 'Hello World!'
node.swarm.dial(peer, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist
Expand All @@ -40,18 +44,16 @@ describe('libp2p-ipfs-browser', function () {

describe('stress', () => {
it('one big write', (done) => {
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
const peer = new Peer(id)
peer.multiaddr.add(mh)

const message = new Buffer(1000000).fill('a').toString('hex')

node.swarm.dial(peer, '/echo/1.0.0', (err, conn) => {
expect(err).to.not.exist

conn.write(message)
conn.write('STOP')

let result = ''

conn.on('data', (data) => {
if (data.toString() === 'STOP') {
conn.end()
Expand Down Expand Up @@ -83,14 +85,14 @@ describe('libp2p-ipfs-browser', function () {
expected += `${counter} `
}

setTimeout(() => {
while (++counter < 20000) {
conn.write(`${counter} `)
expected += `${counter} `
}
while (++counter < 20000) {
conn.write(`${counter} `)
expected += `${counter} `
}

setTimeout(() => {
conn.write('STOP')
}, 1000)
}, 2000)

let result = ''
conn.on('data', (data) => {
Expand Down