]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/pprof: allow tests to run multiple times
authorHana Kim <hakim@google.com>
Thu, 24 May 2018 19:15:45 +0000 (15:15 -0400)
committerHyang-Ah Hana Kim <hyangah@gmail.com>
Thu, 24 May 2018 20:26:47 +0000 (20:26 +0000)
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 <hyangah@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
src/runtime/pprof/pprof_test.go

index e8567f495229f259ee91f5b1b938782c95fdfc32..44d514393ea442f6b47984e943ccf26c73b6dc92 100644 (file)
@@ -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)
        }