]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/trace: update TestSubscribers to dump traces
authorMichael Anthony Knyszek <mknyszek@google.com>
Mon, 8 Dec 2025 17:56:26 +0000 (17:56 +0000)
committerGopher Robot <gobot@golang.org>
Mon, 8 Dec 2025 18:58:21 +0000 (10:58 -0800)
CL 710755 missed this test suite.

For #75665.

Change-Id: Id2f1ab2eae2c20ea5056e893951a73c0b851f0eb
Reviewed-on: https://go-review.googlesource.com/c/go/+/728200
Reviewed-by: Michael Pratt <mpratt@google.com>
Auto-Submit: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/runtime/trace/subscribe_test.go

index 0e6c57cbc6d3520bbd70ec37288e2693b67585d9..6378c3401a9a9f0b500201293e96677d61712301 100644 (file)
@@ -16,11 +16,17 @@ import (
 )
 
 func TestSubscribers(t *testing.T) {
-       validate := func(t *testing.T, source string, tr io.Reader) {
+       validate := func(t *testing.T, source string, tr *bytes.Buffer) {
+               defer func() {
+                       if t.Failed() {
+                               testtrace.Dump(t, "trace", tr.Bytes(), *dumpTraces)
+                       }
+               }()
+
                // Prepare to read the trace snapshot.
                r, err := inttrace.NewReader(tr)
                if err != nil {
-                       t.Fatalf("unexpected error creating trace reader for %s: %v", source, err)
+                       t.Errorf("unexpected error creating trace reader for %s: %v", source, err)
                        return
                }
 
@@ -38,26 +44,28 @@ func TestSubscribers(t *testing.T) {
                                break
                        }
                        if err != nil {
-                               t.Fatalf("unexpected error reading trace for %s: %v", source, err)
+                               t.Errorf("unexpected error reading trace for %s: %v", source, err)
                        }
                        if err := v.Event(ev); err != nil {
-                               t.Fatalf("event validation failed: %s", err)
+                               t.Errorf("event validation failed: %s", err)
                        }
                        if ev.Kind() == inttrace.EventSync {
                                syncs = append(syncs, evs)
                        }
                        evs++
                }
-               ends := []int{syncs[0], syncs[len(syncs)-1]}
-               if wantEnds := []int{0, evs - 1}; !slices.Equal(wantEnds, ends) {
-                       t.Errorf("expected a sync event at each end of the trace, found sync events at %d instead of %d for %s",
-                               ends, wantEnds, source)
+               if !t.Failed() {
+                       ends := []int{syncs[0], syncs[len(syncs)-1]}
+                       if wantEnds := []int{0, evs - 1}; !slices.Equal(wantEnds, ends) {
+                               t.Errorf("expected a sync event at each end of the trace, found sync events at %d instead of %d for %s",
+                                       ends, wantEnds, source)
+                       }
                }
        }
 
-       validateTraces := func(t *testing.T, tReader, frReader io.Reader) {
-               validate(t, "tracer", tReader)
-               validate(t, "flightRecorder", frReader)
+       validateTraces := func(t *testing.T, trace, frTrace *bytes.Buffer) {
+               validate(t, "tracer", trace)
+               validate(t, "flightRecorder", frTrace)
        }
        startFlightRecorder := func(t *testing.T) *trace.FlightRecorder {
                fr := trace.NewFlightRecorder(trace.FlightRecorderConfig{})