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.
This commit is contained in:
Alex Potsides
2021-12-08 08:38:17 +00:00
committed by GitHub
parent b539f9b655
commit 1b46f47fdb
21 changed files with 155 additions and 138 deletions

View File

@ -36,14 +36,14 @@ describe('content-routing', () => {
throw new Error('.findProviders should return an error')
} catch (/** @type {any} */ err) {
expect(err).to.exist()
expect(err.code).to.equal('NO_ROUTERS_AVAILABLE')
expect(err.code).to.equal('ERR_NO_ROUTERS_AVAILABLE')
}
})
it('.provide should return an error', async () => {
await expect(node.contentRouting.provide('a cid'))
.to.eventually.be.rejected()
.and.to.have.property('code', 'NO_ROUTERS_AVAILABLE')
.and.to.have.property('code', 'ERR_NO_ROUTERS_AVAILABLE')
})
})
@ -87,8 +87,11 @@ describe('content-routing', () => {
sinon.stub(nodes[0]._dht, 'findProviders').callsFake(function * () {
deferred.resolve()
yield {
id: providerPeerId,
multiaddrs: []
name: 'PROVIDER',
providers: [{
id: providerPeerId,
multiaddrs: []
}]
}
})
@ -361,7 +364,12 @@ describe('content-routing', () => {
}
sinon.stub(node._dht, 'findProviders').callsFake(async function * () {
yield result1
yield {
name: 'PROVIDER',
providers: [
result1
]
}
})
sinon.stub(delegate, 'findProviders').callsFake(async function * () {
yield result2
@ -382,7 +390,8 @@ describe('content-routing', () => {
const dhtDeferred = pDefer()
const delegatedDeferred = pDefer()
sinon.stub(node._dht, 'provide').callsFake(() => {
sinon.stub(node._dht, 'provide').callsFake(async function * () {
yield
dhtDeferred.resolve()
})
@ -406,7 +415,12 @@ describe('content-routing', () => {
}]
sinon.stub(node._dht, 'findProviders').callsFake(function * () {
yield results[0]
yield {
name: 'PROVIDER',
providers: [
results[0]
]
}
})
sinon.stub(delegate, 'findProviders').callsFake(function * () { // eslint-disable-line require-yield

View File

@ -38,13 +38,13 @@ describe('DHT subsystem is configurable', () => {
})
libp2p = await create(customOptions)
expect(libp2p._dht.isStarted).to.equal(false)
expect(libp2p._dht.isStarted()).to.equal(false)
await libp2p.start()
expect(libp2p._dht.isStarted).to.equal(true)
expect(libp2p._dht.isStarted()).to.equal(true)
await libp2p.stop()
expect(libp2p._dht.isStarted).to.equal(false)
expect(libp2p._dht.isStarted()).to.equal(false)
})
it('should not start if disabled once libp2p starts', async () => {
@ -63,10 +63,10 @@ describe('DHT subsystem is configurable', () => {
})
libp2p = await create(customOptions)
expect(libp2p._dht.isStarted).to.equal(false)
expect(libp2p._dht.isStarted()).to.equal(false)
await libp2p.start()
expect(libp2p._dht.isStarted).to.equal(false)
expect(libp2p._dht.isStarted()).to.equal(false)
})
it('should allow a manual start', async () => {
@ -86,9 +86,9 @@ describe('DHT subsystem is configurable', () => {
libp2p = await create(customOptions)
await libp2p.start()
expect(libp2p._dht.isStarted).to.equal(false)
expect(libp2p._dht.isStarted()).to.equal(false)
await libp2p._dht.start()
expect(libp2p._dht.isStarted).to.equal(true)
expect(libp2p._dht.isStarted()).to.equal(true)
})
})

View File

@ -60,8 +60,8 @@ describe('DHT subsystem operates correctly', () => {
expect(connection).to.exist()
return Promise.all([
pWaitFor(() => libp2p._dht.routingTable.size === 1),
pWaitFor(() => remoteLibp2p._dht.routingTable.size === 1)
pWaitFor(() => libp2p._dht._lan._routingTable.size === 1),
pWaitFor(() => remoteLibp2p._dht._lan._routingTable.size === 1)
])
})
@ -71,14 +71,14 @@ describe('DHT subsystem operates correctly', () => {
await libp2p.dialProtocol(remAddr, subsystemMulticodecs)
await Promise.all([
pWaitFor(() => libp2p._dht.routingTable.size === 1),
pWaitFor(() => remoteLibp2p._dht.routingTable.size === 1)
pWaitFor(() => libp2p._dht._lan._routingTable.size === 1),
pWaitFor(() => remoteLibp2p._dht._lan._routingTable.size === 1)
])
await libp2p.contentRouting.put(key, value)
const fetchedValue = await remoteLibp2p.contentRouting.get(key)
expect(fetchedValue).to.eql(value)
const fetchedValue = await remoteLibp2p.contentRouting.get(key)
expect(fetchedValue).to.have.property('val').that.equalBytes(value)
})
})
@ -119,11 +119,13 @@ describe('DHT subsystem operates correctly', () => {
const connection = await libp2p.dial(remAddr)
expect(connection).to.exist()
expect(libp2p._dht.routingTable.size).to.be.eql(0)
expect(remoteLibp2p._dht.routingTable.size).to.be.eql(0)
expect(libp2p._dht._lan._routingTable.size).to.be.eql(0)
await remoteLibp2p._dht.start()
return pWaitFor(() => libp2p._dht.routingTable.size === 1)
// should be 0 directly after start - TODO this may be susceptible to timing bugs, we should have
// the ability to report stats on the DHT routing table instead of reaching into it's heart like this
expect(remoteLibp2p._dht._lan._routingTable.size).to.be.eql(0)
return pWaitFor(() => libp2p._dht._lan._routingTable.size === 1)
})
it('should put on a peer and get from the other', async () => {
@ -133,12 +135,12 @@ describe('DHT subsystem operates correctly', () => {
const value = uint8ArrayFromString('world')
await remoteLibp2p._dht.start()
await pWaitFor(() => libp2p._dht.routingTable.size === 1)
await pWaitFor(() => libp2p._dht._lan._routingTable.size === 1)
await libp2p.contentRouting.put(key, value)
const fetchedValue = await remoteLibp2p.contentRouting.get(key)
expect(fetchedValue).to.eql(value)
expect(fetchedValue).to.have.property('val').that.equalBytes(value)
})
})
})

View File

@ -1,7 +1,6 @@
'use strict'
const KadDht = require('libp2p-kad-dht')
const { multicodec } = require('libp2p-kad-dht')
const Crypto = require('../../../src/insecure/plaintext')
const Muxer = require('libp2p-mplex')
const Transport = require('libp2p-tcp')
@ -25,13 +24,12 @@ const subsystemOptions = mergeOptions(baseOptions, {
config: {
dht: {
kBucketSize: 20,
randomWalk: {
enabled: true
},
enabled: true
}
}
})
module.exports.subsystemOptions = subsystemOptions
module.exports.subsystemMulticodecs = [multicodec]
module.exports.subsystemMulticodecs = [
'/ipfs/lan/kad/1.0.0'
]

View File

@ -13,9 +13,6 @@ const routingOptions = mergeOptions(baseOptions, {
config: {
dht: {
kBucketSize: 20,
randomWalk: {
enabled: true
},
enabled: true
}
}