Fix a issue in testing nonblocking pool

This commit is contained in:
Andy Pan 2019-10-04 11:36:11 +08:00
parent b0ec5102cc
commit 0a946593e2
1 changed files with 3 additions and 1 deletions

View File

@ -421,8 +421,10 @@ func TestNonblockingSubmit(t *testing.T) {
} }
} }
ch := make(chan struct{}) ch := make(chan struct{})
ch1 := make(chan struct{})
f := func() { f := func() {
<-ch <-ch
close(ch1)
} }
// p is full now. // p is full now.
if err := p.Submit(f); err != nil { if err := p.Submit(f); err != nil {
@ -433,7 +435,7 @@ func TestNonblockingSubmit(t *testing.T) {
} }
// interrupt f to get an available worker // interrupt f to get an available worker
close(ch) close(ch)
time.Sleep(1 * time.Second) <-ch1
if err := p.Submit(demoFunc); err != nil { if err := p.Submit(demoFunc); err != nil {
t.Fatalf("nonblocking submit when pool is not full shouldn't return error") t.Fatalf("nonblocking submit when pool is not full shouldn't return error")
} }