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

Add a function-based wait strategy

Aperta
#1,559 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à
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, node.js, typescript
Ambito
backend, testing

Direzione di ricerca

Start by reading packages/testcontainers/src/wait-strategies/wait.ts and the existing strategies in packages/testcontainers/src/wait-strategies/ to understand their polling and timeout behavior. The issue depends on #1558 for passing the container to the predicate, though it notes an internal adapter could be used first. Done means a function based strategy polls until ready, treats rejected promises as not ready, and includes the last error on timeout.

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

Descrizione

enhancement minor

What happens

There is no way to say "the container is ready when this function says so". A readiness check that the built-in strategies do not cover, such as "a query succeeds" or "the topic exists", needs a class:

  • subclass StartupCheckStrategy, which receives a raw Dockerode client and a container id and returns "PENDING" | "SUCCESS" | "FAIL", or
  • implement WaitStrategy in full, including the timeout bookkeeping.

The usual alternative is to let start() return and then poll in the test with a hand-written retry loop.

Expected

A function-based strategy that is polled until it returns true, with the standard startup timeout:

const container = await new GenericContainer(image)
  .withExposedPorts(5432)
  .withWaitStrategy(
    Wait.forPredicate(async (container) => {
      const result = await container.exec(["pg_isready"]);
      return result.exitCode === 0;
    })
  )
  .start();

A rejected promise counts as "not ready yet", and the last error is included when the wait times out.

Where

  • packages/testcontainers/src/wait-strategies/wait.ts
  • a new strategy in packages/testcontainers/src/wait-strategies/

Notes

  • .NET's IWaitUntil is a single UntilAsync(IContainer) method added with AddCustomWaitStrategy. Go has wait.ForNop(func(ctx, target) error), wait.ForSQL and wait.ForExec.
  • Depends on what a strategy is given: with #1558 the predicate simply receives the container. It can be built before that by constructing the argument internally.
  • Polling must use a deterministic check from the caller. This is not a place for a sleep.

Dependencies

  • Blocked by #1558: the predicate should receive the container. It can be built first with an internal adapter if needed.
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.