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

client/pkg/testutil: add shouldSkip func for interestingGoroutines #17676

Merged
merged 1 commit into from
Apr 1, 2024
Merged

client/pkg/testutil: add shouldSkip func for interestingGoroutines #17676

merged 1 commit into from
Apr 1, 2024

Conversation

callthingsoff
Copy link
Contributor

@callthingsoff callthingsoff commented Mar 30, 2024

interestingGoroutines uses so many strings.Contains checks to determine
whether to continue, I think it can be avoided.

This patch introduces shouldSkip func to do the checks in a loop
to make the logic clearer.

Please read https://github.com/etcd-io/etcd/blob/main/CONTRIBUTING.md#contribution-flow.

@k8s-ci-robot
Copy link

Hi @callthingsoff. Thanks for your PR.

I'm waiting for a etcd-io member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@jmhbnz
Copy link
Member

jmhbnz commented Mar 30, 2024

/ok-to-test

@ahrtr
Copy link
Member

ahrtr commented Mar 31, 2024

Suggested change:

func interestingGoroutines() (gs []string) {
	buf := make([]byte, 2<<20)
	buf = buf[:runtime.Stack(buf, true)]
	for _, g := range strings.Split(string(buf), "\n\n") {
		sl := strings.SplitN(g, "\n", 2)
		if len(sl) != 2 {
			continue
		}
		stack := strings.TrimSpace(sl[1])
		if stack == "" {
			continue
		}
		
		shouldSkip := func() bool {
			var uninterestingMsgs = [...]string{
				"sync.(*WaitGroup).Done",
				"os.(*file).close",
				"os.(*Process).Release",
				"created by os/signal.init",
				"runtime/panic.go",
				"created by testing.RunTests",
				"created by testing.runTests",
				"created by testing.(*T).Run",
				"testing.Main(",
				"runtime.goexit",
				"go.etcd.io/etcd/client/pkg/v3/testutil.interestingGoroutines",
				"go.etcd.io/etcd/client/pkg/v3/logutil.(*MergeLogger).outputLoop",
				"github.com/golang/glog.(*loggingT).flushDaemon",
				"created by runtime.gc",
				"created by text/template/parse.lex",
				"runtime.MHeap_Scavenger",
				"rcrypto/internal/boring.(*PublicKeyRSA).finalize",
				"net.(*netFD).Close(",
				"testing.(*T).Run",
			}
			for _, msg := range uninterestingMsgs {
				if strings.Contains(stack, msg) {
					return true
				}
			}
			return false
		}()

		if shouldSkip {
			continue
		}

		gs = append(gs, stack)
	}
	sort.Strings(gs)
	return gs
}

interestingGoroutines uses so many strings.Contains checks to determine
whether to continue, I think it can be avoided.

This patch introduces shouldSkip func to do the checks in a loop
to make the logic clearer.

Signed-off-by: Jes Cok <[email protected]>
@callthingsoff callthingsoff changed the title client/pkg/testutil: introduce uninterestingMsgs to simplify code for… client/pkg/testutil: add shouldSkip func for interestingGoroutines Mar 31, 2024
Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

LGTM

@ahrtr ahrtr merged commit 5c8a078 into etcd-io:main Apr 1, 2024
39 checks passed
@callthingsoff callthingsoff deleted the refactor_testutil_interestingGoroutines branch April 1, 2024 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

4 participants