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

Commit 9953c7f

Browse files
author
Pedro Santos
committed
refactor: ping before and after methods to async syntax
1 parent cb07f73 commit 9953c7f

File tree

3 files changed

+18
-68
lines changed

3 files changed

+18
-68
lines changed

src/ping/ping-pull-stream.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,27 @@
22
'use strict'
33

44
const pullToPromise = require('pull-to-promise')
5-
const series = require('async/series')
6-
const { spawnNodesWithId } = require('../utils/spawn')
75
const { getDescribe, getIt, expect } = require('../utils/mocha')
86
const { isPong } = require('./utils.js')
9-
const { connect } = require('../utils/swarm')
107

118
module.exports = (createCommon, options) => {
129
const describe = getDescribe(options)
1310
const it = getIt(options)
1411
const common = createCommon()
1512

1613
describe('.pingPullStream', function () {
17-
// TODO revisit when https://github.com/ipfs/go-ipfs/issues/5799 is resolved
18-
this.timeout(2 * 60 * 1000)
14+
this.timeout(60 * 1000)
1915

2016
let ipfsA
2117
let ipfsB
2218

23-
before(function (done) {
24-
common.setup((err, factory) => {
25-
if (err) return done(err)
26-
27-
series([
28-
(cb) => {
29-
spawnNodesWithId(2, factory, (err, nodes) => {
30-
if (err) return cb(err)
31-
ipfsA = nodes[0]
32-
ipfsB = nodes[1]
33-
cb()
34-
})
35-
},
36-
(cb) => connect(ipfsA, ipfsB.peerId.addresses[0], cb)
37-
], done)
38-
})
19+
before(async () => {
20+
ipfsA = await common.setup()
21+
ipfsB = await common.setup()
22+
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
3923
})
4024

41-
after((done) => common.teardown(done))
25+
after(() => common.teardown())
4226

4327
it('should send the specified number of packets over pull stream', async () => {
4428
const count = 3

src/ping/ping-readable-stream.js

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,27 @@
33

44
const pump = require('pump')
55
const { Writable } = require('stream')
6-
const series = require('async/series')
7-
const { spawnNodesWithId } = require('../utils/spawn')
86
const { getDescribe, getIt, expect } = require('../utils/mocha')
97
const { isPong } = require('./utils.js')
10-
const { connect } = require('../utils/swarm')
118

129
module.exports = (createCommon, options) => {
1310
const describe = getDescribe(options)
1411
const it = getIt(options)
1512
const common = createCommon()
1613

1714
describe('.pingReadableStream', function () {
18-
// TODO revisit when https://github.com/ipfs/go-ipfs/issues/5799 is resolved
19-
this.timeout(2 * 60 * 1000)
15+
this.timeout(60 * 1000)
2016

2117
let ipfsA
2218
let ipfsB
2319

24-
before(function (done) {
25-
common.setup((err, factory) => {
26-
if (err) return done(err)
27-
28-
series([
29-
(cb) => {
30-
spawnNodesWithId(2, factory, (err, nodes) => {
31-
if (err) return cb(err)
32-
ipfsA = nodes[0]
33-
ipfsB = nodes[1]
34-
cb()
35-
})
36-
},
37-
(cb) => connect(ipfsA, ipfsB.peerId.addresses[0], cb)
38-
], done)
39-
})
20+
before(async () => {
21+
ipfsA = await common.setup()
22+
ipfsB = await common.setup()
23+
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
4024
})
4125

42-
after((done) => common.teardown(done))
26+
after(() => common.teardown())
4327

4428
it('should send the specified number of packets over readable stream', () => {
4529
let packetNum = 0

src/ping/ping.js

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,27 @@
11
/* eslint-env mocha */
22
'use strict'
33

4-
const series = require('async/series')
5-
const { spawnNodesWithId } = require('../utils/spawn')
64
const { getDescribe, getIt, expect } = require('../utils/mocha')
75
const { expectIsPingResponse, isPong } = require('./utils')
8-
const { connect } = require('../utils/swarm')
96

107
module.exports = (createCommon, options) => {
118
const describe = getDescribe(options)
129
const it = getIt(options)
1310
const common = createCommon()
1411

1512
describe('.ping', function () {
16-
// TODO revisit when https://github.com/ipfs/go-ipfs/issues/5799 is resolved
17-
this.timeout(2 * 60 * 1000)
13+
this.timeout(60 * 1000)
1814

1915
let ipfsA
2016
let ipfsB
2117

22-
before(function (done) {
23-
this.timeout(60 * 1000)
24-
25-
common.setup((err, factory) => {
26-
if (err) return done(err)
27-
28-
series([
29-
(cb) => {
30-
spawnNodesWithId(2, factory, (err, nodes) => {
31-
if (err) return cb(err)
32-
ipfsA = nodes[0]
33-
ipfsB = nodes[1]
34-
cb()
35-
})
36-
},
37-
(cb) => connect(ipfsA, ipfsB.peerId.addresses[0], cb)
38-
], done)
39-
})
18+
before(async () => {
19+
ipfsA = await common.setup()
20+
ipfsB = await common.setup()
21+
await ipfsA.swarm.connect(ipfsB.peerId.addresses[0])
4022
})
4123

42-
after((done) => common.teardown(done))
24+
after(() => common.teardown())
4325

4426
it('should send the specified number of packets', async () => {
4527
const count = 3

0 commit comments

Comments
 (0)