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

Commit baaa828

Browse files
committed
Merge pull request #28 from ipfs/fix/socket-hang
fixes socket hang by adding timeout to close
2 parents 651a5b3 + 3b8e0e3 commit baaa828

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

gulpfile.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const rawPeer = require('./test/peer.json')
1111
const id = Id.createFromPrivKey(rawPeer.privKey)
1212

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

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

2727
gulp.task('libnode:stop', (done) => {
28-
node.swarm.close(done)
28+
setTimeout(() => {
29+
node.swarm.close(done)
30+
}, 2000)
2931
})
3032

3133
gulp.task('test:browser:before', ['libnode:start'])

test/index.spec.js

+16-14
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,21 @@ const id = Id.createFromPrivKey(rawPeer.privKey)
1313
describe('libp2p-ipfs-browser', function () {
1414
this.timeout(10000)
1515
let node
16+
let peer
17+
18+
before((done) => {
19+
const mh = multiaddr('/ip4/127.0.0.1/tcp/9200/ws')
20+
peer = new Peer(id)
21+
peer.multiaddr.add(mh)
22+
done()
23+
})
1624

1725
it('start', (done) => {
1826
node = new Node()
1927
node.start(done)
2028
})
2129

2230
it('echo', (done) => {
23-
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
24-
const peer = new Peer(id)
25-
peer.multiaddr.add(mh)
26-
2731
const message = 'Hello World!'
2832
node.swarm.dial(peer, '/echo/1.0.0', (err, conn) => {
2933
expect(err).to.not.exist
@@ -40,18 +44,16 @@ describe('libp2p-ipfs-browser', function () {
4044

4145
describe('stress', () => {
4246
it('one big write', (done) => {
43-
const mh = multiaddr('/ip4/127.0.0.1/tcp/9090/ws')
44-
const peer = new Peer(id)
45-
peer.multiaddr.add(mh)
46-
4747
const message = new Buffer(1000000).fill('a').toString('hex')
48+
4849
node.swarm.dial(peer, '/echo/1.0.0', (err, conn) => {
4950
expect(err).to.not.exist
5051

5152
conn.write(message)
5253
conn.write('STOP')
5354

5455
let result = ''
56+
5557
conn.on('data', (data) => {
5658
if (data.toString() === 'STOP') {
5759
conn.end()
@@ -83,14 +85,14 @@ describe('libp2p-ipfs-browser', function () {
8385
expected += `${counter} `
8486
}
8587

86-
setTimeout(() => {
87-
while (++counter < 20000) {
88-
conn.write(`${counter} `)
89-
expected += `${counter} `
90-
}
88+
while (++counter < 20000) {
89+
conn.write(`${counter} `)
90+
expected += `${counter} `
91+
}
9192

93+
setTimeout(() => {
9294
conn.write('STOP')
93-
}, 1000)
95+
}, 2000)
9496

9597
let result = ''
9698
conn.on('data', (data) => {

0 commit comments

Comments
 (0)