mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-12 17:27:50 +08:00
make async_reader_test more reliable by applying random jitters
This commit is contained in:
parent
d579453641
commit
6fcf7dba93
|
@ -2,6 +2,7 @@ package edit
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"os"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -10,11 +11,16 @@ import (
|
|||
// Pretty arbitrary numbers. May not reveal deadlocks on all machines.
|
||||
|
||||
var (
|
||||
NWrite = 40960
|
||||
Run = 6400
|
||||
Timeout = 500 * time.Millisecond
|
||||
NWrite = 40960
|
||||
Run = 6400
|
||||
Timeout = 500 * time.Millisecond
|
||||
MaxJitter = time.Millisecond
|
||||
)
|
||||
|
||||
func jitter() {
|
||||
time.Sleep(time.Duration(float64(MaxJitter) * rand.Float64()))
|
||||
}
|
||||
|
||||
func f(done chan struct{}) {
|
||||
r, w, _ := os.Pipe()
|
||||
defer r.Close()
|
||||
|
@ -22,7 +28,11 @@ func f(done chan struct{}) {
|
|||
ar := NewAsyncReader(r)
|
||||
defer ar.Close()
|
||||
fmt.Fprintf(w, "%*s", NWrite, "")
|
||||
go ar.Start()
|
||||
go func() {
|
||||
jitter()
|
||||
ar.Start()
|
||||
}()
|
||||
jitter()
|
||||
ar.Quit()
|
||||
done <- struct{}{}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user