Skip to content

Conversation

@laurazard
Copy link
Collaborator

@laurazard laurazard commented Jul 26, 2024

- What I did

This test was just incorrect (and testing incorrect behavior): it was checking that docker run exited with a context canceled error after signalling the CLI/cancelling the command's context, but this was incorrect (and was fixed in
991b130 - 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 govet even has a check for this (but it only catches t.Fatal and t.FailNow calls and not assert.Xx).

- How I did it

Fixed RunAttachTermination to 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)

@laurazard laurazard requested review from thaJeztah and vvoland July 26, 2024 14:08
@codecov-commenter
Copy link

codecov-commenter commented Jul 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 61.45%. Comparing base (826fc32) to head (eac8357).
Report is 8 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5303      +/-   ##
==========================================
- Coverage   61.45%   61.45%   -0.01%     
==========================================
  Files         299      299              
  Lines       20856    20855       -1     
==========================================
- Hits        12818    12816       -2     
- Misses       7122     7124       +2     
+ Partials      916      915       -1     

@laurazard
Copy link
Collaborator Author

@thaJeztah @vvoland can you TAL?

Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall LGTM; left two comments / questions

@laurazard laurazard force-pushed the fix-flaky-runattach-test branch from 60f51c1 to 3be9c8f Compare July 29, 2024 12:08
@laurazard laurazard requested review from thaJeztah and vvoland July 29, 2024 12:08
Copy link
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@laurazard laurazard force-pushed the fix-flaky-runattach-test branch from 3be9c8f to 1b53d4c Compare July 29, 2024 12:13
@thaJeztah
Copy link
Member

oh! LOL, I saw failures, and see you just pushed - probably need to remove the import as well

@laurazard laurazard force-pushed the fix-flaky-runattach-test branch from 1b53d4c to 2290f7a Compare July 29, 2024 12:24
@laurazard
Copy link
Collaborator Author

laurazard commented Jul 29, 2024

Turns out the version was set for a reason. I added a comment.

Edit: aaahh I commented the wrong SHA. I'll fix it.

This test was just incorrect (and testing incorrect
behavior): it was checking that `docker run` exited with a `context
canceled` error after signalling the CLI/cancelling the command's
context, but this was incorrect (and was fixed in
991b130 - which was when this test
started failing).

However, since this test assertion was happening inside of a goroutine,
it would sometimes pass if this assertion didn't get to run before the
test suite terminated. It was flaky because sometimes this 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 `govet`
even has a linter for this (but it only catches `t.Fatal` and `t.FailNow`
calls and not `assert.Xx`.

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
@laurazard laurazard force-pushed the fix-flaky-runattach-test branch from 2290f7a to eac8357 Compare July 29, 2024 12:29
@laurazard laurazard merged commit ddd4c39 into docker:master Jul 29, 2024
@laurazard laurazard deleted the fix-flaky-runattach-test branch July 29, 2024 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants