Skip to content

Commit 1b46f47

Browse files
authored
chore: run node tests in ci (#1057)
Looks like this project stopped running the `test:node` npm script when it was migrated to gh actions. Re-enable it and fix all the related test failures.
1 parent b539f9b commit 1b46f47

21 files changed

+151
-134
lines changed

.github/workflows/main.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
node-version: ${{ matrix.node }}
3939
- run: npm install
40-
- run: npx aegir test -t node --cov --bail
40+
- run: npm run test:node -- --cov --bail
4141
- uses: codecov/codecov-action@v1
4242
test-chrome:
4343
needs: check
@@ -48,7 +48,7 @@ jobs:
4848
with:
4949
node-version: lts/*
5050
- run: npm install
51-
- run: npx aegir test -t browser -t webworker --bail
51+
- run: npm run test:browser -- -t browser -t webworker --bail
5252
test-firefox:
5353
needs: check
5454
runs-on: ubuntu-latest
@@ -58,7 +58,7 @@ jobs:
5858
with:
5959
node-version: lts/*
6060
- run: npm install
61-
- run: npx aegir test -t browser -t webworker --bail -- --browser firefox
61+
- run: npm run test:browser -- -t browser -t webworker --bail -- --browser firefox
6262
test-ts:
6363
needs: check
6464
runs-on: ubuntu-latest

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@
151151
"libp2p": ".",
152152
"libp2p-bootstrap": "^0.14.0",
153153
"libp2p-delegated-content-routing": "^0.11.0",
154-
"libp2p-delegated-peer-routing": "^0.11.0",
154+
"libp2p-delegated-peer-routing": "^0.11.1",
155155
"libp2p-floodsub": "^0.27.0",
156156
"libp2p-gossipsub": "^0.12.1",
157157
"libp2p-interfaces-compliance-tests": "^2.0.1",

src/circuit/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const debug = require('debug')
44
const log = Object.assign(debug('libp2p:relay'), {
55
error: debug('libp2p:relay:err')
66
})
7-
7+
const { codes } = require('./../errors')
88
const {
99
setDelayedInterval,
1010
clearDelayedInterval
@@ -88,7 +88,7 @@ class Relay {
8888
const cid = await namespaceToCid(RELAY_RENDEZVOUS_NS)
8989
await this._libp2p.contentRouting.provide(cid)
9090
} catch (/** @type {any} */ err) {
91-
if (err.code === 'NO_ROUTERS_AVAILABLE') {
91+
if (err.code === codes.ERR_NO_ROUTERS_AVAILABLE) {
9292
log.error('a content router, such as a DHT, must be provided in order to advertise the relay service', err)
9393
// Stop the advertise
9494
this.stop()

src/config.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,7 @@ const DefaultConfig = {
6060
protocolPrefix: 'ipfs',
6161
dht: {
6262
enabled: false,
63-
kBucketSize: 20,
64-
randomWalk: {
65-
enabled: false, // disabled waiting for https://github.com/libp2p/js-libp2p-kad-dht/issues/86
66-
queriesPerPeriod: 1,
67-
interval: 300e3,
68-
timeout: 10e3
69-
}
63+
kBucketSize: 20
7064
},
7165
nat: {
7266
enabled: true,

src/content-routing/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class ContentRouting {
5454
*/
5555
async * findProviders (key, options = {}) {
5656
if (!this.routers.length) {
57-
throw errCode(new Error('No content this.routers available'), 'NO_ROUTERS_AVAILABLE')
57+
throw errCode(new Error('No content this.routers available'), codes.ERR_NO_ROUTERS_AVAILABLE)
5858
}
5959

6060
yield * pipe(
@@ -77,7 +77,7 @@ class ContentRouting {
7777
*/
7878
async provide (key) {
7979
if (!this.routers.length) {
80-
throw errCode(new Error('No content routers available'), 'NO_ROUTERS_AVAILABLE')
80+
throw errCode(new Error('No content routers available'), codes.ERR_NO_ROUTERS_AVAILABLE)
8181
}
8282

8383
await Promise.all(this.routers.map((router) => router.provide(key)))

src/dht/dht-peer-routing.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,12 @@ class DHTPeerRouting {
2727
*/
2828
async findPeer (peerId, options = {}) {
2929
for await (const event of this._dht.findPeer(peerId, options)) {
30-
if (event.name === 'FINAL_PEER') {
31-
return event.peer
30+
if (event.name === 'PEER_RESPONSE') {
31+
const peer = event.closer.find(peerData => peerData.id.equals(peerId))
32+
33+
if (peer) {
34+
return peer
35+
}
3236
}
3337
}
3438

src/errors.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ exports.codes = {
3838
ERR_INVALID_MULTIADDR: 'ERR_INVALID_MULTIADDR',
3939
ERR_SIGNATURE_NOT_VALID: 'ERR_SIGNATURE_NOT_VALID',
4040
ERR_FIND_SELF: 'ERR_FIND_SELF',
41-
ERR_NO_ROUTERS: 'ERR_NO_ROUTERS',
41+
ERR_NO_ROUTERS_AVAILABLE: 'ERR_NO_ROUTERS_AVAILABLE',
4242
ERR_CONNECTION_NOT_MULTIPLEXED: 'ERR_CONNECTION_NOT_MULTIPLEXED',
4343
ERR_NO_DIAL_TOKENS: 'ERR_NO_DIAL_TOKENS',
4444
ERR_KEYCHAIN_REQUIRED: 'ERR_KEYCHAIN_REQUIRED',

src/index.js

-7
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,9 @@ const { updateSelfPeerRecord } = require('./record/utils')
5656
* @property {MuxedStream} stream
5757
* @property {string} protocol
5858
*
59-
* @typedef {Object} RandomWalkOptions
60-
* @property {boolean} [enabled = false]
61-
* @property {number} [queriesPerPeriod = 1]
62-
* @property {number} [interval = 300e3]
63-
* @property {number} [timeout = 10e3]
64-
*
6559
* @typedef {Object} DhtOptions
6660
* @property {boolean} [enabled = false]
6761
* @property {number} [kBucketSize = 20]
68-
* @property {RandomWalkOptions} [randomWalk]
6962
* @property {boolean} [clientMode]
7063
* @property {import('libp2p-interfaces/src/types').DhtSelectors} [selectors]
7164
* @property {import('libp2p-interfaces/src/types').DhtValidators} [validators]

src/peer-routing.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class PeerRouting {
105105
*/
106106
async findPeer (id, options) { // eslint-disable-line require-await
107107
if (!this._routers.length) {
108-
throw errCode(new Error('No peer routers available'), errors.codes.ERR_NO_ROUTERS)
108+
throw errCode(new Error('No peer routers available'), errors.codes.ERR_NO_ROUTERS_AVAILABLE)
109109
}
110110

111111
if (id.toB58String() === this._peerId.toB58String()) {
@@ -145,7 +145,7 @@ class PeerRouting {
145145
*/
146146
async * getClosestPeers (key, options = { timeout: 30e3 }) {
147147
if (!this._routers.length) {
148-
throw errCode(new Error('No peer routers available'), errors.codes.ERR_NO_ROUTERS)
148+
throw errCode(new Error('No peer routers available'), errors.codes.ERR_NO_ROUTERS_AVAILABLE)
149149
}
150150

151151
if (options.timeout) {

test/content-routing/content-routing.node.js

+21-7
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ describe('content-routing', () => {
3636
throw new Error('.findProviders should return an error')
3737
} catch (/** @type {any} */ err) {
3838
expect(err).to.exist()
39-
expect(err.code).to.equal('NO_ROUTERS_AVAILABLE')
39+
expect(err.code).to.equal('ERR_NO_ROUTERS_AVAILABLE')
4040
}
4141
})
4242

4343
it('.provide should return an error', async () => {
4444
await expect(node.contentRouting.provide('a cid'))
4545
.to.eventually.be.rejected()
46-
.and.to.have.property('code', 'NO_ROUTERS_AVAILABLE')
46+
.and.to.have.property('code', 'ERR_NO_ROUTERS_AVAILABLE')
4747
})
4848
})
4949

@@ -87,8 +87,11 @@ describe('content-routing', () => {
8787
sinon.stub(nodes[0]._dht, 'findProviders').callsFake(function * () {
8888
deferred.resolve()
8989
yield {
90-
id: providerPeerId,
91-
multiaddrs: []
90+
name: 'PROVIDER',
91+
providers: [{
92+
id: providerPeerId,
93+
multiaddrs: []
94+
}]
9295
}
9396
})
9497

@@ -361,7 +364,12 @@ describe('content-routing', () => {
361364
}
362365

363366
sinon.stub(node._dht, 'findProviders').callsFake(async function * () {
364-
yield result1
367+
yield {
368+
name: 'PROVIDER',
369+
providers: [
370+
result1
371+
]
372+
}
365373
})
366374
sinon.stub(delegate, 'findProviders').callsFake(async function * () {
367375
yield result2
@@ -382,7 +390,8 @@ describe('content-routing', () => {
382390
const dhtDeferred = pDefer()
383391
const delegatedDeferred = pDefer()
384392

385-
sinon.stub(node._dht, 'provide').callsFake(() => {
393+
sinon.stub(node._dht, 'provide').callsFake(async function * () {
394+
yield
386395
dhtDeferred.resolve()
387396
})
388397

@@ -406,7 +415,12 @@ describe('content-routing', () => {
406415
}]
407416

408417
sinon.stub(node._dht, 'findProviders').callsFake(function * () {
409-
yield results[0]
418+
yield {
419+
name: 'PROVIDER',
420+
providers: [
421+
results[0]
422+
]
423+
}
410424
})
411425

412426
sinon.stub(delegate, 'findProviders').callsFake(function * () { // eslint-disable-line require-yield

test/content-routing/dht/configuration.node.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ describe('DHT subsystem is configurable', () => {
3838
})
3939

4040
libp2p = await create(customOptions)
41-
expect(libp2p._dht.isStarted).to.equal(false)
41+
expect(libp2p._dht.isStarted()).to.equal(false)
4242

4343
await libp2p.start()
44-
expect(libp2p._dht.isStarted).to.equal(true)
44+
expect(libp2p._dht.isStarted()).to.equal(true)
4545

4646
await libp2p.stop()
47-
expect(libp2p._dht.isStarted).to.equal(false)
47+
expect(libp2p._dht.isStarted()).to.equal(false)
4848
})
4949

5050
it('should not start if disabled once libp2p starts', async () => {
@@ -63,10 +63,10 @@ describe('DHT subsystem is configurable', () => {
6363
})
6464

6565
libp2p = await create(customOptions)
66-
expect(libp2p._dht.isStarted).to.equal(false)
66+
expect(libp2p._dht.isStarted()).to.equal(false)
6767

6868
await libp2p.start()
69-
expect(libp2p._dht.isStarted).to.equal(false)
69+
expect(libp2p._dht.isStarted()).to.equal(false)
7070
})
7171

7272
it('should allow a manual start', async () => {
@@ -86,9 +86,9 @@ describe('DHT subsystem is configurable', () => {
8686

8787
libp2p = await create(customOptions)
8888
await libp2p.start()
89-
expect(libp2p._dht.isStarted).to.equal(false)
89+
expect(libp2p._dht.isStarted()).to.equal(false)
9090

9191
await libp2p._dht.start()
92-
expect(libp2p._dht.isStarted).to.equal(true)
92+
expect(libp2p._dht.isStarted()).to.equal(true)
9393
})
9494
})

test/content-routing/dht/operation.node.js

+13-11
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ describe('DHT subsystem operates correctly', () => {
6060
expect(connection).to.exist()
6161

6262
return Promise.all([
63-
pWaitFor(() => libp2p._dht.routingTable.size === 1),
64-
pWaitFor(() => remoteLibp2p._dht.routingTable.size === 1)
63+
pWaitFor(() => libp2p._dht._lan._routingTable.size === 1),
64+
pWaitFor(() => remoteLibp2p._dht._lan._routingTable.size === 1)
6565
])
6666
})
6767

@@ -71,14 +71,14 @@ describe('DHT subsystem operates correctly', () => {
7171

7272
await libp2p.dialProtocol(remAddr, subsystemMulticodecs)
7373
await Promise.all([
74-
pWaitFor(() => libp2p._dht.routingTable.size === 1),
75-
pWaitFor(() => remoteLibp2p._dht.routingTable.size === 1)
74+
pWaitFor(() => libp2p._dht._lan._routingTable.size === 1),
75+
pWaitFor(() => remoteLibp2p._dht._lan._routingTable.size === 1)
7676
])
7777

7878
await libp2p.contentRouting.put(key, value)
79-
const fetchedValue = await remoteLibp2p.contentRouting.get(key)
8079

81-
expect(fetchedValue).to.eql(value)
80+
const fetchedValue = await remoteLibp2p.contentRouting.get(key)
81+
expect(fetchedValue).to.have.property('val').that.equalBytes(value)
8282
})
8383
})
8484

@@ -119,11 +119,13 @@ describe('DHT subsystem operates correctly', () => {
119119
const connection = await libp2p.dial(remAddr)
120120

121121
expect(connection).to.exist()
122-
expect(libp2p._dht.routingTable.size).to.be.eql(0)
123-
expect(remoteLibp2p._dht.routingTable.size).to.be.eql(0)
122+
expect(libp2p._dht._lan._routingTable.size).to.be.eql(0)
124123

125124
await remoteLibp2p._dht.start()
126-
return pWaitFor(() => libp2p._dht.routingTable.size === 1)
125+
// should be 0 directly after start - TODO this may be susceptible to timing bugs, we should have
126+
// the ability to report stats on the DHT routing table instead of reaching into it's heart like this
127+
expect(remoteLibp2p._dht._lan._routingTable.size).to.be.eql(0)
128+
return pWaitFor(() => libp2p._dht._lan._routingTable.size === 1)
127129
})
128130

129131
it('should put on a peer and get from the other', async () => {
@@ -133,12 +135,12 @@ describe('DHT subsystem operates correctly', () => {
133135
const value = uint8ArrayFromString('world')
134136

135137
await remoteLibp2p._dht.start()
136-
await pWaitFor(() => libp2p._dht.routingTable.size === 1)
138+
await pWaitFor(() => libp2p._dht._lan._routingTable.size === 1)
137139

138140
await libp2p.contentRouting.put(key, value)
139141

140142
const fetchedValue = await remoteLibp2p.contentRouting.get(key)
141-
expect(fetchedValue).to.eql(value)
143+
expect(fetchedValue).to.have.property('val').that.equalBytes(value)
142144
})
143145
})
144146
})

test/content-routing/dht/utils.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const KadDht = require('libp2p-kad-dht')
4-
const { multicodec } = require('libp2p-kad-dht')
54
const Crypto = require('../../../src/insecure/plaintext')
65
const Muxer = require('libp2p-mplex')
76
const Transport = require('libp2p-tcp')
@@ -25,13 +24,12 @@ const subsystemOptions = mergeOptions(baseOptions, {
2524
config: {
2625
dht: {
2726
kBucketSize: 20,
28-
randomWalk: {
29-
enabled: true
30-
},
3127
enabled: true
3228
}
3329
}
3430
})
3531

3632
module.exports.subsystemOptions = subsystemOptions
37-
module.exports.subsystemMulticodecs = [multicodec]
33+
module.exports.subsystemMulticodecs = [
34+
'/ipfs/lan/kad/1.0.0'
35+
]

test/content-routing/utils.js

-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ const routingOptions = mergeOptions(baseOptions, {
1313
config: {
1414
dht: {
1515
kBucketSize: 20,
16-
randomWalk: {
17-
enabled: true
18-
},
1916
enabled: true
2017
}
2118
}

test/nat-manager/nat-manager.node.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,10 @@ describe('Nat Manager (TCP)', () => {
244244
})
245245

246246
it('shuts the nat api down when stopping', async function () {
247+
if (process.env.CI) {
248+
return this.skip('CI environments will not let us map external ports')
249+
}
250+
247251
function findRoutableAddress () {
248252
const interfaces = networkInterfaces()
249253

@@ -261,7 +265,7 @@ describe('Nat Manager (TCP)', () => {
261265

262266
if (!addr) {
263267
// skip test if no non-loopback address is found
264-
this.skip()
268+
return this.skip()
265269
}
266270

267271
const {

test/peer-discovery/index.node.js

+1-8
Original file line numberDiff line numberDiff line change
@@ -161,20 +161,13 @@ describe('peer discovery scenarios', () => {
161161
autoDial: false
162162
},
163163
dht: {
164-
randomWalk: {
165-
enabled: false,
166-
delay: 1000, // start the first query quickly
167-
interval: 10000,
168-
timeout: 5000
169-
},
170164
enabled: true
171165
}
172166
}
173167
})
174168

175169
const localConfig = getConfig(peerId)
176-
// Only run random walk on our local node
177-
localConfig.config.dht.randomWalk.enabled = true
170+
178171
libp2p = new Libp2p(localConfig)
179172

180173
const remoteLibp2p1 = new Libp2p(getConfig(remotePeerId1))

0 commit comments

Comments
 (0)