[27.x backport] tests/run: fix flaky RunAttachTermination test
#5326
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RunAttachTerminationtest #5303- What I did
This test was just incorrect (and testing incorrect behavior): it was checking that
docker runexited with acontext cancelederror after signalling the CLI/cancelling the command's context, but this was incorrect (and was fixed in991b130 - which was when this test started failing).
However, since this test assertion was happening inside of a goroutine, it would sometimes pass if it didn't get to run before the test suite terminated. It was flaky because sometimes the assertion inside the goroutine did get to execute, but after the test finished execution, which is a big no-no.
As an aside, assertions inside goroutines are generally bad, and
goveteven has a check for this (but it only catchest.Fatalandt.FailNowcalls and notassert.Xx).- How I did it
Fixed
RunAttachTerminationto test for the correct behavior, and generally cleaned the tests up a bit. Also added another test for the general/not SIGINT'ed case.- How to verify it
go test -v -count=1 -run=TestRunAttach ./cli/command/container/...- Description for the changelog
- A picture of a cute animal (not mandatory but encouraged)