-
-
Notifications
You must be signed in to change notification settings - Fork 584
feat: allow overriding the session ID #3051
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
base: main
Are you sure you want to change the base?
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hey @jcmfernandes, I am actually surprised your setup doesn't work with the current Test Session Semantics. Also, your change doesn't take the parent PID into account anymore, so it would be a breaking change for downstream integrations, that rely on the current session ID semantics. |
Thanks for getting back to me. Without these changes, every As stated in the PR description:
I'm happy to revert those changes, but so far, setting the session ID myself (through an env var) has been the only solution that worked for me. |
Alright, that is how it is supposed to work. Either way, the semantics around sessions IDs and cleanup behavior are fairly involved. I'd suggest to not proceed with this work without specifically syncing with @mdelapenya and @stevenh on the design. |
Thanks for the pointers. @mdelapenya and @stevenh, your input is very much welcome.
I am using a reusable container, and the container was always reused as expected; no issues there. The problem is that the reaper isn't reused because the session ID keeps changing. |
I pushed a new commit that brings back the logic I had previously removed. This shouldn't break things for anyone anymore. |
|
Hi @jcmfernandes can you clarify to me the problem you're trying to solve? Your description seems to indicate to me you want to share containers between tests due to the slow startup time? |
Hi @stevenh! Correct. In other words, I want:
Copying from #2804, this is what I see when I enable reusable containers:
I want to see one reaper for the reusable container. As a side effect, having one reaper creates a “rolling window” behavior, where the reaper resets its timeout upon a new connection to the container, which is precisely what I would like to see: keep the container up and running between test runs and terminate it after the defined period of inactivity. Am I making sense? |
|
Oh yes, that makes absolutely sense and I believe this is more of a bug and something that Testcontainers should already handle correctly, rather than having a user to specify a session id manually. |
|
Thanks for the confirmation @jcmfernandes. To facilitate this are you intending to set a long |
|
@stevenh yes, because I want to keep the testcontainer running for the entirety of my work session. I usually start a watcher that runs tests automatically as I save changes. I want the testcontainer to boot on the first test run and to stay around for, say, one hour, waiting for new connections. Furthermore, I then want new connections to reset that timeout. Example.
This is precisely the behavior I get by manually setting the session ID and |
|
Thanks again for the clarification, the challenge I see with that is not only does it impact the long lived container but all containers for example: You run a test which starts the long lived DB container as well a short lived test container. The desired behaviour is the DB container stays running between tests, but the test container itself exits after the test is run. However in the case where the test fails and the short lived contain didn't exit as expected, with a standard ryuk setup this wouldn't be an issue as the test container would be quickly cleaned up, but with Does this make sense? To handle this situation properly I think we'd need more fine grained control of when specific containers are cleaned up. |
|
Thanks for the prompt reply, @stevenh. That's a fair concern — it seems that testcontainers is missing some kind of "group" concept to which certain GC options apply. Currently, that's a "session", and this PR won't change it. That is, I don't see how this PR makes things worse regarding your concern, and it solves an actual reported issue. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jcmfernandes, thanks for opening this PR, and following-up after @kiview's comments. I'm returning today after summer break, working on the open PRs/issues in the repo.
I'm not against the changes in this PR, although it introduces some breaking changes (BCs) after removing public API functions. See my comments for that. We could avoid it offering a deprecation path when/if possible, although we sometimes introduce BCs if needed.
I'd rename the PR to feat: allow overriding the sessionID and would focus on that, only. The added value if we do this is we would also enable Bazel folks to contribute their own env var for the session ID at build time. Nevertheless, we must check how the reaper behaves in that scenario. As discussed here, it's by design that the reaper is spawned just once per test session (a shell), but it's true that the design could be inconsistent with reusable containers used in multiple shells (different session IDs). Sharing state, even in tests, is a complex thing to maintain, so we probably need a more robust design for both features: reusable containers and the reaper, and it could need dedicated work on that direction.
607c474 to
dc868e2
Compare
|
@mdelapenya thanks for your input. I modified this PR, making it focus solely on allowing devs to set the session ID, and I opened a separate PR #3269 where I delete |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm concerned calling config.Read in init could have some unintended side effects which are impossible to address, something we'll need to confirm.
internal/core/bootstrap.go
Outdated
| const sessionIDPlaceholder = "testcontainers-go:%d:%d" | ||
|
|
||
| func init() { | ||
| cfg := config.Read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mdelapenya could calling config.Read() in init cause undesired behaviour due to how early it called?
I'm thinking this would prevent things like changing the environment variables in a test from having the desired effect as an example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the feedback, @stevenh. I understand your concern: reading the config in an init() function felt wrong.
I change the code so that config.Read falls back to the session in core/bootstrap (I moved bootstrap.go to a new package to avoid import cycle between internal/config and internal/core). Please let me know what you think.
What does this PR do?
Makes the session ID configurable, allowing for long-running sessions.
Why is it important?
Speaking of my use-case, Apache Pulsar takes a long time to boot, so I wanted testcontainers to boot it up, eventually take it down, but allow me to use the same container across several runs. This wasn't the case, since I was getting a new reaper running on every test run. I wanted a rolling-window behavior, hence this change.
Related issues
reuseWindowfor cleaning up reusable containers if no tests run within a certain duration #2804Follow-ups
Update the documentation.