diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 4cb9a36a9..66d634943 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -185,7 +185,7 @@ }, { "ImportPath": "github.com/jbenet/goprocess", - "Rev": "c37725a4a97d6ad772818b071ceef82789562142" + "Rev": "c5455a611a9e0cebac87e7ae421c3273c3224000" }, { "ImportPath": "github.com/kr/binarydist", diff --git a/Godeps/_workspace/src/github.com/jbenet/goprocess/.travis.yml b/Godeps/_workspace/src/github.com/jbenet/goprocess/.travis.yml index 7669438ed..d16d679a6 100644 --- a/Godeps/_workspace/src/github.com/jbenet/goprocess/.travis.yml +++ b/Godeps/_workspace/src/github.com/jbenet/goprocess/.travis.yml @@ -1,11 +1,10 @@ language: go go: - - 1.2 - 1.3 - 1.4 - release - tip script: - - go test -v ./... + - go test -race -cpu=5 -v ./... diff --git a/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go b/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go index 277c01b72..d9c9e702d 100644 --- a/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go +++ b/Godeps/_workspace/src/github.com/jbenet/goprocess/goprocess_test.go @@ -29,15 +29,18 @@ func setupHierarchy(p Process) tree { func TestClosingClosed(t *testing.T) { + bWait := make(chan struct{}) a := WithParent(Background()) - b := WithParent(a) + a.Go(func(proc Process) { + <-bWait + }) Q := make(chan string, 3) go func() { <-a.Closing() Q <- "closing" - b.Close() + bWait <- struct{}{} }() go func() { @@ -149,7 +152,7 @@ func TestTeardownCalledOnce(t *testing.T) { a.c[1].Close() } -func TestOnClosed(t *testing.T) { +func TestOnClosedAll(t *testing.T) { Q := make(chan string, 10) p := WithParent(Background()) @@ -165,12 +168,39 @@ func TestOnClosed(t *testing.T) { go p.Close() - testStrs(t, Q, "00", "01", "10", "11") - testStrs(t, Q, "00", "01", "10", "11") - testStrs(t, Q, "00", "01", "10", "11") - testStrs(t, Q, "00", "01", "10", "11") - testStrs(t, Q, "0", "1") - testStrs(t, Q, "0", "1") + testStrs(t, Q, "00", "01", "10", "11", "0", "1", "") + testStrs(t, Q, "00", "01", "10", "11", "0", "1", "") + testStrs(t, Q, "00", "01", "10", "11", "0", "1", "") + testStrs(t, Q, "00", "01", "10", "11", "0", "1", "") + testStrs(t, Q, "00", "01", "10", "11", "0", "1", "") + testStrs(t, Q, "00", "01", "10", "11", "0", "1", "") +} + +func TestOnClosedLeaves(t *testing.T) { + + Q := make(chan string, 10) + p := WithParent(Background()) + a := setupHierarchy(p) + + go onClosedStr(Q, "0", a.c[0]) + go onClosedStr(Q, "10", a.c[1].c[0]) + go onClosedStr(Q, "", a) + go onClosedStr(Q, "00", a.c[0].c[0]) + go onClosedStr(Q, "1", a.c[1]) + go onClosedStr(Q, "01", a.c[0].c[1]) + go onClosedStr(Q, "11", a.c[1].c[1]) + + go a.c[0].Close() + testStrs(t, Q, "00", "01", "0") + testStrs(t, Q, "00", "01", "0") + testStrs(t, Q, "00", "01", "0") + + go a.c[1].Close() + testStrs(t, Q, "10", "11", "1") + testStrs(t, Q, "10", "11", "1") + testStrs(t, Q, "10", "11", "1") + + go p.Close() testStrs(t, Q, "") } @@ -370,6 +400,7 @@ func TestCloseAfterChildren(t *testing.T) { <-p.Closing() // wait till we're told to close (parents mustnt) }) ready <- struct{}{} + // <-p.Closing() // will CloseAfterChildren }) a.Go(func(p Process) { d = p @@ -379,6 +410,7 @@ func TestCloseAfterChildren(t *testing.T) { <-p.Closing() // wait till we're told to close (parents mustnt) }) ready <- struct{}{} + <-p.Closing() }) <-ready @@ -397,6 +429,7 @@ func TestCloseAfterChildren(t *testing.T) { aDone := make(chan struct{}) bDone := make(chan struct{}) + t.Log("test none when waiting on a") testNone(t, Q) go func() { a.CloseAfterChildren() @@ -404,6 +437,7 @@ func TestCloseAfterChildren(t *testing.T) { }() testNone(t, Q) + t.Log("test none when waiting on b") go func() { b.CloseAfterChildren() bDone <- struct{}{} @@ -482,8 +516,8 @@ func testNotClosed(t *testing.T, p Process) { func testNone(t *testing.T, c <-chan string) { select { - case <-c: - t.Fatal("none should be closed") + case out := <-c: + t.Fatal("none should be closed", out) default: } } diff --git a/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go b/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go index 633d5b056..8d13c4a96 100644 --- a/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go +++ b/Godeps/_workspace/src/github.com/jbenet/goprocess/impl-mutex.go @@ -82,8 +82,8 @@ func (p *process) Go(f ProcessFunc) Process { child.WaitFor(waitFor) // prevent child from closing go func() { f(child) - waitFor.Close() // allow child to close. - child.Close() // close to tear down. + waitFor.Close() // allow child to close. + child.CloseAfterChildren() // close to tear down. }() return child } diff --git a/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit/ratelimit_test.go b/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit/ratelimit_test.go index 4d559cee4..90fb5a208 100644 --- a/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit/ratelimit_test.go +++ b/Godeps/_workspace/src/github.com/jbenet/goprocess/ratelimit/ratelimit_test.go @@ -46,7 +46,7 @@ func TestRateLimitLimitedGoBlocks(t *testing.T) { t.Log("should be done spawning.") select { case <-doneSpawning: - case <-time.After(time.Millisecond): // for scheduler + case <-time.After(100 * time.Millisecond): // for scheduler t.Error("still blocked...") } @@ -84,7 +84,7 @@ func TestRateLimitGoDoesntBlock(t *testing.T) { select { case <-doneSpawning: t.Log("did not block") - case <-time.After(time.Millisecond): // for scheduler + case <-time.After(100 * time.Millisecond): // for scheduler t.Error("process.Go blocked. it should not.") }