Skip to content

tests/run: fix flaky RunAttachTermination test - #5303

Merged
laurazard merged 1 commit into
docker:masterfrom
laurazard:fix-flaky-runattach-test
Jul 29, 2024
Merged

tests/run: fix flaky RunAttachTermination test#5303
laurazard merged 1 commit into
docker:masterfrom
laurazard:fix-flaky-runattach-test

Conversation

@laurazard

@laurazardlaurazard commented Jul 26, 2024

Copy link
Copy Markdown
Member

- 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 goveteven 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)

@codecov-commenter

codecov-commenter commented Jul 26, 2024

Copy link
Copy Markdown

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
Copy Markdown
MemberAuthor

@thaJeztah@vvoland can you TAL?

Comment threadcli/command/container/run_test.go Outdated

@thaJeztahthaJeztah left a comment

Copy link
Copy Markdown
Member

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

Comment threadcli/command/container/run_test.go Outdated
Comment threadcli/command/container/run_test.go Outdated
@laurazard
laurazardforce-pushed the fix-flaky-runattach-test branch from 60f51c1 to 3be9c8fCompareJuly 29, 2024 12:08

@thaJeztahthaJeztah left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@laurazard
laurazardforce-pushed the fix-flaky-runattach-test branch from 3be9c8f to 1b53d4cCompareJuly 29, 2024 12:13
@thaJeztah

Copy link
Copy Markdown
Member

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

@laurazard
laurazardforce-pushed the fix-flaky-runattach-test branch from 1b53d4c to 2290f7aCompareJuly 29, 2024 12:24
@laurazard

laurazard commented Jul 29, 2024

Copy link
Copy Markdown
MemberAuthor

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
laurazardforce-pushed the fix-flaky-runattach-test branch from 2290f7a to eac8357CompareJuly 29, 2024 12:29
@laurazard
laurazard merged commit ddd4c39 into docker:masterJul 29, 2024
@laurazard
laurazard deleted the fix-flaky-runattach-test branch July 29, 2024 12:43
Sign up for freeto 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

@laurazard@codecov-commenter@thaJeztah@vvoland