From 21ec9031bf1703fd8f82a343f31f2964b9567428 Mon Sep 17 00:00:00 2001 From: Joshua MacDonald Date: Thu, 26 Nov 2015 22:53:32 -0800 Subject: Wait for I/O to finish before waiting for subprocesses to exit --- xdelta3/go/src/xdelta/test.go | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'xdelta3/go/src/xdelta/test.go') diff --git a/xdelta3/go/src/xdelta/test.go b/xdelta3/go/src/xdelta/test.go index ab4137c..05de487 100644 --- a/xdelta3/go/src/xdelta/test.go +++ b/xdelta3/go/src/xdelta/test.go @@ -47,9 +47,8 @@ func (t *TestGroup) Drain(f io.ReadCloser, desc string) <-chan []byte { return c } -func (t *TestGroup) Empty(f io.ReadCloser, desc string) { - t.Go(desc, func (g Goroutine) { - g.OK() +func (t *TestGroup) Empty(f io.ReadCloser, desc string) Goroutine { + return t.Go("empty:"+desc, func (g Goroutine) { s := bufio.NewScanner(f) for s.Scan() { os.Stderr.Write([]byte(fmt.Sprint(desc, ": ", s.Text(), "\n"))) @@ -57,9 +56,9 @@ func (t *TestGroup) Empty(f io.ReadCloser, desc string) { err := s.Err() f.Close() if err != nil { - fmt.Println("Empty", desc, err) g.Panic(err) } + g.OK() }) } @@ -75,8 +74,8 @@ func TestWrite(what string, f io.WriteCloser, b []byte) error { return nil } -func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) { - t.Go("copy", func(g Goroutine) { +func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) Goroutine { + return t.Go("copy", func(g Goroutine) { _, err := io.Copy(w, r) if err != nil { fmt.Println("CopyS", err) @@ -96,8 +95,8 @@ func (t *TestGroup) CopyStreams(r io.ReadCloser, w io.WriteCloser) { }) } -func (t *TestGroup) CompareStreams(r1 io.ReadCloser, r2 io.ReadCloser, length int64) { - t.Go("compare", func(g Goroutine) { +func (t *TestGroup) CompareStreams(r1 io.ReadCloser, r2 io.ReadCloser, length int64) Goroutine { + return t.Go("compare", func(g Goroutine) { b1 := make([]byte, blocksize) b2 := make([]byte, blocksize) var idx int64 @@ -162,15 +161,13 @@ func (t *TestGroup) Exec(desc string, p *Program, srcfifo bool, flags []string) if serr := run.Cmd.Start(); serr != nil { return nil, serr } - t.Go("exec-wait:" + desc, func (g Goroutine) { - if err := run.Cmd.Wait(); err != nil { - g.Panic(err) - } - g.OK() - }) return run, nil } +func (r *Run) Wait() error { + return r.Cmd.Wait() +} + func writeFifo(srcfile string, read io.Reader) error { fifo, err := os.OpenFile(srcfile, os.O_WRONLY, 0600) if err != nil { -- cgit v1.2.3