mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-06-26 23:41:34 +00:00
connection reuse test
This commit is contained in:
@ -32,34 +32,21 @@ beforeEach(function (done) {
|
||||
peerB = new Peer(Id.create(), [multiaddr('/ip4/127.0.0.1/tcp/' + swarmB.port)])
|
||||
c.hit()
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
afterEach({ timeout: 5000 }, function (done) {
|
||||
var c = new Counter(4, done)
|
||||
swarmA.closeConns(function () {
|
||||
c.hit()
|
||||
swarmA.closeListener(function () {
|
||||
console.log('AAA CLOSE')
|
||||
c.hit()
|
||||
})
|
||||
})
|
||||
|
||||
swarmB.closeConns(function () {
|
||||
console.log('bb')
|
||||
c.hit()
|
||||
swarmB.closeListener(function () {
|
||||
console.log('BBB CLOSE')
|
||||
c.hit()
|
||||
})
|
||||
})
|
||||
afterEach(function (done) {
|
||||
swarmA.closeListener()
|
||||
swarmB.closeListener()
|
||||
done()
|
||||
})
|
||||
|
||||
experiment('BASE', function () {
|
||||
test('Open a stream', {timeout: false}, function (done) {
|
||||
test('Open a stream', function (done) {
|
||||
var protocol = '/sparkles/3.3.3'
|
||||
var c = new Counter(2, done)
|
||||
|
||||
swarmB.registerHandle(protocol, function (stream) {
|
||||
swarmB.registerHandler(protocol, function (stream) {
|
||||
c.hit()
|
||||
})
|
||||
|
||||
@ -69,17 +56,21 @@ experiment('BASE', function () {
|
||||
})
|
||||
})
|
||||
|
||||
test('Reuse stream (from dialer)', {timeout: false}, function (done) {
|
||||
test('Reuse connection (from dialer)', function (done) {
|
||||
var protocol = '/sparkles/3.3.3'
|
||||
var c = new Counter(2, done)
|
||||
|
||||
swarmB.registerHandle(protocol, function (stream) {
|
||||
c.hit()
|
||||
swarmB.registerHandler(protocol, function (err, stream) {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
})
|
||||
|
||||
swarmA.openStream(peerB, protocol, function (err, stream) {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
c.hit()
|
||||
|
||||
swarmA.openStream(peerB, protocol, function (err, stream) {
|
||||
expect(err).to.not.be.instanceof(Error)
|
||||
expect(swarmA.connections.length === 1)
|
||||
done()
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@ -99,3 +90,8 @@ function Counter (target, callback) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkErr (err) {
|
||||
console.log('err')
|
||||
expect(err).to.be.instanceof(Error)
|
||||
}
|
||||
|
Reference in New Issue
Block a user