mirror of https://github.com/panjf2000/ants.git
🌊 Updated to fit the refactor
This commit is contained in:
parent
c50c1eac23
commit
29f47ced64
38
ants_test.go
38
ants_test.go
|
@ -123,10 +123,11 @@ func TestPanicHandler(t *testing.T) {
|
||||||
p0.PanicHandler = func(p interface{}) {
|
p0.PanicHandler = func(p interface{}) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
atomic.AddInt64(&panicCounter, 1)
|
atomic.AddInt64(&panicCounter, 1)
|
||||||
|
t.Logf("catch panic with PanicHandler: %v", p)
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
p0.Submit(func() {
|
p0.Submit(func() {
|
||||||
panic("test")
|
panic("Oops!")
|
||||||
})
|
})
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
c := atomic.LoadInt64(&panicCounter)
|
c := atomic.LoadInt64(&panicCounter)
|
||||||
|
@ -136,6 +137,7 @@ func TestPanicHandler(t *testing.T) {
|
||||||
if p0.Running() != 0 {
|
if p0.Running() != 0 {
|
||||||
t.Errorf("pool should be empty after panic")
|
t.Errorf("pool should be empty after panic")
|
||||||
}
|
}
|
||||||
|
|
||||||
p1, err := ants.NewPoolWithFunc(10, func(p interface{}) {
|
p1, err := ants.NewPoolWithFunc(10, func(p interface{}) {
|
||||||
panic(p)
|
panic(p)
|
||||||
})
|
})
|
||||||
|
@ -148,7 +150,7 @@ func TestPanicHandler(t *testing.T) {
|
||||||
atomic.AddInt64(&panicCounter, 1)
|
atomic.AddInt64(&panicCounter, 1)
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
p1.Serve("test")
|
p1.Serve("Oops!")
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
c = atomic.LoadInt64(&panicCounter)
|
c = atomic.LoadInt64(&panicCounter)
|
||||||
if c != 2 {
|
if c != 2 {
|
||||||
|
@ -159,6 +161,26 @@ func TestPanicHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPoolPanicWithoutHandler(t *testing.T) {
|
||||||
|
p0, err := ants.NewPool(10)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("create new pool failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
defer p0.Release()
|
||||||
|
p0.Submit(func() {
|
||||||
|
panic("Oops!")
|
||||||
|
})
|
||||||
|
|
||||||
|
p1, err := ants.NewPoolWithFunc(10, func(p interface{}) {
|
||||||
|
panic(p)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("create new pool with func failed: %s", err.Error())
|
||||||
|
}
|
||||||
|
defer p1.Release()
|
||||||
|
p1.Serve("Oops!")
|
||||||
|
}
|
||||||
|
|
||||||
func TestCodeCov(t *testing.T) {
|
func TestCodeCov(t *testing.T) {
|
||||||
_, err := ants.NewTimingPool(-1, -1)
|
_, err := ants.NewTimingPool(-1, -1)
|
||||||
t.Log(err)
|
t.Log(err)
|
||||||
|
@ -178,9 +200,9 @@ func TestCodeCov(t *testing.T) {
|
||||||
t.Logf("pool, capacity:%d", p0.Cap())
|
t.Logf("pool, capacity:%d", p0.Cap())
|
||||||
t.Logf("pool, running workers number:%d", p0.Running())
|
t.Logf("pool, running workers number:%d", p0.Running())
|
||||||
t.Logf("pool, free workers number:%d", p0.Free())
|
t.Logf("pool, free workers number:%d", p0.Free())
|
||||||
p0.ReSize(AntsSize)
|
p0.Tune(AntsSize)
|
||||||
p0.ReSize(AntsSize / 2)
|
p0.Tune(AntsSize / 2)
|
||||||
t.Logf("pool, after resize, capacity:%d, running:%d", p0.Cap(), p0.Running())
|
t.Logf("pool, after tuning capacity, capacity:%d, running:%d", p0.Cap(), p0.Running())
|
||||||
|
|
||||||
p, _ := ants.NewPoolWithFunc(TestSize, demoPoolFunc)
|
p, _ := ants.NewPoolWithFunc(TestSize, demoPoolFunc)
|
||||||
defer p.Serve(Param)
|
defer p.Serve(Param)
|
||||||
|
@ -192,9 +214,9 @@ func TestCodeCov(t *testing.T) {
|
||||||
t.Logf("pool with func, capacity:%d", p.Cap())
|
t.Logf("pool with func, capacity:%d", p.Cap())
|
||||||
t.Logf("pool with func, running workers number:%d", p.Running())
|
t.Logf("pool with func, running workers number:%d", p.Running())
|
||||||
t.Logf("pool with func, free workers number:%d", p.Free())
|
t.Logf("pool with func, free workers number:%d", p.Free())
|
||||||
p.ReSize(TestSize)
|
p.Tune(TestSize)
|
||||||
p.ReSize(AntsSize)
|
p.Tune(AntsSize)
|
||||||
t.Logf("pool with func, after resize, capacity:%d, running:%d", p.Cap(), p.Running())
|
t.Logf("pool with func, after tuning capacity, capacity:%d, running:%d", p.Cap(), p.Running())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPurge(t *testing.T) {
|
func TestPurge(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue