Bug: LogMessageWaitStrategy argument 'times' does not affect wait logic (unused)

Open
#1,137 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, python
Domain
testing

Research direction

The report identifies LogMessageWaitStrategy in testcontainers.core.wait_strategies and provides a reproducer using DockerContainer. Start by reading the wait strategy and its tests, then run the reproducer with times=2. Done means the container keeps waiting until the message appears twice; the issue links PR #1136, so work may already be underway.

Written by the indexing model from the issue text.

Description

Describe the bug

When using LogMessageWaitStrategy(message='hi', times=2) I expect containers to wait until 'hi' has occurred twice in the logs. Instead, containers wait until 'hi' has occurred once. I.e., the times argument is unused.

I confirmed this in the code, once a single search for the provided message succeeds the waiting ends.

To Reproduce

from testcontainers.core.container import DockerContainer
from testcontainers.core.wait_strategies import LogMessageWaitStrategy

BUG_IF_MISSING = 'bug if missing'
WAIT_MARKER = 'marker'

SCRIPT = f'''/bin/sh -c "echo '{WAIT_MARKER}' && sleep 10 && echo '{BUG_IF_MISSING}' && echo '{WAIT_MARKER}'"'''

with (
    DockerContainer(image='alpine:latest')
            .with_command(SCRIPT)
            .waiting_for(LogMessageWaitStrategy(message=WAIT_MARKER, times=2)) as container
):
    stdout, _ = container.get_logs()
    if not BUG_IF_MISSING in stdout.decode():
        raise AssertionError(f'"{BUG_IF_MISSING}" not found in stdout of container but waiting finished')

Suggested fix
I'm not sure if it's OK to include a PR with bug reports, but just in case it's OK: https://github.com/testcontainers/testcontainers-python/pull/1136

Runtime environment

Provide a summary of your runtime environment. Which operating system, python version, and docker version are you using? What is the version of testcontainers-python you are using? You can run the following commands to get the relevant information.

# Get the operating system information (on a unix os).
$ uname -a
# Get the python version.
$ python --version
# Get the docker version and other docker information.
$ docker info
# Get all python packages.
$ pip freeze
Linux desktop 7.1.1-76070101-generic #202606191302~1782222967~22.04~dfed2f1 SMP PREEMPT_DYNAMIC Tue J x86_64 x86_64 x86_64 GNU/Linux
Python 3.10.12
Client: Docker Engine - Community
 Version:    29.9.1
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.38.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v5.6.0
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 10
  Running: 0
  Paused: 0
  Stopped: 10
 Images: 73
 Server Version: 29.9.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: b7a25261e029d68978bbf290df0a62fc819b3c51
 runc version: v1.5.2-0-g29dd3dc2
 init version: de40ad0
 Security Options:
  apparmor
   Profile: default
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 7.1.1-76070101-generic
 Operating System: Pop!_OS 22.04 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 32
 Total Memory: 31.25GiB
 Name: desktop
 ID: 0f4fa007-9e64-4716-9218-e7273377271d
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
  ::1/128
 Live Restore Enabled: false
 Firewall Backend: iptables
  EnableUserlandProxy: true
  UserlandProxyPath: /usr/bin/docker-proxy

