From 38e0df7b58c6f209ead1697ab465fded5b34f429 Mon Sep 17 00:00:00 2001 From: Qi Xiao Date: Wed, 3 Feb 2016 02:57:06 +0100 Subject: [PATCH] edit: improve async_reader_test --- edit/async_reader_test.go | 13 +++++++++---- sys/isatty.go | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 sys/isatty.go diff --git a/edit/async_reader_test.go b/edit/async_reader_test.go index 4a595015..97a9e10e 100644 --- a/edit/async_reader_test.go +++ b/edit/async_reader_test.go @@ -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()) } } } diff --git a/sys/isatty.go b/sys/isatty.go new file mode 100644 index 00000000..aa6ce59a --- /dev/null +++ b/sys/isatty.go @@ -0,0 +1,10 @@ +package sys + +/* +#include +*/ +import "C" + +func IsATTY(fd int) bool { + return C.isatty(C.int(fd)) != 0 +}