edit: improve async_reader_test

This commit is contained in:
Qi Xiao 2016-02-03 02:57:06 +01:00
parent 67c2687a07
commit 38e0df7b58
2 changed files with 19 additions and 4 deletions

View File

@ -6,13 +6,15 @@ import (
"os"
"testing"
"time"
"github.com/elves/elvish/sys"
)
// Pretty arbitrary numbers. May not reveal deadlocks on all machines.
var (
NWrite = 40960
Run = 6400
NWrite = 1024
Run = 1024
Timeout = 500 * time.Millisecond
MaxJitter = time.Millisecond
)
@ -39,8 +41,10 @@ func f(done chan struct{}) {
func TestAsyncReaderDeadlock(t *testing.T) {
done := make(chan struct{})
isatty := sys.IsATTY(1)
rand.Seed(time.Now().UTC().UnixNano())
for i := 0; i < Run; i++ {
if i%100 == 0 {
if isatty {
fmt.Printf("\r%d/%d", i, Run)
}
go f(done)
@ -49,7 +53,8 @@ func TestAsyncReaderDeadlock(t *testing.T) {
// no deadlock trigerred
case <-time.After(Timeout):
// deadlock
t.Fatalf("AsyncReader deadlock trigerred on run %d/%d", i, Run)
t.Errorf("%s", sys.DumpStack())
t.Fatalf("AsyncReader deadlock trigerred on run %d/%d, stack trace:\n%s", i, Run, sys.DumpStack())
}
}
}

10
sys/isatty.go Normal file
View File

@ -0,0 +1,10 @@
package sys
/*
#include <unistd.h>
*/
import "C"
func IsATTY(fd int) bool {
return C.isatty(C.int(fd)) != 0
}