Skip to content
Closed
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
9 changes: 9 additions & 0 deletions .changeset/wild-buses-guess.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
'prool': patch
---

Make the testcontainers Tempo instance startup timeout configurable via `startupTimeout`.

This also introduces a shared internal container-options shape for testcontainers-backed instances, so future container adapters can reuse the same option pattern.

The default timeout remains `10_000ms`.
5 changes: 4 additions & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
- name: Set up Docker
uses: docker/setup-docker-action@v4

- name: Pre-pull Tempo image
run: docker pull ghcr.io/tempoxyz/tempo:latest

- name: Run tests
run: pnpm test --bail=1
run: pnpm exec vitest --bail=1 --testTimeout=120000 --hookTimeout=120000
env:
VITE_FORK_URL: ${{ secrets.VITE_FORK_URL }}
5 changes: 3 additions & 2 deletions src/Pool.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ import { altoOptions } from '../test/utils.js'

let pool: ReturnType<typeof Pool.define>
const port = await getPort()
const forkUrl = process.env['VITE_FORK_URL'] || 'https://eth.merkle.io'

beforeAll(() =>
Server.create({
instance: Instance.anvil({
chainId: 1,
forkUrl: process.env['VITE_FORK_URL'] ?? 'https://eth.merkle.io',
forkUrl,
}),
port,
}).start(),
Expand Down Expand Up @@ -40,7 +41,7 @@ describe.each([
expect(pool).toBeDefined()
})

test('start', async () => {
test('start', { timeout: 60_000 }, async () => {
pool = Pool.define({
instance,
})
Expand Down
5 changes: 3 additions & 2 deletions src/Server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import { altoOptions } from '../test/utils.js'

const port = await getPort()
const forkUrl = process.env['VITE_FORK_URL'] || 'https://eth.merkle.io'

beforeAll(async () => {
await Server.create({
instance: Instance.anvil({
chainId: 1,
forkUrl: process.env['VITE_FORK_URL'] ?? 'https://eth.merkle.io',
forkUrl,
}),
port,
}).start()
Expand Down Expand Up @@ -83,7 +84,7 @@
await stop()
})

test('request: /start + /stop', async () => {
test('request: /start + /stop', { timeout: 60_000 }, async () => {

Check failure on line 87 in src/Server.test.ts

View workflow job for this annotation

GitHub Actions / Verify / Test

src/Server.test.ts > instance: 'tempo' > request: /start + /stop

Error: Test timed out in 60000ms. If this is a long-running test, pass a timeout value as the last argument or configure it globally with "testTimeout". ❯ src/Server.test.ts:87:3
const server = Server.create({
instance,
})
Expand Down
3 changes: 2 additions & 1 deletion src/instances/alto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { altoOptions } from '../../test/utils.js'
const instances: Instance.Instance[] = []

const port = await getPort()
const forkUrl = process.env['VITE_FORK_URL'] || 'https://eth.merkle.io'

const defineInstance = (parameters: Partial<Instance.alto.Parameters> = {}) => {
const instance = Instance.alto({
Expand All @@ -18,7 +19,7 @@ const defineInstance = (parameters: Partial<Instance.alto.Parameters> = {}) => {

beforeAll(() =>
Instance.anvil({
forkUrl: process.env['VITE_FORK_URL'] ?? 'https://eth.merkle.io',
forkUrl,
port,
}).start(),
)
Expand Down
15 changes: 10 additions & 5 deletions src/instances/tempo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,16 @@ export const tempo = Instance.define((parameters?: tempo.Parameters) => {
{
...options,
// Resolve when the process is listening via consensus engine message.
resolver({ process, reject, resolve }) {
process.stdout.on('data', (data) => {
const message = data.toString()
if (log) console.log(message)
if (message.includes('Received new payload from consensus engine') || message.includes('Received block from consensus engine'))
resolver({ process, reject, resolve }) {
process.stdout.on('data', (data) => {
const message = data.toString()
if (log) console.log(message)
if (
message.includes(
'Received new payload from consensus engine',
) ||
message.includes('Received block from consensus engine')
)
resolve()
if (message.includes('shutting down')) reject('shutting down')
})
Expand Down
47 changes: 27 additions & 20 deletions src/testcontainers/Instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
} from 'testcontainers'
import * as Instance from '../Instance.js'
import { command, type tempo as core_tempo } from '../instances/tempo.js'
import * as ContainerOptions from './containerOptions.js'

export type { Instance, InstanceOptions } from '../Instance.js'

Expand All @@ -25,6 +26,7 @@ export const tempo = Instance.define((parameters?: tempo.Parameters) => {
containerName = `tempo.${crypto.randomUUID()}`,
image = 'ghcr.io/tempoxyz/tempo:latest',
log: log_,
startupTimeout,
...args
} = parameters || {}

Expand Down Expand Up @@ -62,7 +64,9 @@ export const tempo = Instance.define((parameters?: tempo.Parameters) => {
.withEnvironment({ RUST_LOG })
.withCommand(command({ ...args, port }))
.withWaitStrategy(
Wait.forLogMessage(/Received (block|new payload) from consensus engine/),
Wait.forLogMessage(
/Received (block|new payload) from consensus engine/,
),
)
.withLogConsumer((stream) => {
stream.on('data', (data) => {
Expand All @@ -80,7 +84,9 @@ export const tempo = Instance.define((parameters?: tempo.Parameters) => {
promise.reject(new Error(`Failed to start: ${error.message}`))
})
})
.withStartupTimeout(10_000)
.withStartupTimeout(
ContainerOptions.resolveStartupTimeout(startupTimeout),
)

c.start()
.then((c) => {
Expand All @@ -100,22 +106,23 @@ export const tempo = Instance.define((parameters?: tempo.Parameters) => {
})

export declare namespace tempo {
export type Parameters = Omit<core_tempo.Parameters, 'binary'> & {
/**
* Name of the container.
*/
containerName?: string | undefined
/**
* Docker image to use.
*/
image?: string | undefined
/**
* Host the server will listen on.
*/
host?: string | undefined
/**
* Port the server will listen on.
*/
port?: number | undefined
}
export type Parameters = Omit<core_tempo.Parameters, 'binary'> &
ContainerOptions.Parameters & {
/**
* Name of the container.
*/
containerName?: string | undefined
/**
* Docker image to use.
*/
image?: string | undefined
/**
* Host the server will listen on.
*/
host?: string | undefined
/**
* Port the server will listen on.
*/
port?: number | undefined
}
}
20 changes: 20 additions & 0 deletions src/testcontainers/containerOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
export const defaults = {
startupTimeout: 10_000,
} as const

export type Parameters = {
/**
* Startup timeout (in milliseconds) for testcontainers readiness checks.
*
* Increase this when running in CI or environments with slow image pulls.
*
* @default 10_000
*/
startupTimeout?: number | undefined
}

export function resolveStartupTimeout(
startupTimeout: number | undefined,
): number {
return startupTimeout ?? defaults.startupTimeout
}
Loading