mirror of https://github.com/lightninglabs/loop
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
439 B
Go
32 lines
439 B
Go
6 years ago
|
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):
|
||
|
pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
|
||
|
|
||
|
panic("test timeout")
|
||
|
case <-done:
|
||
|
}
|
||
|
}()
|
||
|
|
||
|
fn := leaktest.Check(t)
|
||
|
|
||
|
return func() {
|
||
|
close(done)
|
||
|
fn()
|
||
|
}
|
||
|
}
|