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

tester Service bug fixes (mostly around panicked test handling) #359

Merged
merged 12 commits into from
Jan 19, 2024

Conversation

jasondborneman
Copy link
Contributor

@jasondborneman jasondborneman commented Jan 16, 2024

  • Rename tests to match test func names. This makes test names in the return match the func names for easier debugging.

run_tests.go

  • Fix getStackTrace. It had a defer w.Close() that was making it hang + it needed to check for error from io.Copy
  • change wildcard filtering to use a regex instead of a glob library. This allows for return of the matched string, which in turn makes it possible to always know the true name of a test func even when filtering by wildcards

test_methods.go

  • Rework how TestAll works. Instead of calling the other goa gRPC funcs (TestLocator, TestForecaster) call runTests directly and define the collections in TestAll. This makes it so I don't have a global filtering payload var, which was causing a bug when you make a filtered TestAll call then try to make an unfiltered call (filtering not available except for TestAll) to another func like TestSmoke.

jasondborneman and others added 7 commits January 16, 2024 15:49
…#357)

Bumps [golang.org/x/tools](https://github.com/golang/tools) from 0.16.1 to 0.17.0.
- [Release notes](https://github.com/golang/tools/releases)
- [Commits](golang/tools@v0.16.1...v0.17.0)

---
updated-dependencies:
- dependency-name: golang.org/x/tools
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
)

Bumps goa.design/goa/v3 from 3.14.4 to 3.14.5.

---
updated-dependencies:
- dependency-name: goa.design/goa/v3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
`tester` : Make synch panic handling work, get name of panicked test via reflection, filter then not filtered call bug fix
Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

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

Left a few comments, the TL;DR is that It would be good to come up with a solution that does not involve reflection.

log.Infof(ctx, "RUNNING TEST [%v]", testName)
f(ctx, testCollection)
}(test, n)
Copy link
Member

Choose a reason for hiding this comment

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

The previous version was much better :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@raphael not sure I follow, I took the testName out because I am using getTestName and didn't need to pass in testName anymore to the goroutine. If I figure out how to get testName without reflection this may go back though.

}
defer recoverFromTestPanic(ctx, testNameFunc, testCollection)
for _, test := range testsToRun {
testName = getTestName(test)
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure I understand the need for getTestName. In general using reflection for a service at runtime isn't great (it's slow) and a bit of a code smell. At the very least if we were to use getTestName we could get rid of lines 218-221. But it would be much better to find a solution that does not require it. Is testsToRun not indexed by test name?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@raphael It is, but I was having trouble getting the true test name in the case of wildcard filters. I'll take some time to see if I can't rework this. If I fail to do that I may need to keep it though so that the true test name is returned, especially when there is a panic so that the exact test that is panicking can be identified

io.Copy(&buf, f) // nolint: errcheck
outC <- buf.String()
_, err := io.Copy(&buf, f)
if err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I am not sure the if is required. If the error is nil then outErr <- err works fine and if there's an error then buf.String() should return "" (buffer is empty).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK cool. I was being overly cautious. :) Will change

return out
if err := <-outErr; err != nil {
return "", err
} else {
Copy link
Member

Choose a reason for hiding this comment

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

The else is not needed.

if err != nil {
err = fmt.Errorf("error getting stack trace for panicked test: %v", err)
resultMsg := err.Error()
testCollection.AppendTestResult(&gentester.TestResult{
Copy link
Member

Choose a reason for hiding this comment

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

This could be taken out of the if (since the else does the same thing).

@jasondborneman
Copy link
Contributor Author

jasondborneman commented Jan 17, 2024

@raphael I figured it out using a regex instead of a glob. This eliminates the need for reflection. Take a look and let me know what you think.

@codecov-commenter
Copy link

codecov-commenter commented Jan 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (b5e85f7) 93.24% compared to head (eccdf28) 93.24%.

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #359   +/-   ##
=======================================
  Coverage   93.24%   93.24%           
=======================================
  Files          32       32           
  Lines        1822     1822           
=======================================
  Hits         1699     1699           
  Misses        100      100           
  Partials       23       23           
Flag Coverage Δ
micro 93.24% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

defer wg.Done()
defer recoverFromTestPanic(ctx, testName, testCollection)
log.Infof(ctx, "RUNNING TEST [%v]", testName)
testName := ""
Copy link
Member

Choose a reason for hiding this comment

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

This could be simplified to:

testNameFunc := func() string {
    return testNameRunning
}

No need for the testName variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@raphael fixed.

Copy link
Member

@raphael raphael left a comment

Choose a reason for hiding this comment

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

Looks good, left a small comment

@raphael raphael merged commit b76a0f9 into goadesign:main Jan 19, 2024
2 checks passed
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.

3 participants