arandr==0.1.10
argcomplete==1.8.1
Babel==2.8.0
bcc==0.18.0
beautifulsoup4==4.10.0
blessings==1.7
blinker==1.4
bpython==0.22.1
Brlapi==0.8.3
CacheControl==0.12.10
cachetools==5.3.0
cachy==0.3.0
certifi==2020.6.20
chardet==4.0.0
charset-normalizer==2.1.1
chrome-gnome-shell==0.0.0
cleo==0.8.1
click==8.0.3
clikit==0.6.2
colorama==0.4.4
colour==0.1.5
command-not-found==0.3
crashtest==0.3.1
cryptography==3.4.8
cupshelpers==1.0
curtsies==0.3.10
cwcwidth==0.1.6
daemonize==2.5.0
dbus-python==1.2.18
defer==1.0.6
distlib==0.3.4
distro==1.7.0
evdev==1.4.0
fail2ban==0.11.2
fasteners==0.14.1
filelock==3.6.0
flake8==4.0.1
google-api-core==2.11.0
google-api-python-client==2.83.0
google-auth==2.17.1
google-auth-httplib2==0.1.0
googleapis-common-protos==1.59.0
greenlet==1.1.2
guake==3.8.5
hidpidaemon==18.4.6
html5lib==1.1
httplib2==0.20.2
idna==3.3
importlib-metadata==4.6.4
jedi==0.18.0
jeepney==0.7.1
Jinja2==3.0.3
kernelstub==3.1.4
keyring==23.5.0
language-selector==0.1
launchpadlib==1.10.16
lazr.restfulclient==0.14.4
lazr.uri==1.0.6
livereload==2.6.3
lockfile==0.12.2
louis==3.20.0
lxml==4.8.0
macaroonbakery==1.3.1
Mako==1.1.3
Markdown==3.3.6
MarkupSafe==2.0.1
mccabe==0.6.1
mkdocs==1.1.2
monotonic==1.6
more-itertools==8.10.0
msgpack==1.0.3
netaddr==0.8.0
netifaces==0.11.0
notify2==0.3
numpy==1.21.5
oauth2client==4.1.3
oauthlib==3.2.0
olefile==0.46
packaging==21.3
parso==0.8.1
pastel==0.2.1
pbr==5.8.0
pexpect==4.8.0
Pillow==9.0.1
pipx==1.0.0
pkginfo==1.8.2
platformdirs==2.5.1
poetry==1.1.12
poetry-core==1.0.7
pop-transition==1.1.2
protobuf==4.22.1
psutil==5.9.0
ptyprocess==0.7.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycairo==1.21.0
pycodestyle==2.8.0
pycups==2.0.1
pydbus==0.6.0
PyDrive==1.3.1
pyflakes==2.4.0
Pygments==2.11.2
PyGObject==3.42.2
pyinotify==0.9.6
PyJWT==2.3.0
pylev==1.2.0
pymacaroons==0.13.0
PyNaCl==1.5.0
pyOpenSSL==21.0.0
pyparsing==2.4.7
pyperclip==1.8.2
PyQt5==5.15.6
PyQt5-sip==12.9.1
PyQtWebEngine==5.15.5
pyRFC3339==1.1
python-apt==2.4.0+ubuntu4.1
python-debian==0.1.43+ubuntu1.1
python-gnupg==0.4.8
python-xlib==0.29
pytz==2022.1
pyudev==0.22.0
pyxdg==0.27
PyYAML==5.4.1
repolib==2.2.1
repoman==1.4.0
requests==2.28.1
requests-futures==1.0.0
requests-toolbelt==0.9.1
rsa==4.9
SecretStorage==3.3.1
sessioninstaller==0.0.0
setproctitle==1.2.2
shellingham==1.4.0
six==1.16.0
soupsieve==2.3.1
SQLAlchemy==1.4.31
ssh-import-id==5.11
systemd-python==234
termcolor==2.3.0
tomlkit==0.9.2
tornado==6.1
typing-extensions==3.10.0.2
ubuntu-drivers-common==0.0.0
ubuntu-pro-client==8001
ufw==0.36.1
uritemplate==4.1.1
urllib3==1.26.5
userpath==1.8.0
virtualenv==20.13.0+ds
wadllib==1.3.6
watchdog==2.1.6
webencodings==0.5.1
WoeUSB-ng==0.2.12
wxPython==4.0.7
xdg==5
xkit==0.0.0
zipp==1.0.0
Dominant language
Python
Stars
2.3k
Forks
397
Avg merge
8d 16h
Merged PRs (30d)
5

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from testcontainers/testcontainers-python

All issues in testcontainers/testcontainers-python

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.