-
Notifications
You must be signed in to change notification settings - Fork 8
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
Clean up TestContext
when pack build unexpectedly succeeds
#588
Conversation
Moves the creation of the `TestContext` to before the invocation of `run_pack_command` so that the context will be cleaned up regardless of the outcome. @fixes #586
Moves the creation of the `TestContext` to before the invocation of `run_pack_command` so that the context will be cleaned up regardless of the outcome. @fixes #586
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.
Your PR looks good in terms of I think it does what it says it does. I'm wanting to make it so that it doesn't regress in the future i.e. if someone were to re-order the commands in a future PR tests wouldn't fail.
That's the "changes requested": To encode the fix in the build/test logic (through tests, types, or both).
We could (brainstorm):
- Add a test for this explicit behavior (probably hard and/or expensive)
- Couple
run_pack_command
with needing aTestContext
(even if it's not used) to force it's creation before it's run or possibly introduce another function - Move the creation of the TestContext to the same location that allocates the resource (RAII)
- Couple the creation of the image name with the creation of something that tears it down.
Ideally I want to move the logic closest to where the resource is allocated. In this case we decouple creating an image name from allocating/generating that image (via pack). I'm proposing to couple the teardown logic of the image name along with image name creation so then there's never a scenario where one would be created and not torn down.
Sketch
- Introduce a
ImageName
struct that holds, well, an image name. - Have
util::random_docker_identifier()
return this new struct instead of a string - Move the drop logic to this struct
ImageName
struct - Add a new field to TestContext to hold an ImageName
Now when TestContext
is dropped it will drop it's contents and call drop on ImageName
triggering the cleanup (existing behavior is preserved). And since ImageName
is allocated before run_pack_command
is ever called, if it fails then ImageName
drop behavior will be called (new behavior).
This assumes that the drop logic is a no-op if an image name has not been created in docker.
Co-authored-by: Manuel Fuchs <manuel.fuchs@salesforce.com>
@Malax No #619 does not fix this directly, though it does give more options here as to how to fix this issue. It seems the options here now are to:
I think my preference is for option (1) or (2). Thoughts? |
I would vote for option 1 here. I find |
Works for me! I've opened #625. |
#625) Previously, if a test with an expected result of `PackResult::Failure` unexpectedly succeeded, the built app image was left behind since cleanup was only performed in `TestContext::Drop` (and in this scenario, a `TestContext` is never created in the first place). Now the app image is correctly cleaned up. Fixes #586. Closes #588. GUS-W-13903181.
Moves the creation of the
TestContext
to before the invocation ofrun_pack_command
so that the context will be cleaned up regardless of the outcome.@fixes #586