Files
aperture/internal/test/timeout.go
Oliver Gugger 3b73ac96cb mod+lsat+test: copy test code to get rid of loop
To get rid of the loop dependency, we copy the test code that we rely on
and fix some imports.
2020-08-11 10:03:34 +02:00

35 lines
485 B
Go

package test
import (
"os"
"runtime/pprof"
"testing"
"time"
"github.com/fortytw2/leaktest"
)
// Guard implements a test level timeout.
func Guard(t *testing.T) func() {
done := make(chan struct{})
go func() {
select {
case <-time.After(5 * time.Second):
err := pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
if err != nil {
panic(err)
}
panic("test timeout")
case <-done:
}
}()
fn := leaktest.Check(t)
return func() {
close(done)
fn()
}
}