Skip to content

Commit

Permalink
chore: make tests more reliable in ci (#2821)
Browse files Browse the repository at this point in the history
CI is underpowered, the "many small writes" test overloads process
and means the connection monitor thinks the remote has gone away
so disable it during interface tests.
  • Loading branch information
achingbrain authored Nov 14, 2024
1 parent 7dcabb8 commit 844a8d2
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 14 deletions.
7 changes: 6 additions & 1 deletion packages/integration-tests/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default {
const { identify } = await import('@libp2p/identify')
const { echo } = await import('@libp2p/echo')
const { mockMuxer } = await import('@libp2p/interface-compliance-tests/mocks')
const { ping } = await import('@libp2p/ping')

const libp2p = await createLibp2p({
connectionManager: {
Expand Down Expand Up @@ -54,7 +55,11 @@ export default {
}),
echo: echo({
maxInboundStreams: 5
})
}),
ping: ping()
},
connectionMonitor: {
enabled: false
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ describe('Circuit relay transport interface compliance', () => {
},
connectionGater: {
denyDialMultiaddr: () => false
},
connectionMonitor: {
enabled: false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ describe('memory transport interface compliance tests', () => {
],
streamMuxers: [
yamux()
]
],
connectionMonitor: {
enabled: false
}
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ describe('tcp transport interface compliance IPv4', () => {
],
streamMuxers: [
yamux()
]
],
connectionMonitor: {
enabled: false
}
}

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { yamux } from '@chainsafe/libp2p-yamux'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'
import { identify } from '@libp2p/identify'
import tests from '@libp2p/interface-compliance-tests/transport'
import { ping } from '@libp2p/ping'
import { webRTC } from '@libp2p/webrtc'
import { webSockets } from '@libp2p/websockets'
import { all } from '@libp2p/websockets/filters'
Expand Down Expand Up @@ -33,10 +34,14 @@ describe('WebRTC transport interface compliance', () => {
yamux()
],
services: {
identify: identify()
identify: identify(),
ping: ping()
},
connectionGater: {
denyDialMultiaddr: () => false
},
connectionMonitor: {
enabled: false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ describe('websocket transport interface compliance', () => {
],
connectionGater: {
denyDialMultiaddr: () => false
},
connectionMonitor: {
enabled: false
}
}

Expand Down
10 changes: 5 additions & 5 deletions packages/interface-compliance-tests/src/transport/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isValidTick } from '../is-valid-tick.js'
import { createPeer, getTransportManager, getUpgrader, slowNetwork } from './utils.js'
import type { TestSetup } from '../index.js'
import type { Echo } from '@libp2p/echo'
import type { Connection, Libp2p, Stream } from '@libp2p/interface'
import type { Connection, Libp2p } from '@libp2p/interface'
import type { Multiaddr } from '@multiformats/multiaddr'
import type { MultiaddrMatcher } from '@multiformats/multiaddr-matcher'
import type { Libp2pInit } from 'libp2p'
Expand Down Expand Up @@ -164,14 +164,14 @@ export default (common: TestSetup<TransportTestFixtures>): void => {
remoteConn = await incomingConnectionPromise.promise
}

const streams: Stream[] = []

for (let i = 0; i < 5; i++) {
streams.push(await connection.newStream('/echo/1.0.0', {
await connection.newStream('/echo/1.0.0', {
maxOutboundStreams: 5
}))
})
}

const streams = connection.streams

// Close the connection and verify all streams have been closed
await connection.close()

Expand Down
13 changes: 10 additions & 3 deletions packages/transport-webrtc/src/muxer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,16 @@ export class DataChannelMuxer implements StreamMuxer {
return
}

// lib-datachannel throws if `.getId` is called on a closed channel so
// memoize it
const id = channel.id

const stream = createStream({
channel,
direction: 'inbound',
onEnd: () => {
this.log('incoming channel %s ended with state %s', channel.id, channel.readyState)
this.#onStreamEnd(stream, channel)
this.log('incoming channel %s ended', id)
},
logger: this.logger,
...this.dataChannelOptions
Expand Down Expand Up @@ -241,15 +245,18 @@ export class DataChannelMuxer implements StreamMuxer {
newStream (): Stream {
// The spec says the label SHOULD be an empty string: https://github.com/libp2p/specs/blob/master/webrtc/README.md#rtcdatachannel-label
const channel = this.peerConnection.createDataChannel('')
// lib-datachannel throws if `.getId` is called on a closed channel so
// memoize it
const id = channel.id

this.log.trace('opened outgoing datachannel with channel id %s', channel.id)
this.log.trace('opened outgoing datachannel with channel id %s', id)

const stream = createStream({
channel,
direction: 'outbound',
onEnd: () => {
this.log('outgoing channel %s ended with state %s', channel.id, channel.readyState)
this.#onStreamEnd(stream, channel)
this.log('outgoing channel %s ended', id)
},
logger: this.logger,
...this.dataChannelOptions
Expand Down
8 changes: 6 additions & 2 deletions packages/transport-webrtc/src/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,11 @@ export class WebRTCStream extends AbstractStream {
}

async sendReset (): Promise<void> {
await this._sendFlag(Message.Flag.RESET)
try {
await this._sendFlag(Message.Flag.RESET)
} catch (err) {
this.log.error('failed to send reset - %e', err)
}
}

async sendCloseWrite (options: AbortOptions): Promise<void> {
Expand Down Expand Up @@ -362,7 +366,7 @@ export class WebRTCStream extends AbstractStream {

return true
} catch (err: any) {
this.log.error('could not send flag %s', flag.toString(), err)
this.log.error('could not send flag %s - %e', flag.toString(), err)
}

return false
Expand Down

0 comments on commit 844a8d2

Please sign in to comment.