Skip to content

Support AbortSignal in start(), exec and other long-running calls #1560

Open

Description

@cristianrgreco

What happens

Nothing in the API accepts an AbortSignal.

  • start() can spend minutes pulling an image and waiting for readiness. When the test runner times the test out, or the user gives up, the start carries on in the background. The container is still created and stays until Ryuk removes it at process exit.
  • The only timeout is the wait strategy's startup timeout. It does not cover the image pull.
  • exec has no timeout and cannot be cancelled, so a command that hangs blocks its caller indefinitely.
  • DockerComposeEnvironment.up() and GenericContainerBuilder.build() are the same.

Expected

Long-running operations take a signal:

await new GenericContainer(image).start({ signal: AbortSignal.timeout(30_000) });
await container.exec(["pg_dump"], { signal });

On abort the promise rejects with the signal's reason, and whatever was half-created (container, network attachment, Compose project) is stopped and removed.

Where

  • start and startContainer in packages/testcontainers/src/generic-container/generic-container.ts
  • pull and build in packages/testcontainers/src/container-runtime/clients/image/docker-image-client.ts
  • packages/testcontainers/src/wait-strategies/*.ts
  • exec in packages/testcontainers/src/container-runtime/clients/container/docker-container-client.ts
  • up in packages/testcontainers/src/docker-compose-environment/docker-compose-environment.ts

Notes

Dependencies

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestminorBackward compatible functionality

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions