testcontainers-go
                                
                                 testcontainers-go copied to clipboard
                                
                                    testcontainers-go copied to clipboard
                            
                            
                            
                        [Bug]: Multiple core.SessionId values for test runs under tools like Bazel
Testcontainers version
0.31.0
Using the latest Testcontainers version?
Yes
Host OS
n/a
Host arch
n/a
Go version
n/a
Docker version
n/a
Docker info
n/a
What happened?
Symptom: Many (10+ in my case) reapers are getting spawned for a single testcontainer when running tests across a Bazel monorepo with rules_go. This causes the single testcontainer to get preemptively reaped while tests are running, yielding test failures.
Background I've got a lot of tests in a monorepo that are set up to use testcontainers-go to launch a postgres container. The postgres container is assigned a fixed name "testcontainers-postgres" and runs a series of setup migrations. Everything works fine when running individual tests targets under Bazel. However, when running multiple test targets, multiple reapers are getting spawned for the shared testcontainer. The test are being ran locally (no remote execution) on a single machine.
Digging in further it seems that testcontainer-go's sessionId logic doesn't work well for tests ran under Bazel. It assumes that the parent process is the same across all test runner processes.
We can't safely make assumptions about the Bazel process hierarchy-- it's probably different across platforms, sandboxing modes, sandboxing implementations, and remote/local execution. Bazel also doesn't offer any information to the test process that could be used as a test run session id (see Bazel's test encyclopedia for info on what is available).
Fixes
Could we provide a way for users to manually override the session ID before creating containers? I've tested this approach and it works perfectly for resolving the issue under Bazel.
Relevant log output
No response
Additional information
No response