Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Pass the started container to `WaitStrategy.waitUntilReady`

未关闭
#1,558 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
45/100
Issue 类型
重构
描述清晰度
描述清楚
活跃度
活跃
技术栈
docker, node.js, typescript

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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.
主要语言
TypeScript
星标
2.6k
派生
274
平均合并
1 天 14 小时
30 天内合并 PR
44

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

testcontainers/testcontainers-node 的其他 Issue

查看 testcontainers/testcontainers-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。