Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 24 additions & 18 deletions datadriven.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ var (
)
)

// SlowDirectiveLogPeriod is the period with which we log slow-running
// directives. Set to 0 to disable the logging.
var SlowDirectiveLogPeriod = 10 * time.Second

// Verbose returns true iff -datadriven-quiet was not passed.
func Verbose() bool {
return testing.Verbose() && !*quietLog
Expand Down Expand Up @@ -344,25 +348,27 @@ 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{})
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))
if SlowDirectiveLogPeriod > 0 {
// 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{})
go func() {
startTime := time.Now()
for {
select {
case <-done:
return
case <-time.After(SlowDirectiveLogPeriod):
t.Logf("%s: still running after %s\n", d.Pos, time.Since(startTime))
}
}
}
}()
defer func() {
// Because the channel is unbuffered, we wait here until the goroutine is
// exiting.
done <- struct{}{}
}()
}()
defer func() {
// Because the channel is unbuffered, we wait here until the goroutine is
// exiting.
done <- struct{}{}
}()
}

actual := f(t, d)
fReturned = true
Expand Down