Skip to content
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

tests: Handle some failures when using -race #739

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

3v1n0
Copy link
Collaborator

@3v1n0 3v1n0 commented Jan 17, 2025

See commits for details.

Close: #703

UDENG-5710

@3v1n0 3v1n0 requested a review from a team as a code owner January 17, 2025 18:34
@3v1n0 3v1n0 force-pushed the some-goraces-handling branch from 342d4e1 to 3b403b0 Compare January 17, 2025 18:36
@codecov-commenter
Copy link

codecov-commenter commented Jan 17, 2025

Codecov Report

Attention: Patch coverage is 62.50000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 83.07%. Comparing base (36511cd) to head (6c1bf10).
Report is 214 commits behind head on main.

Files with missing lines Patch % Lines
pam/tools/pam-runner/pam-runner.go 0.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #739      +/-   ##
==========================================
- Coverage   83.43%   83.07%   -0.37%     
==========================================
  Files          83       96      +13     
  Lines        8689     9585     +896     
  Branches       74       74              
==========================================
+ Hits         7250     7963     +713     
- Misses       1111     1238     +127     
- Partials      328      384      +56     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Comment on lines +319 to +321
if !testutils.IsRace() || raceLog == "" {
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

That means we ignore go test exiting with a non-zero exit code if the race logfile is empty, right? Is that what we want?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it also means we ignore any error if go test is not run with -race

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

However, we also fail on that line if we "ignored" the error in checkDataRace, right? What's the purpose of checkDataRace then?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No, in case we detected the race, we're skiping the test... And Skip implies skipNow, thus no further checks will happen and we'll just go through the cleanups.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, I see. Do you mind making that a bit clearer in the code?

diff --git a/pam/integration-tests/vhs-helpers_test.go b/pam/integration-tests/vhs-helpers_test.go
index a9dd7c6b..ace4bada 100644
--- a/pam/integration-tests/vhs-helpers_test.go
+++ b/pam/integration-tests/vhs-helpers_test.go
@@ -336,14 +336,14 @@ func checkDataRace(t *testing.T, raceLog string) {
 		// https://github.com/charmbracelet/bubbletea/issues/909
 		// We can't do much here, as the workaround will likely affect the
 		// GUI behavior, but we ignore this since it's definitely not our bug.
-		defer t.Skip("This is a very well known bubble tea bug (#909), ignoring it")
 		if testutils.IsVerbose() {
 			t.Logf("Ignored bubbletea race:\n%s", out)
-			return
+		} else {
+			fmt.Fprintf(os.Stderr, "Ignored bubbletea race:\n%s", out)
 		}
 
-		fmt.Fprintf(os.Stderr, "Ignored bubbletea race:\n%s", out)
-		return
+		// This stops the execution of the test
+		t.Skip("This is a very well known bubble tea bug (#909), ignoring it")
 	}
 
 	t.Fatalf("Got a GO Race on vhs child:\n%s", out)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've been taught here that using else is evil, thus the convolution :) but if you like it better...

Copy link
Contributor

Choose a reason for hiding this comment

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

I've been taught here that using else is evil

As a rule of thumb I agree, but if it hurts clarity (like it in this case) I very much prefer clarity

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've just dropped the logging, since it would happen still via skip, FWIW... And CI will include it.


if testutils.IsRace() && strings.Contains(got, "WARNING: DATA RACE") &&
strings.Contains(got, "bubbles/cursor.(*Model).BlinkCmd.func1") {
if strings.Contains(out, "bubbles/cursor.(*Model).BlinkCmd.func1") {
Copy link
Contributor

Choose a reason for hiding this comment

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

does each race logfile only contain one race? if not, we might ignore other detected races here if it happens in the same run as this well known race.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No the log file contains all the races logs it detects AFAIK... Here i wanted to preserve the same behavior we had before.

Indeed, ideally we should parse it and still fail in case some other kind of race is detected, but I didn't want to go too far...

Copy link
Contributor

Choose a reason for hiding this comment

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

Here i wanted to preserve the same behavior we had before.

Fair enough, but then let's add a // TODO comment

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

@3v1n0 3v1n0 force-pushed the some-goraces-handling branch 2 times, most recently from 74f8df0 to f6d13c8 Compare January 20, 2025 15:52
3v1n0 added 3 commits January 20, 2025 16:58
Errno may be accessed by other code during the go execution, breaking
our assumptions.

So let's test that our code is race-free by using a test variable
instead.
…vhs output

Since the introduction of the VHS wait feature we may get the data race
output as VHS error, so let's handle it earlier if vhs process fails.

We still keep the check in the golden file, as we may still get a race
output after a successful Wait.

Closes: ubuntu#703
We were relying on the process output to check on data races, while Go allows
us to write the race content
@3v1n0 3v1n0 force-pushed the some-goraces-handling branch from f6d13c8 to 6c1bf10 Compare January 20, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Data race in pam/integration-tests
3 participants