@cryptotaxi247 / kubo / commits / 7777a231f

updated goprocess -- bugfixes

Juan Batiz-Benet committed Mar 18, 2015 at 01:14 UTC 7777a231f039f2bdb2f781ad0aad1fd3582808df
3 files changed +47 -3
Godeps/Godeps.json
+1 -1
@@ -207,7 +207,7 @@
207 },
208 {
209 "ImportPath": "github.com/jbenet/goprocess",
210 - "Rev": "b4efc4c8775f0250710b39bfa716276ca10f85af"
210 + "Rev": "140749d0a125caaf7c9a2893d166331e2e963a7a"
211 },
212 {
213 "ImportPath": "github.com/kardianos/osext",
Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go
+38
@@ -460,6 +460,44 @@ func TestCloseAfterChildren(t *testing.T) {
460 testStrs(t, Q, "a", "d")
461 }
462
463 +func TestGoClosing(t *testing.T) {
464 +
465 + var ready = make(chan struct{})
466 + a := WithParent(Background())
467 + a.Go(func(p Process) {
468 +
469 + // this should be fine.
470 + a.Go(func(p Process) {
471 + ready <- struct{}{}
472 + })
473 +
474 + // set a to close. should not fully close until after this func returns.
475 + go a.Close()
476 +
477 + // wait until a is marked as closing
478 + <-a.Closing()
479 +
480 + // this should also be fine.
481 + a.Go(func(p Process) {
482 +
483 + select {
484 + case <-p.Closing():
485 + // p should be marked as closing
486 + default:
487 + t.Error("not marked closing when it should be.")
488 + }
489 +
490 + ready <- struct{}{}
491 + })
492 +
493 + ready <- struct{}{}
494 + })
495 +
496 + <-ready
497 + <-ready
498 + <-ready
499 +}
500 +
501 func TestBackground(t *testing.T) {
502 // test it hangs indefinitely:
503 b := Background()
Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go
+8 -2
@@ -61,6 +61,8 @@ func (p *process) AddChildNoWait(child Process) {
61 select {
62 case <-p.Closed():
63 panic("Process cannot add children after being closed")
64 + case <-p.Closing():
65 + go child.Close()
66 default:
67 }
68
@@ -78,6 +80,8 @@ func (p *process) AddChild(child Process) {
80 select {
81 case <-p.Closed():
82 panic("Process cannot add children after being closed")
83 + case <-p.Closing():
84 + go child.Close()
85 default:
86 }
87
@@ -88,10 +92,12 @@ func (p *process) AddChild(child Process) {
92
93 func (p *process) Go(f ProcessFunc) Process {
94 child := newProcess(nil)
91 - p.AddChild(child)
92 -
95 waitFor := newProcess(nil)
96 child.WaitFor(waitFor) // prevent child from closing
97 +
98 + // add child last, to prevent a closing parent from
99 + // closing all of them prematurely, before running the func.
100 + p.AddChild(child)
101 go func() {
102 f(child)
103 waitFor.Close() // allow child to close.