Skip to content

Commit

Permalink
feat!: test different transports (#149)
Browse files Browse the repository at this point in the history
Split `connect` tests into TCP and WebTransport
  • Loading branch information
achingbrain committed Apr 29, 2024
1 parent efb27b6 commit 48bbf8b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
23 changes: 18 additions & 5 deletions src/connect.ts → src/connect/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
import { expect } from 'aegir/chai'
import { runTests } from './utils/test-matrix.js'
import type { Daemon, SpawnOptions, DaemonFactory } from './index.js'
import type { Daemon, DaemonFactory, NodeType, SpawnOptions, TransportType } from '../index.js'

export function connectTests (factory: DaemonFactory): void {
runTests('connect', runConnectTests, factory)
const nodeTypes: NodeType[] = ['js', 'go']
const transportTypes: TransportType[] = ['tcp', 'webtransport']

for (const typeA of nodeTypes) {
for (const typeB of nodeTypes) {
transportTypes.forEach(transport => {
runConnectTests(
transport,
factory,
{ type: typeA, transport },
{ type: typeB, transport }
)
})
}
}
}

function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnOptions, optionsB: SpawnOptions): void {
describe(name, () => {
describe(`connection.${name}`, () => {
let daemonA: Daemon
let daemonB: Daemon

Expand All @@ -28,7 +41,7 @@ function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnO
)
})

it(`${optionsA.type} peer to ${optionsB.type} peer`, async function () {
it(`${optionsA.type} peer to ${optionsB.type} peer over ${name}`, async function () {
this.timeout(10 * 1000)

const identify1 = await daemonA.client.identify()
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
* For an example, see the js-libp2p interop test runner.
*/

import { connectTests } from './connect.js'
import { connectTests } from './connect/index.js'
import { dhtTests } from './dht/index.js'
import { pubsubTests } from './pubsub/index.js'
import { relayTests } from './relay/index.js'
Expand All @@ -59,6 +59,7 @@ export type PeerIdType = 'rsa' | 'ed25519' | 'secp256k1'
export type PubSubRouter = 'gossipsub' | 'floodsub'
export type Muxer = 'mplex' | 'yamux'
export type Encryption = 'noise' | 'tls'
export type TransportType = 'tcp' | 'webtransport'

export interface SpawnOptions {
type: NodeType
Expand All @@ -72,6 +73,7 @@ export interface SpawnOptions {
// the node will not listen on any
// addresses if true
noListen?: boolean
transport?: TransportType
}

export interface DaemonFactory {
Expand Down

0 comments on commit 48bbf8b

Please sign in to comment.