summaryrefslogtreecommitdiff
path: root/xdelta3/go/src/xdelta/tgroup.go
diff options
context:
space:
mode:
Diffstat (limited to 'xdelta3/go/src/xdelta/tgroup.go')
-rw-r--r--xdelta3/go/src/xdelta/tgroup.go27
1 files changed, 15 insertions, 12 deletions
diff --git a/xdelta3/go/src/xdelta/tgroup.go b/xdelta3/go/src/xdelta/tgroup.go
index b64827c..c7337c6 100644
--- a/xdelta3/go/src/xdelta/tgroup.go
+++ b/xdelta3/go/src/xdelta/tgroup.go
@@ -40,7 +40,7 @@ func (g *Goroutine) OK() {
40} 40}
41 41
42func (g *Goroutine) Panic(err error) { 42func (g *Goroutine) Panic(err error) {
43 fmt.Print("[", g.name, "] ", err, "\n") 43 fmt.Println(g, err)
44 if g.errChan != nil { 44 if g.errChan != nil {
45 g.errChan <- err 45 g.errChan <- err
46 _ = <- g.errChan 46 _ = <- g.errChan
@@ -48,16 +48,17 @@ func (g *Goroutine) Panic(err error) {
48 select {} 48 select {}
49} 49}
50 50
51func (t *TestGroup) Go(name string, f func(Goroutine)) { 51func (t *TestGroup) Go(name string, f func(Goroutine)) Goroutine {
52 g := Goroutine{name, make(chan error)} 52 g := Goroutine{name, make(chan error)}
53 t.Lock() 53 t.Lock()
54 t.running = append(t.running, g) 54 t.running = append(t.running, g)
55 t.Unlock() 55 t.Unlock()
56 go f(g) 56 go f(g)
57 return g
57} 58}
58 59
59func (t *TestGroup) Wait(g Goroutine) { 60func (t *TestGroup) Wait(self Goroutine, procs... *Run) {
60 g.OK() 61 self.OK()
61 t.Lock() 62 t.Lock()
62 wc := t.waitChan 63 wc := t.waitChan
63 t.waitChan = nil 64 t.waitChan = nil
@@ -66,17 +67,22 @@ func (t *TestGroup) Wait(g Goroutine) {
66 t.Lock() 67 t.Lock()
67 errs := t.errors 68 errs := t.errors
68 t.Unlock() 69 t.Unlock()
70 for _, p := range procs {
71 if err := p.Wait(); err != nil {
72 errs = append(errs, err)
73 }
74 }
69 if len(errs) != 0 { 75 if len(errs) != 0 {
70 panic(fmt.Sprintln(len(errs), "errors in test")) 76 for _, err := range errs {
77 fmt.Println(err)
78 }
79 panic(fmt.Sprint(len(errs), " errors"))
71 } 80 }
72} 81}
73 82
74func waitAll(t *TestGroup, wc chan bool) { 83func waitAll(t *TestGroup, wc chan bool) {
75 for { 84 for {
76 t.Lock() 85 t.Lock()
77 // for _, x := range t.running {
78 // fmt.Println("RUNNING", x.name)
79 // }
80 if len(t.running) == 0 { 86 if len(t.running) == 0 {
81 t.Unlock() 87 t.Unlock()
82 break 88 break
@@ -86,17 +92,14 @@ func waitAll(t *TestGroup, wc chan bool) {
86 t.Unlock() 92 t.Unlock()
87 93
88 timeout := time.After(time.Second) 94 timeout := time.After(time.Second)
89 // fmt.Println("Waiting on", runner) 95
90 select { 96 select {
91 case err := <- runner.errChan: 97 case err := <- runner.errChan:
92 runner.errChan <- err 98 runner.errChan <- err
93 if err != nil { 99 if err != nil {
94 // fmt.Println("[G]", runner, err)
95 t.Lock() 100 t.Lock()
96 t.errors = append(t.errors, err) 101 t.errors = append(t.errors, err)
97 t.Unlock() 102 t.Unlock()
98 } else {
99 // fmt.Println("[G]", runner, "OK")
100 } 103 }
101 case <- timeout: 104 case <- timeout:
102 t.Lock() 105 t.Lock()