-
-
Notifications
You must be signed in to change notification settings - Fork 511
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
feat: expose functions for resource clean up in tests and examples #2738
Conversation
✅ Deploy Preview for testcontainers-go ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
931b868
to
657e42c
Compare
@mdelapenya sorry about the size of this one, no easy way to get around it. A good amount of the files are just go.mod / go.sum changes, but will still be a long review I'm afraid. |
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.
Excellent work, changes consistently applied across the codebase. Thanks for making reviews that easy 🙇
I added a few minor comments, but LGTM. I will basically accept the PR, just want some clarification on those points.
BTW, I've resolved the conflicts manually |
Never mind: I updated it |
@stevenh there is one error in a testable example for the registry module. I think we messed up something in the fmt prints. |
124cf30
to
670f7eb
Compare
Just ran the tests locally, no errors, will keep an eye on the CI. go test -timeout 10m -coverprofile=/tmp/vscode-goDlE8R3/go-code-cover github.com/testcontainers/testcontainers-go/modules/registry -v -count=1
=== RUN TestRegistry_unauthenticated
2024/09/10 22:32:28 github.com/testcontainers/testcontainers-go - Connected to docker:
Server Version: 27.1.1
API Version: 1.46
Operating System: Docker Desktop
Total Memory: 31947 MB
...
2024/09/10 22:32:41 🚫 Container terminated: e46301df078f
--- PASS: ExampleRun_pushImage (3.84s)
PASS
coverage: 79.7% of statements
ok github.com/testcontainers/testcontainers-go/modules/registry 12.630s coverage: 79.7% of statements |
670f7eb
to
c6e53c5
Compare
thanks for a very through review on such a big PR @mdelapenya. I've made 90% of the changes, resolving the comments that match, there's a few questions outstanding, but getting close. |
c6e53c5
to
1574d2b
Compare
@stevenh I'm marking this PR as an |
Ensure that all resources are cleaned up for tests and examples even if they fail. This leverages new helpers in testcontainers: * TerminateContainer for examples * CleanupContainer and CleanupNetwork for tests These are required ensuring that containers that are created but fail in later actions are returned alongside the error so that clean up can be performed. Consistently clean up created networks using a new context to ensure that the removal gets run even if original context has timed out or been cancelled. Use fmt.Print instead of log.Fatal to ensure that defers are run in all examples again ensuring that clean up is processed. Call Stop from Terminate to ensure that child containers are shutdown correctly on clean up as the hard coded timeout using by ContainerRemove is too short to allow this to happen correctly. Clean up of test logic replacing manual checks and asserts with require to make them more concise and hence easier to understand. Quiet test output by either capturing or disabling output so it's easier to identify issues when tests are run in non verbose mode. Clarify source of errors with wrapping and update tests to handle. Ensure that port forwarding container is shutdown if an error occurs during setup so it isn't orphaned. Shutdown the port forwarding container on both stop and terminate to prevent it being orphaned when the Stop is used. Add missing error checks to tests. Remove unused nolint directives and enable the nolintlint to catch any regressions. Don't use container as a variable as its overused.
1574d2b
to
e04735e
Compare
@mdelapenya I think this should be good, just two open discussion points which I don't think are blockers. |
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.
LGTM, great PR 🙇
* main: fix: resource clean up for tests and examples (#2738)
* main: fix: resource clean up for tests and examples (testcontainers#2738) ci: add generate for mocks (testcontainers#2774) fix: docker config error handling when config file does not exist (testcontainers#2772)
* main: chore: use a much smaller image for testing (testcontainers#2795) fix: parallel containers clean race (testcontainers#2790) fix(registry): wait for (testcontainers#2793) fix: container timeout test (testcontainers#2792) docs: document redpanda options (testcontainers#2789) feat: support databend module (testcontainers#2779) chore: golangci-lint 1.61.0 (testcontainers#2787) fix(mssql): bump Docker image version (testcontainers#2786) fix: handle 127 error code for podman compatibility (testcontainers#2778) fix: do not override ImageBuildOptions.Labels when building from a Dockerfile (testcontainers#2775) feat(mongodb): Wait for mongodb module with a replicaset to finish (testcontainers#2777) fix(postgres): Apply default snapshot name if no name specified (testcontainers#2783) fix: resource clean up for tests and examples (testcontainers#2738) ci: add generate for mocks (testcontainers#2774) fix: docker config error handling when config file does not exist (testcontainers#2772)
* main: chore: use a much smaller image for testing (testcontainers#2795) fix: parallel containers clean race (testcontainers#2790) fix(registry): wait for (testcontainers#2793) fix: container timeout test (testcontainers#2792) docs: document redpanda options (testcontainers#2789) feat: support databend module (testcontainers#2779) chore: golangci-lint 1.61.0 (testcontainers#2787) fix(mssql): bump Docker image version (testcontainers#2786) fix: handle 127 error code for podman compatibility (testcontainers#2778) fix: do not override ImageBuildOptions.Labels when building from a Dockerfile (testcontainers#2775) feat(mongodb): Wait for mongodb module with a replicaset to finish (testcontainers#2777) fix(postgres): Apply default snapshot name if no name specified (testcontainers#2783) fix: resource clean up for tests and examples (testcontainers#2738)
* main: (29 commits) fix: template for code generation (#2800) fix: update module path (#2797) fix: container logging deadlocks (#2791) chore: use a much smaller image for testing (#2795) fix: parallel containers clean race (#2790) fix(registry): wait for (#2793) fix: container timeout test (#2792) docs: document redpanda options (#2789) feat: support databend module (#2779) chore: golangci-lint 1.61.0 (#2787) fix(mssql): bump Docker image version (#2786) fix: handle 127 error code for podman compatibility (#2778) fix: do not override ImageBuildOptions.Labels when building from a Dockerfile (#2775) feat(mongodb): Wait for mongodb module with a replicaset to finish (#2777) fix(postgres): Apply default snapshot name if no name specified (#2783) fix: resource clean up for tests and examples (#2738) ci: add generate for mocks (#2774) fix: docker config error handling when config file does not exist (#2772) docs: refine heading badges in README (#2770) feat(wait): for file (#2731) ...
Ensure that all resources are cleaned up for tests and examples even if they fail.
This leverages new helpers in testcontainers:
TerminateContainer
for examplesCleanupContainer
andCleanupNetwork
for testsThese are required ensuring that containers that are created but fail in later actions are returned alongside the error so that clean up can be performed.
Consistently clean up created networks using a new context to ensure that the removal gets run even if original context has timed out or been cancelled.
Use
fmt.Print
instead oflog.Fatal
to ensure that defers are run in all examples again ensuring that clean up is processed.Call
Stop
fromTerminate
to ensure that child containers are shutdown correctly on clean up as the hard coded timeout using byContainerRemove
is too short to allow this to happen correctly.Clean up of test logic replacing manual checks and asserts with require to make them more concise and hence easier to understand.
Quiet test output by either capturing or disabling output so it's easier to identify issues when tests are run in non verbose mode.
Clarify source of errors with wrapping and update tests to handle.
Ensure that port forwarding container is shutdown if an error occurs during setup so it isn't orphaned.
Shutdown the port forwarding container on both stop and terminate to prevent it being orphaned when the
Stop
is used.Add missing error checks to tests.
Remove unused
nolint
directives and enable thenolintlint
to catch any regressions.