From b53fb5f7c20dba1b5a647527e778edfc35ef8bd7 Mon Sep 17 00:00:00 2001 From: Radu Berinde Date: Fri, 5 Sep 2025 09:08:52 -0700 Subject: [PATCH] datadriven: log slow commands This change adds a `t.Log` every 10 seconds if the function that runs a directive takes a long time. This should show the cause of a test timeout. --- datadriven.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/datadriven.go b/datadriven.go index 8f8cf7e..4fc2045 100644 --- a/datadriven.go +++ b/datadriven.go @@ -337,6 +337,23 @@ func runDirective(t testing.TB, r *testDataReader, f func(testing.TB, *TestData) panic(r) } }() + + // Set up a goroutine to log periodically if the function is taking a long + // time. This is useful to pinpoint the cause of a test timeout. + done := make(chan struct{}) + defer close(done) + go func() { + startTime := time.Now() + for { + select { + case <-done: + return + case <-time.After(10 * time.Second): + t.Logf("%s: still running after %s\n", d.Pos, time.Since(startTime)) + } + } + }() + actual := f(t, d) if actual != "" && !strings.HasSuffix(actual, "\n") { actual += "\n"