Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add webrtc-direct connect tests #153

Merged
merged 1 commit into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/connect/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ import type { Daemon, DaemonFactory, NodeType, SpawnOptions, TransportType } fro

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

for (const typeA of nodeTypes) {
for (const typeB of nodeTypes) {
transportTypes.forEach(transport => {
runConnectTests(
transport,
factory,
{ type: typeA, transport },
{ type: typeA, transport, noListen: true },
{ type: typeB, transport }
)
})
Expand All @@ -23,13 +23,23 @@ function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnO
describe(`connection.${name}`, () => {
let daemonA: Daemon
let daemonB: Daemon
let skipped: boolean

// Start Daemons
before(async function () {
this.timeout(20 * 1000)

daemonA = await factory.spawn(optionsA)
daemonB = await factory.spawn(optionsB)
try {
daemonA = await factory.spawn(optionsA)
daemonB = await factory.spawn(optionsB)
} catch (err: any) {
if (err.name === 'UnsupportedError') {
skipped = true
return
}

throw err
}
})

// Stop daemons
Expand All @@ -44,6 +54,10 @@ function runConnectTests (name: string, factory: DaemonFactory, optionsA: SpawnO
it(`${optionsA.type} peer to ${optionsB.type} peer over ${name}`, async function () {
this.timeout(10 * 1000)

if (skipped) {
return this.skip()
}

const identify1 = await daemonA.client.identify()
const identify2 = await daemonB.client.identify()

Expand Down
14 changes: 13 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +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 type TransportType = 'tcp' | 'webtransport' | 'webrtc-direct'

export interface SpawnOptions {
type: NodeType
Expand Down Expand Up @@ -95,3 +95,15 @@ export {
streamTests as streamInteropTests,
relayTests as relayInteropTests
}

/**
* Some tests allow skipping certain configurations. When this is necessary,
* `DaemonFactory.spawn` should thow an instance of this error.
*/
export class UnsupportedError extends Error {
constructor (message = 'Unsupported test configuration') {
super(message)

this.name = 'UnsupportedError'
}
}
Loading