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

Fix copying suite.Suite in integration tests #5481

Merged
merged 8 commits into from
Dec 18, 2023

Conversation

3vilhamster
Copy link
Member

@3vilhamster 3vilhamster commented Dec 16, 2023

  • Fix integration suite copying suite while passing it around

What changed?
Changed TestBase and IntegrationBase to be passed as a pointer to avoid copying suite.Suite internals. That can cause side effects like missing links to test initiated and internal mutex is copied together with the struct.

Why?
Lint warning, though I see a lot of logs in integration tests that likely are leaking due to this copying.

How did you test it?
run integration tests

Potential risks

Release notes

Documentation Changes

@@ -27,10 +27,8 @@ import (
"testing"
"time"

"github.com/uber/cadence/common/log/loggerimpl"

"github.com/startreedata/pinot-client-go/pinot"
Copy link
Member

Choose a reason for hiding this comment

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

nit: import groups should ideally go in following order

  • builtin packages
  • repo specific packages
  • external packages
  • named packages

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm using default goimports behaviour.
As far as I've seen discussions about grouping, the outcome is that there should be either 2 or 3 groups. But in Uber style guide, we've settled in 2 groups. https://github.com/uber-go/guide/blob/master/style.md#import-group-ordering

Copy link
Member

Choose a reason for hiding this comment

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

broadly I agree, but tbh I don't think it matters much, and it doesn't affect behavior as of [some semi-recent Go version]. automate it or ignore it, imo, it's hidden in almost all editors anyway and it doesn't make code review any more difficult.

Copy link
Member

Choose a reason for hiding this comment

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

It's still a bit surprising to me that goimports doesn't have an option to forcibly reorder stuff... but this looks like it might be reasonable: https://github.com/incu6us/goimports-reviser

I might see if that does what we want. The less we have to touch here, the better.

Copy link
Member

@Groxx Groxx Dec 17, 2023

Choose a reason for hiding this comment

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

well. it's like 99% good... but it strips comments on anything it moves :|
if that's fixed it seems quite promising tho. probably not too hard, astutil.CommentMap addresses exactly this kind of thing.

Copy link
Member

Choose a reason for hiding this comment

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

I'd vote to put whatever behaviour we settle on in a linter and just enforce it at the lint level

Copy link
Member Author

@3vilhamster 3vilhamster Dec 18, 2023

Choose a reason for hiding this comment

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

There is also this https://github.com/NonLogicalDev/gofancyimports which is pretty good. It is mentioned in a issue for goimports golang/go#20818, though it is quite fresh.

Unfortunately that even in monorepo there is no tooling to enforce proper imports.

Copy link
Member

@Groxx Groxx Dec 18, 2023

Choose a reason for hiding this comment

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

gofancyimports looks great at a glance:

  • keeps comments
  • enforces grouping
  • drops import ( "single/thing" ) parenthesis
  • comments above an import keeps that group of imports organized together (manual grouping is possible when desired)
  • comments on the same line as an import get reordered with other imports

I can get a PR for that up today, it's pretty simple. just gotta verify the changes/license/etc first.

logger, err := loggerimpl.NewDevelopment()
if err != nil {
panic(err)
}

return TestBase{
return &TestBase{
Copy link
Member

Choose a reason for hiding this comment

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

looks like some other tests depend on this too. unit tests are failing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it turns out that most of persistence tests use this and copy suite all the time. Fixed

@3vilhamster 3vilhamster changed the title Fix integration test base usage Fix copying suite.Suite in integration tests Dec 16, 2023
Copy link
Member

@Groxx Groxx left a comment

Choose a reason for hiding this comment

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

huh. TIL that go vet's at-test-time checks don't include copy-lock checks... that's quite surprising, and yeah there are loads of copy-lock problems in these tests D:

we should deeeeefinitely add go vet -copylocks ./... to our PR-blocking lint checks. too many failures at the moment though.
thankfully they're all in tests except for common/persistence/nosql, and those might be safe in practice (but still absolutely deserve fixing, there's no reason at all to allow that to exist)

Comment on lines +53 to +55
if testing.Verbose() {
log.SetOutput(os.Stdout)
}
Copy link
Member

@Groxx Groxx Dec 17, 2023

Choose a reason for hiding this comment

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

does using t.Log-proxied stuff work, or do these run into races if you do that? I know it's not directly log compatible, but I doubt that matters in practice for our tests.


otherwise:

  • default stderr -> verbose stdout: essentially matches go test -v (stdout) so 👍 that seems reasonable.
  • to match -v more closely, do we want to maybe io.Discard when not verbose? I know that's not the same since it will print nothing on non-verbose failure, but it feels closer to the goal of non-verbose for go test ./... purposes. plus none of our existing stuff treats stdout vs stderr differently, and CI is verbose, so I don't know if there's much benefit to specializing it like this unless it's going to lead to a pragmatic or technical improvement somewhere.
  • this seems broadly useful, given all the bare log use, and this one test doesn't seem special at all at a glance (is it in practice?). seems worth adding to a test-helper package and using everywhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

In the following PR I want to move all logging into the root suite TestBase/IntegrationBase part and use -v to either use zaptest or use zap.NewDevelopment depending on the -v. At least that is my plan.

Copy link
Member

Choose a reason for hiding this comment

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

if zaptest doesn't cause data races (due to unclean shutdown), always prefer zaptest. there's basically no reason to use zap.NewDevelopment or log.* or fmt.Println in tests, t.Log-based stuff is massively better.

Comment on lines +34 to +35
cadenceIndex := strings.LastIndex(cadencePackageDir, "cadence/")
cadencePackageDir = cadencePackageDir[:cadenceIndex+len("cadence/")]
Copy link
Member

@Groxx Groxx Dec 17, 2023

Choose a reason for hiding this comment

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

was this failing somewhere, or just felt like removing / prefixes? seems fine either way since it doesn't change the behavior (afaict), just odd to see it change, curious if there is some scenario it improves.

generally I think "dir means it has a / suffix already" is reasonable, I just don't know if we have any established patterns here.

Copy link
Member Author

Choose a reason for hiding this comment

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

My local folder is called my-cadence :D and it failed. I've tried switching to finding git root, but apparently our CI is running on windows and has some issues with safe-folder related stuff. So I just fixed the / part.

Copy link
Member

Choose a reason for hiding this comment

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

our ci is definitely on linux, so it's not that at least. either way this seems totally fine tho.

we could eliminate this entirely if we used //go:embed for the indexes, but that's a separate thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

Well, from the errors like from
git rev-parse --show-toplevel
that I've got when using https://github.com/Integralist/go-findroot/blob/master/find/find.go#L36
fatal: detected dubious ownership of /cadence
means that we are running on windows with WSL.

Copy link
Member

@Groxx Groxx left a comment

Choose a reason for hiding this comment

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

I suspect that not all of these are necessary on a technical level (ephemeral copies e.g. on return are safe and go vet does not highlight them either)... but using a pointer for all these seems entirely reasonable too, and also more copy-bug-resistant (it's very clear that copies are not being used for intentional behavior here), so 👍


I'm game to approve now and let you merge with whatever since it seems all safe + a clear improvement, and/or feel free to re-request review if ya want more input after changes.

@3vilhamster 3vilhamster merged commit e55cb82 into cadence-workflow:master Dec 18, 2023
16 checks passed
@3vilhamster 3vilhamster deleted the fix-test-base branch December 18, 2023 11:35
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.

4 participants