testcontainers / testcontainers/testcontainers-python

Feature: Timeout on command execution

Ouverte
#972 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

🚀 enhancement
Langage dominant
Python
Étoiles
2.3k
Forks
386
Merge moyen
4 h 40 min
PR mergées (30 j)
1

Description

What are you trying to do?

The DockerContainer.exec() method does not support a timeout parameter, even though the documentation explicitly describes this functionality:

with GenericContainer("alpine:latest") as container:
    try:
        exit_code, output = container.exec(
            ["sleep", "10"],
            timeout=5  # Timeout in seconds
        )
    except TimeoutError:
        print("Command timed out")

However, the actual implementation simply forwards to docker-py's exec_run without accepting any additional keyword arguments:

def exec(self, command: Union[str, list[str]]) -> ExecResult:
    if not self._container:
        raise ContainerStartException("Container should be started before executing a command")
    return self._container.exec_run(command)

We'd like exec() to support a timeout so that commands that hang or take too long don't block test runs indefinitely.

Why should it be done this way?

Without a timeout, any exec() call that hangs (e.g. a command waiting on a resource that never becomes available) will block the test process forever with no way to recover other than killing the process externally.

Unfortunately this isn't a simple pass through - the underlying docker-py Container.exec_run() also does not expose a timeout parameter. So this would need a client-side implementation, for example wrapping the call with concurrent.futures.ThreadPoolExecutor and a deadline, or using exec_run(socket=True) with a socket-level timeout.

Just like the timeout for a subprocess.run run doesn't guarantee closing the process after the timeout, so will this.

I'm happy to open a PR for this, but wanted to gain agreement on the issue first before submitting code.

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Piste de recherche

Commencez par DockerContainer.exec et docs/features/executing_commands.md, puis comparez l’exemple de timeout documenté avec docker-py Container.exec_run et ses limitations. C’est terminé lorsque exec() accepte un timeout, lève TimeoutError lorsque le délai est dépassé et ne laisse pas le test run bloqué indéfiniment.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
docker, python
Domaine
devops, testing
Type d'issue
Fonctionnalité
Difficulté
4/5
Temps estimé
3-5 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
42/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.