diff --git a/datadriven.go b/datadriven.go index a98048a..7437cca 100644 --- a/datadriven.go +++ b/datadriven.go @@ -347,7 +347,6 @@ func runDirective(t testing.TB, r *testDataReader, f func(testing.TB, *TestData) // 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 { @@ -359,6 +358,11 @@ func runDirective(t testing.TB, r *testDataReader, f func(testing.TB, *TestData) } } }() + defer func() { + // Because the channel is unbuffered, we wait here until the goroutine is + // exiting. + done <- struct{}{} + }() actual := f(t, d) fReturned = true