Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Pass the started container to `WaitStrategy.waitUntilReady`

Aperta
#1,558 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
45/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, node.js, typescript

Direzione di ricerca

Start with packages/testcontainers/src/wait-strategies/wait-strategy.ts and inspect every strategy in packages/testcontainers/src/wait-strategies/, then trace the listed callers in generic-container.ts, started-generic-container.ts and docker-compose-environment.ts. Check the start() and restart() paths, including how the log strategy receives startTime, and review the coordination issues before changing the shared signatures. Done means strategies receive the started container or a suitable target, callers and custom strategy examples are updated, and the startup deadline and abort signal have a defined place in the interface.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

enhancement major

What happens

A wait strategy is handed the low-level pieces instead of the container:

export interface WaitStrategy {
  waitUntilReady(container: Dockerode.Container, boundPorts: BoundPorts, startTime?: Date): Promise<void>;
  withStartupTimeout(startupTimeoutMs: number): WaitStrategy;
  isStartupTimeoutSet(): boolean;
  getStartupTimeout(): number;
}

To do anything useful, an implementation has to fetch the rest itself. The six built-in strategies each call getContainerRuntimeClient() to find the host, read logs or run a command. A custom strategy needs Dockerode knowledge to do what StartedTestContainer already offers as getHost(), getMappedPort(), exec() and logs(). The documented route for custom strategies, StartupCheckStrategy.checkStartupState(dockerClient: Dockerode, containerId: string), has the same shape.

It also makes strategies awkward to reuse on a container that is already started. CouchbaseContainer rebuilds the arguments by hand to run an HTTP wait:

Wait.forHttp("/pools", PORTS.MGMT_PORT)
  .forStatusCode(200)
  .waitUntilReady(
    client.container.getById(startedTestContainer.getId()),
    BoundPorts.fromInspectResult(client.info.containerRuntime.hostIps, inspectResult)
  );

Kafka and Redpanda do the same through waitForContainer.

Expected

waitUntilReady receives the container, or a narrower target interface that the started container satisfies:

interface WaitStrategy {
  waitUntilReady(container: StartedTestContainer): Promise<void>;
}
  • A module can write await Wait.forHttp("/pools", port).waitUntilReady(container).
  • A custom strategy uses container.getHost(), container.getMappedPort(port), container.exec(...) and container.logs().
  • Dockerode.Container and BoundPorts leave the public interface.

Where

  • packages/testcontainers/src/wait-strategies/wait-strategy.ts
  • every strategy in packages/testcontainers/src/wait-strategies/
  • packages/testcontainers/src/wait-strategies/wait-for-container.ts
  • callers in generic-container.ts, started-generic-container.ts and docker-compose-environment.ts

Notes

  • Java: void waitUntilReady(WaitStrategyTarget waitStrategyTarget), where WaitStrategyTarget extends ContainerState and the container itself is passed (getHost, getMappedPort, execInContainer, getLogs, getContainerInfo).
  • Go: WaitUntilReady(ctx, target StrategyTarget), with Host, Inspect, MappedPort, Logs, Exec, State and CopyFileFromContainer.
  • .NET: IWaitUntil.UntilAsync(IContainer container).
  • The wait runs before start() returns, so the started container has to exist before the wait instead of after it. restart() passes a startTime so the log strategy ignores older output; that needs a home on the target.
  • Semver: this changes the interface that custom strategies implement, hence major.
  • Whatever replaces the current arguments should have room for a startup deadline and an abort signal, so the interface changes once.

Dependencies

  • Nothing blocks this. It can start now.
  • Coordinate with #1523, #1533, #1534: small changes to the same strategy files. Land them first, since this rewrites every strategy's signature.
  • Coordinate with #1532: the same files gain typed errors.
  • Coordinate with #1582: the startup deadline needs a place in the new arguments.
Lingua principale
TypeScript
Stelle
2.6k
Fork
274
Merge medio
1g 14h
PR unite (30g)
44

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di testcontainers/testcontainers-node

Tutte le issue di testcontainers/testcontainers-node

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.