runtime/trace: update TestSubscribers to dump traces

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>
This commit is contained in:
Michael Anthony Knyszek
2025-12-08 17:56:26 +00:00
committed by Gopher Robot
parent 4837bcc92c
commit f2d96272cb

View 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{})