diff --git a/paddle/go/pserver/service_test.go b/paddle/go/pserver/service_test.go index 23b2d17dc7f49e9804f9662b20e9a00127b188ce..6aa7f47c7475ca27f5d1155609349c3a73f19827 100644 --- a/paddle/go/pserver/service_test.go +++ b/paddle/go/pserver/service_test.go @@ -110,6 +110,7 @@ func TestMultipleInit(t *testing.T) { func TestBlockUntilInitialized(t *testing.T) { s := pserver.NewService() + ch := make(chan struct{}, 3) var wg sync.WaitGroup wg.Add(1) go func() { @@ -119,6 +120,7 @@ func TestBlockUntilInitialized(t *testing.T) { t.FailNow() } wg.Done() + ch <- struct{}{} }() wg.Add(1) @@ -129,6 +131,7 @@ func TestBlockUntilInitialized(t *testing.T) { t.FailNow() } wg.Done() + ch <- struct{}{} }() wg.Add(1) @@ -139,6 +142,7 @@ func TestBlockUntilInitialized(t *testing.T) { t.FailNow() } wg.Done() + ch <- struct{}{} }() var dummy int @@ -147,6 +151,13 @@ func TestBlockUntilInitialized(t *testing.T) { t.FailNow() } + select { + case <-ch: + // some function returned before initialization is completed. + t.FailNow() + default: + } + err = s.FinishInitParams(0, &dummy) if err != nil { t.FailNow()