diff options
Diffstat (limited to 'xdelta3/go/src/xdelta/tgroup.go')
-rw-r--r-- | xdelta3/go/src/xdelta/tgroup.go | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/xdelta3/go/src/xdelta/tgroup.go b/xdelta3/go/src/xdelta/tgroup.go index bb34258..b64827c 100644 --- a/xdelta3/go/src/xdelta/tgroup.go +++ b/xdelta3/go/src/xdelta/tgroup.go | |||
@@ -10,6 +10,7 @@ type TestGroup struct { | |||
10 | *Runner | 10 | *Runner |
11 | sync.Mutex | 11 | sync.Mutex |
12 | running []Goroutine | 12 | running []Goroutine |
13 | errors []error | ||
13 | waitChan <-chan bool | 14 | waitChan <-chan bool |
14 | } | 15 | } |
15 | 16 | ||
@@ -31,13 +32,19 @@ func (g *Goroutine) String() string { | |||
31 | } | 32 | } |
32 | 33 | ||
33 | func (g *Goroutine) OK() { | 34 | func (g *Goroutine) OK() { |
34 | g.errChan <- nil | 35 | if g.errChan != nil { |
35 | _ = <- g.errChan | 36 | g.errChan <- nil |
37 | _ = <- g.errChan | ||
38 | g.errChan = nil | ||
39 | } | ||
36 | } | 40 | } |
37 | 41 | ||
38 | func (g *Goroutine) Panic(err error) { | 42 | func (g *Goroutine) Panic(err error) { |
39 | g.errChan <- err | 43 | fmt.Print("[", g.name, "] ", err, "\n") |
40 | _ = <- g.errChan | 44 | if g.errChan != nil { |
45 | g.errChan <- err | ||
46 | _ = <- g.errChan | ||
47 | } | ||
41 | select {} | 48 | select {} |
42 | } | 49 | } |
43 | 50 | ||
@@ -52,15 +59,24 @@ func (t *TestGroup) Go(name string, f func(Goroutine)) { | |||
52 | func (t *TestGroup) Wait(g Goroutine) { | 59 | func (t *TestGroup) Wait(g Goroutine) { |
53 | g.OK() | 60 | g.OK() |
54 | t.Lock() | 61 | t.Lock() |
55 | t.waitChan = nil | ||
56 | wc := t.waitChan | 62 | wc := t.waitChan |
63 | t.waitChan = nil | ||
57 | t.Unlock() | 64 | t.Unlock() |
58 | _ = <- wc | 65 | _ = <- wc |
66 | t.Lock() | ||
67 | errs := t.errors | ||
68 | t.Unlock() | ||
69 | if len(errs) != 0 { | ||
70 | panic(fmt.Sprintln(len(errs), "errors in test")) | ||
71 | } | ||
59 | } | 72 | } |
60 | 73 | ||
61 | func waitAll(t *TestGroup, wc chan bool) { | 74 | func waitAll(t *TestGroup, wc chan bool) { |
62 | for { | 75 | for { |
63 | t.Lock() | 76 | t.Lock() |
77 | // for _, x := range t.running { | ||
78 | // fmt.Println("RUNNING", x.name) | ||
79 | // } | ||
64 | if len(t.running) == 0 { | 80 | if len(t.running) == 0 { |
65 | t.Unlock() | 81 | t.Unlock() |
66 | break | 82 | break |
@@ -69,19 +85,18 @@ func waitAll(t *TestGroup, wc chan bool) { | |||
69 | t.running = t.running[1:] | 85 | t.running = t.running[1:] |
70 | t.Unlock() | 86 | t.Unlock() |
71 | 87 | ||
72 | timeout := make(chan bool, 1) | 88 | timeout := time.After(time.Second) |
73 | go func() { | 89 | // fmt.Println("Waiting on", runner) |
74 | time.Sleep(1 * time.Second) | ||
75 | timeout <- true | ||
76 | }() | ||
77 | fmt.Println("Waiting on", runner) | ||
78 | select { | 90 | select { |
79 | case err := <- runner.errChan: | 91 | case err := <- runner.errChan: |
80 | runner.errChan <- err | 92 | runner.errChan <- err |
81 | if err != nil { | 93 | if err != nil { |
82 | fmt.Println("[G]", runner, err) | 94 | // fmt.Println("[G]", runner, err) |
95 | t.Lock() | ||
96 | t.errors = append(t.errors, err) | ||
97 | t.Unlock() | ||
83 | } else { | 98 | } else { |
84 | fmt.Println("[G]", runner, "OK") | 99 | // fmt.Println("[G]", runner, "OK") |
85 | } | 100 | } |
86 | case <- timeout: | 101 | case <- timeout: |
87 | t.Lock() | 102 | t.Lock() |