]> Cypherpunks repositories - gostls13.git/commitdiff
runtime/trace: fix flaky test for SetMinAge
authorCarlos Amedee <carlos@golang.org>
Thu, 22 May 2025 17:33:28 +0000 (13:33 -0400)
committerCarlos Amedee <carlos@golang.org>
Fri, 23 May 2025 14:45:39 +0000 (07:45 -0700)
This change fixes the flaky test which expects setting SetMinAge to a
small ammount. It expects two sync events but should realistically
expect up to 3.

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

src/runtime/trace/flightrecorder_test.go

index 075215db000a2c35e3e3fd0434980d030909ef4d..61cb03dcf60681ac044c5599831bb7f209577478 100644 (file)
@@ -170,7 +170,7 @@ func TestFlightRecorderLog(t *testing.T) {
        }
 }
 
-func TestFlightRecorderOneGeneration(t *testing.T) {
+func TestFlightRecorderGenerationCount(t *testing.T) {
        test := func(t *testing.T, fr *trace.FlightRecorder) {
                tr := testFlightRecorder(t, fr, func(snapshot func()) {
                        // Sleep to let a few generations pass.
@@ -184,7 +184,7 @@ func TestFlightRecorderOneGeneration(t *testing.T) {
                        t.Fatalf("unexpected error creating trace reader: %v", err)
                }
 
-               // Make sure there are exactly two Sync events: at the start and end.
+               // Make sure there are Sync events: at the start and end.
                var syncs []int
                evs := 0
                for {
@@ -200,13 +200,18 @@ func TestFlightRecorderOneGeneration(t *testing.T) {
                        }
                        evs++
                }
-               if ends := []int{0, evs - 1}; !slices.Equal(syncs, ends) {
-                       t.Errorf("expected two sync events (one at each end of the trace), found %d at %d instead of %d",
-                               len(syncs), syncs[:min(len(syncs), 5)], ends)
+               const wantMaxSyncs = 3
+               if len(syncs) > wantMaxSyncs {
+                       t.Errorf("expected at most %d sync events, found %d at %d",
+                               wantMaxSyncs, len(syncs), syncs)
+               }
+               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",
+                               ends, wantEnds)
                }
        }
-       t.Run("SetMinAge", func(t *testing.T) {
-               t.Skip("issue 63185: flaky test")
+       t.Run("MinAge", func(t *testing.T) {
                fr := trace.NewFlightRecorder(trace.FlightRecorderConfig{MinAge: time.Millisecond})
                test(t, fr)
        })