Skip to content

Commit

Permalink
chore: add timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Feb 12, 2025
1 parent bcf35d3 commit 43a4e16
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 13 deletions.
4 changes: 4 additions & 0 deletions .github/actions/run-transport-interop-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ inputs:
description: "How many workers to use for the test"
required: false
default: "2"
timeout:
description: "How many seconds to let each test run for"
required: false
runs:
using: "composite"
steps:
Expand Down Expand Up @@ -122,6 +125,7 @@ runs:
EXTRA_VERSION: ${{ inputs.extra-versions }}
NAME_FILTER: ${{ inputs.test-filter }}
NAME_IGNORE: ${{ inputs.test-ignore }}
TIMEOUT: ${{ inputs.timeout }}
run: npm run test -- --extra-version=$EXTRA_VERSION --name-filter=$NAME_FILTER --name-ignore=$NAME_IGNORE
shell: bash

Expand Down
2 changes: 1 addition & 1 deletion transport-interop/impl/js/v1.x/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ ENV CI=true
RUN npm ci
RUN npm run build

ENTRYPOINT npm test -- -t node
ENTRYPOINT npm test -- -t node -- --exit
6 changes: 5 additions & 1 deletion transport-interop/impl/js/v1.x/test/dialer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ describe('ping test (dialer)', function () {
})

it('should dial and ping', async function () {
this.timeout(timeoutMs + 30_000)

let [, otherMaStr]: string[] = await redisProxy(['BLPOP', 'listenerAddr', `${timeoutMs / 1000}`])

// Hack until these are merged:
Expand All @@ -42,7 +44,9 @@ describe('ping test (dialer)', function () {
const handshakeStartInstant = Date.now()

console.error(`node ${node.peerId.toString()} dials: ${otherMa}`)
await node.dial(otherMa)
await node.dial(otherMa, {
signal: AbortSignal.timeout(timeoutMs)
})

console.error(`node ${node.peerId.toString()} pings: ${otherMa}`)
const pingRTT = await node.services.ping.ping(multiaddr(otherMa), {
Expand Down
12 changes: 8 additions & 4 deletions transport-interop/impl/js/v1.x/test/listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import type { Libp2p } from '@libp2p/interface'
import type { PingService } from '@libp2p/ping'

const isDialer: boolean = process.env.is_dialer === 'true'
const timeoutSecs: string = process.env.test_timeout_secs ?? '180'
const timeoutMs: number = parseInt(process.env.test_timeout_secs ?? '180') * 1000

describe('ping test (listener)', function () {
if (isDialer) {
return
}

// make the default timeout longer than the listener timeout
this.timeout((parseInt(timeoutSecs) * 1000) + 30000)
this.timeout(timeoutMs + 30_000)
let node: Libp2p<{ ping: PingService }>

beforeEach(async () => {
Expand All @@ -32,6 +32,8 @@ describe('ping test (listener)', function () {
})

it('should listen for ping', async function () {
this.timeout(timeoutMs + 30_000)

const sortByNonLocalIp = (a: Multiaddr, b: Multiaddr): -1 | 0 | 1 => {
if (a.toString().includes('127.0.0.1')) {
return 1
Expand Down Expand Up @@ -61,7 +63,9 @@ describe('ping test (listener)', function () {
}
// const conn = await node.dial(multiaddr(relayAddr))
console.error('dial relay')
await node.dial(multiaddr(relayAddr))
await node.dial(multiaddr(relayAddr), {
signal: AbortSignal.timeout(timeoutMs)
})
console.error('wait for relay reservation')
multiaddrs = await hasWebrtcMultiaddr
}
Expand All @@ -72,6 +76,6 @@ describe('ping test (listener)', function () {
await redisProxy(['RPUSH', 'listenerAddr', multiaddrs[0]])
// Wait
console.error('wait for incoming ping')
await new Promise(resolve => setTimeout(resolve, 1000 * parseInt(timeoutSecs, 10)))
await new Promise(resolve => setTimeout(resolve, timeoutMs))
})
})
2 changes: 1 addition & 1 deletion transport-interop/impl/js/v2.x/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ ENV CI=true
RUN npm ci
RUN npm run build

ENTRYPOINT npm test -- -t node
ENTRYPOINT npm test -- -t node -- --exit
6 changes: 5 additions & 1 deletion transport-interop/impl/js/v2.x/test/dialer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ describe('ping test (dialer)', function () {
})

it('should dial and ping', async function () {
this.timeout(timeoutMs + 30_000)

let [, otherMaStr]: string[] = await redisProxy(['BLPOP', 'listenerAddr', `${timeoutMs / 1000}`])

// Hack until these are merged:
Expand All @@ -42,7 +44,9 @@ describe('ping test (dialer)', function () {
const handshakeStartInstant = Date.now()

console.error(`node ${node.peerId.toString()} dials: ${otherMa}`)
await node.dial(otherMa)
await node.dial(otherMa, {
signal: AbortSignal.timeout(timeoutMs)
})

console.error(`node ${node.peerId.toString()} pings: ${otherMa}`)
const pingRTT = await node.services.ping.ping(multiaddr(otherMa), {
Expand Down
12 changes: 8 additions & 4 deletions transport-interop/impl/js/v2.x/test/listener.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import type { Libp2p } from '@libp2p/interface'
import type { PingService } from '@libp2p/ping'

const isDialer: boolean = process.env.is_dialer === 'true'
const timeoutSecs: string = process.env.test_timeout_secs ?? '180'
const timeoutMs: number = parseInt(process.env.test_timeout_secs ?? '180') * 1000

describe('ping test (listener)', function () {
if (isDialer) {
return
}

// make the default timeout longer than the listener timeout
this.timeout((parseInt(timeoutSecs) * 1000) + 30000)
this.timeout(timeoutMs + 30_000)
let node: Libp2p<{ ping: PingService }>

beforeEach(async () => {
Expand All @@ -32,6 +32,8 @@ describe('ping test (listener)', function () {
})

it('should listen for ping', async function () {
this.timeout(timeoutMs + 30_000)

const sortByNonLocalIp = (a: Multiaddr, b: Multiaddr): -1 | 0 | 1 => {
if (a.toString().includes('127.0.0.1')) {
return 1
Expand Down Expand Up @@ -61,7 +63,9 @@ describe('ping test (listener)', function () {
}
// const conn = await node.dial(multiaddr(relayAddr))
console.error('dial relay')
await node.dial(multiaddr(relayAddr))
await node.dial(multiaddr(relayAddr), {
signal: AbortSignal.timeout(timeoutMs)
})
console.error('wait for relay reservation')
multiaddrs = await hasWebrtcMultiaddr
}
Expand All @@ -72,6 +76,6 @@ describe('ping test (listener)', function () {
await redisProxy(['RPUSH', 'listenerAddr', multiaddrs[0]])
// Wait
console.error('wait for incoming ping')
await new Promise(resolve => setTimeout(resolve, 1000 * parseInt(timeoutSecs, 10)))
await new Promise(resolve => setTimeout(resolve, timeoutMs))
})
})
12 changes: 11 additions & 1 deletion transport-interop/src/compose-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@ import { stringify } from 'yaml';
import { dialerStdout, dialerTimings } from './compose-stdout-helper';

const exec = util.promisify(execStd);
const timeoutSecs = 3 * 60
const timeoutSecs = getTimeout();

function getTimeout (): number {
const timeout = parseInt(process.env.TIMEOUT, 10)

if (isNaN(timeout)) {
return 3 * 60
}

return timeout
}

export type RunOpts = {
up: {
Expand Down

0 comments on commit 43a4e16

Please sign in to comment.