Skip to content

Simplify log-wait-strategy #977

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

Merged

Conversation

danielbodart
Copy link
Contributor

@danielbodart danielbodart commented Apr 5, 2025

This pull request simplifies the log-wait-strategy in a number of ways:

  • Replaces all callbacks with async code
  • Separates concerns of timeout and log processing
  • Starts timeout immediately so that if Docker/dockerode is slow it will still timeout in the correct amount of time
  • Removes bylines dependency
  • 95% of all consoles will buffer by line anyway
  • More flexible as it could allow a regex across multiple lines when need
  • Minor performance improvement
  • Bonus 20% less code

I'd also argue that it is a lot easier to read!

Copy link

netlify bot commented Apr 5, 2025

Deploy Preview for testcontainers-node ready!

Name Link
🔨 Latest commit f5231e1
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-node/deploys/67f35f20bcce78000867356e
😎 Deploy Preview https://deploy-preview-977--testcontainers-node.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Apr 5, 2025

The refactor looks great! Looks like a test is failing just because the LogWaitStrategy failure message has changed.

One Q: I'm pretty sure that removing byline can result in an intermittent issue. E.g let's say we're looking for the message "Started successfully!". It's possible we get that message in 2 chunks, e.g "Started" and " successfully!". Without buffering into a single line we would not match the message.

@cristianrgreco cristianrgreco added maintenance Improvements that do not change functionality patch Backward compatible bug fix labels Apr 5, 2025
@danielbodart
Copy link
Contributor Author

I'll fix the tests when I'm back at my PC later

@danielbodart
Copy link
Contributor Author

The message should be exactly the same so I'll fix that.

On the bylines side, I'd argue for an actual example/real use case. Even if you do echo -n, the shell will buffer the output by line, same with python and node I believe.

The only real world example I have seen in the wild is with binary outputs and you don't need new lines

Even if you did need it, you don't need a library to do it. with an iterator it's a couple of lines of code at worst, so less lines of code than using that library!

@danielbodart
Copy link
Contributor Author

Hey @cristianrgreco I've added tests for both the message not being found and also for if the content is not sent in a single line and they all pass (without need to bylines). Please have a look and let me know what you think?

@danielbodart
Copy link
Contributor Author

So I readded byline even though the test passes with or without it

@cristianrgreco
Copy link
Collaborator

cristianrgreco commented Apr 6, 2025

The changes LGTM. I had a doubt about removing the stream.destroy(), IIRC it resulted in some open handles reported by Jest, but I cannot reproduce that anymore. As all the tests are passing as well it doesn't seem necessary.

Are there any other changes you wanna make or are we good to merge?

@danielbodart
Copy link
Contributor Author

Good from me!

@danielbodart danielbodart force-pushed the dwb-simplify-log-wait-strategy branch from 660fc5b to f5231e1 Compare April 7, 2025 05:14
@cristianrgreco cristianrgreco merged commit b837e90 into testcontainers:main Apr 7, 2025
249 checks passed
cristianrgreco added a commit that referenced this pull request Apr 10, 2025
cristianrgreco added a commit that referenced this pull request Apr 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
maintenance Improvements that do not change functionality patch Backward compatible bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants