Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case with container and lots of output eventually deadlock and likely cause test to fail or cause other strange issues with test code #82

Open
manuel-koch opened this issue Apr 21, 2021 · 1 comment

Comments

@manuel-koch
Copy link

manuel-koch commented Apr 21, 2021

We have a testcase that runs multiple containers with docker-compose that create considerable output on console.

Somehow we noticed that sooner or later the test seems to run into a timeout because the applications in the container under test get stuck into deadlocks related to filled-up stdout buffers and simply don't output anything anymore and cease to function properly.

The root cause seems to be the call of the pytest-plugin ( equivalent to docker-compose up ) that doesn't read the output gathered by docker-compose and stdout/stderr buffers within containers eventually fill up, blocking any attempt to further output anything.

Here is a simple docker-compose setup and a test to show the scenario. I.e. it runs a simple busybox that outputs chunks of arbitrary strings while the pytest just runs simulating test-code for the container under test.

As stdout fills up within container, it eventually causes the output to stop, while the test is still running.

E.g. the python test looks like:

import time
import datetime

pytest_plugins = ["docker_compose"]

def test_lots_of_output(module_scoped_container_getter):
    while True:
        print(f"Test at {datetime.datetime.now()} still running...")
        time.sleep(5)
        # eventually there will be no more output from our busybox container
        # as it deadlocked because if output buffer exhaustion caused
        # by running `docker-compose up` without reading output gathered by `docker-compose up`...

docker-compose setup looks like:

version: "3.4"
services:
  busybox:
    image: busybox
    command: sh -c "while true ; do date ; cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 2048 | head -n 1 ; sleep 1 ; done"

A helper script to start the test ( it spawns docker-compose logs -f to show that container under test eventually gets stuck deadlocked ):

#!/bin/sh
( sleep 10 ; docker-compose logs -f --tail=0 ) &
pytest --capture=no --docker-compose-no-build

The only workaround for this problem that we came up is to start containers detached manually ( docker-compose up -d ) before starting pytest and executing the test functionality.

Shouldn't the pytest plugin read output of docker-compose up to prevent such filling up of buffers and eventually deadlock the containers under test ?

Used pytest-docker-compose 3.2.1

@askurihin
Copy link

Seems relevant #76

@renovate renovate bot mentioned this issue Mar 22, 2024
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants