From: Hana Kim Date: Thu, 24 May 2018 19:15:45 +0000 (-0400) Subject: runtime/pprof: allow tests to run multiple times X-Git-Tag: go1.11beta1~315 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=9eb2c434747cc83aa1e356b9ba7c2a58e8cb6926;p=gostls13.git runtime/pprof: allow tests to run multiple times TestMutexProfile and TestEmptyCallStack couldn't run multiple times because they mutate state in runtime (mutex profile counters and a user-defined profile type) and test whether the state matches what it is supposed to be after the very first run. We fix TestMutexProfile by relaxing the expected state condition. We fix TestEmptyCallStack by creating a new profile with a different name every time the test runs. For #25520 Change-Id: I8e50cd9526eb650c8989457495ff90a24ce07863 Reviewed-on: https://go-review.googlesource.com/114495 Run-TryBot: Hyang-Ah Hana Kim Reviewed-by: Brad Fitzpatrick --- diff --git a/src/runtime/pprof/pprof_test.go b/src/runtime/pprof/pprof_test.go index e8567f4952..44d514393e 100644 --- a/src/runtime/pprof/pprof_test.go +++ b/src/runtime/pprof/pprof_test.go @@ -700,7 +700,7 @@ func TestMutexProfile(t *testing.T) { return } // checking that the line is like "35258904 1 @ 0x48288d 0x47cd28 0x458931" - r2 := `^\d+ 1 @(?: 0x[[:xdigit:]]+)+` + r2 := `^\d+ \d+ @(?: 0x[[:xdigit:]]+)+` //r2 := "^[0-9]+ 1 @ 0x[0-9a-f x]+$" if ok, err := regexp.MatchString(r2, lines[3]); err != nil || !ok { t.Errorf("%q didn't match %q", lines[3], r2) @@ -823,16 +823,22 @@ func containsCounts(prof *profile.Profile, counts []int64) bool { return true } +var emptyCallStackTestRun int64 + // Issue 18836. func TestEmptyCallStack(t *testing.T) { + name := fmt.Sprintf("test18836_%d", emptyCallStackTestRun) + emptyCallStackTestRun++ + t.Parallel() var buf bytes.Buffer - p := NewProfile("test18836") + p := NewProfile(name) + p.Add("foo", 47674) p.WriteTo(&buf, 1) p.Remove("foo") got := buf.String() - prefix := "test18836 profile: total 1\n" + prefix := name + " profile: total 1\n" if !strings.HasPrefix(got, prefix) { t.Fatalf("got:\n\t%q\nwant prefix:\n\t%q\n", got, prefix) }