mirror of https://github.com/panjf2000/ants.git
🎷 Reset the unit tests to default core number
This commit is contained in:
parent
204e93011d
commit
e988680ffc
19
ants_test.go
19
ants_test.go
|
@ -51,17 +51,10 @@ const (
|
||||||
n = 100000
|
n = 100000
|
||||||
)
|
)
|
||||||
|
|
||||||
func SkipIfNotMultiCores(t *testing.T) {
|
|
||||||
if runtime.GOMAXPROCS(0) == 1 {
|
|
||||||
t.SkipNow()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var curMem uint64
|
var curMem uint64
|
||||||
|
|
||||||
// TestAntsPoolWaitToGetWorker is used to test waiting to get worker.
|
// TestAntsPoolWaitToGetWorker is used to test waiting to get worker.
|
||||||
func TestAntsPoolWaitToGetWorker(t *testing.T) {
|
func TestAntsPoolWaitToGetWorker(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
p, _ := ants.NewPool(AntsSize)
|
p, _ := ants.NewPool(AntsSize)
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
|
@ -83,7 +76,6 @@ func TestAntsPoolWaitToGetWorker(t *testing.T) {
|
||||||
|
|
||||||
// TestAntsPoolWithFuncWaitToGetWorker is used to test waiting to get worker.
|
// TestAntsPoolWithFuncWaitToGetWorker is used to test waiting to get worker.
|
||||||
func TestAntsPoolWithFuncWaitToGetWorker(t *testing.T) {
|
func TestAntsPoolWithFuncWaitToGetWorker(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
p, _ := ants.NewPoolWithFunc(AntsSize, func(i interface{}) {
|
p, _ := ants.NewPoolWithFunc(AntsSize, func(i interface{}) {
|
||||||
demoPoolFunc(i)
|
demoPoolFunc(i)
|
||||||
|
@ -105,7 +97,6 @@ func TestAntsPoolWithFuncWaitToGetWorker(t *testing.T) {
|
||||||
|
|
||||||
// TestAntsPoolGetWorkerFromCache is used to test getting worker from sync.Pool.
|
// TestAntsPoolGetWorkerFromCache is used to test getting worker from sync.Pool.
|
||||||
func TestAntsPoolGetWorkerFromCache(t *testing.T) {
|
func TestAntsPoolGetWorkerFromCache(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
p, _ := ants.NewPool(TestSize)
|
p, _ := ants.NewPool(TestSize)
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
|
|
||||||
|
@ -123,7 +114,6 @@ func TestAntsPoolGetWorkerFromCache(t *testing.T) {
|
||||||
|
|
||||||
// TestAntsPoolWithFuncGetWorkerFromCache is used to test getting worker from sync.Pool.
|
// TestAntsPoolWithFuncGetWorkerFromCache is used to test getting worker from sync.Pool.
|
||||||
func TestAntsPoolWithFuncGetWorkerFromCache(t *testing.T) {
|
func TestAntsPoolWithFuncGetWorkerFromCache(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
dur := 10
|
dur := 10
|
||||||
p, _ := ants.NewPoolWithFunc(TestSize, demoPoolFunc)
|
p, _ := ants.NewPoolWithFunc(TestSize, demoPoolFunc)
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
|
@ -144,7 +134,6 @@ func TestAntsPoolWithFuncGetWorkerFromCache(t *testing.T) {
|
||||||
// Contrast between goroutines without a pool and goroutines with ants pool.
|
// Contrast between goroutines without a pool and goroutines with ants pool.
|
||||||
//-------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------
|
||||||
func TestNoPool(t *testing.T) {
|
func TestNoPool(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
|
@ -162,7 +151,6 @@ func TestNoPool(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAntsPool(t *testing.T) {
|
func TestAntsPool(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
defer ants.Release()
|
defer ants.Release()
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
|
@ -188,7 +176,6 @@ func TestAntsPool(t *testing.T) {
|
||||||
//-------------------------------------------------------------------------------------------
|
//-------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
func TestPanicHandler(t *testing.T) {
|
func TestPanicHandler(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
p0, err := ants.NewPool(10)
|
p0, err := ants.NewPool(10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("create new pool failed: %s", err.Error())
|
t.Fatalf("create new pool failed: %s", err.Error())
|
||||||
|
@ -238,7 +225,6 @@ func TestPanicHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPoolPanicWithoutHandler(t *testing.T) {
|
func TestPoolPanicWithoutHandler(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
p0, err := ants.NewPool(10)
|
p0, err := ants.NewPool(10)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("create new pool failed: %s", err.Error())
|
t.Fatalf("create new pool failed: %s", err.Error())
|
||||||
|
@ -259,7 +245,6 @@ func TestPoolPanicWithoutHandler(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPurge(t *testing.T) {
|
func TestPurge(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
p, err := ants.NewTimingPool(10, 1)
|
p, err := ants.NewTimingPool(10, 1)
|
||||||
defer p.Release()
|
defer p.Release()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -283,7 +268,6 @@ func TestPurge(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRestCodeCoverage(t *testing.T) {
|
func TestRestCodeCoverage(t *testing.T) {
|
||||||
SkipIfNotMultiCores(t)
|
|
||||||
_, err := ants.NewTimingPool(-1, -1)
|
_, err := ants.NewTimingPool(-1, -1)
|
||||||
t.Log(err)
|
t.Log(err)
|
||||||
_, err = ants.NewTimingPool(1, -1)
|
_, err = ants.NewTimingPool(1, -1)
|
||||||
|
@ -321,6 +305,3 @@ func TestRestCodeCoverage(t *testing.T) {
|
||||||
t.Logf("pool with func, after tuning capacity, 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 TestInSingleCore(t *testing.T) {
|
|
||||||
t.Log("workerChanCap in ants tested.")
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue