forked from mirror/ants
add codecov test
This commit is contained in:
parent
d77f01cf9a
commit
23c80e1158
10
.travis.yml
10
.travis.yml
|
@ -6,6 +6,12 @@ go:
|
||||||
- "1.10.x"
|
- "1.10.x"
|
||||||
- master
|
- master
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- go get -t -v ./...
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- go test -v ./...
|
- go test -race -coverprofile=coverage.txt -covermode=atomic
|
||||||
- go test -bench=. -benchmem=true -run=none ./...
|
- go test -bench=. -benchmem=true -run=none ./...
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
- bash <(curl -s https://codecov.io/bash)
|
|
@ -42,9 +42,9 @@ const (
|
||||||
YiB // 1208925819614629174706176
|
YiB // 1208925819614629174706176
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
RunTimes = 1000000
|
RunTimes = 1000
|
||||||
Param = 10
|
Param = 10
|
||||||
AntsSize = 100000
|
AntsSize = 100
|
||||||
)
|
)
|
||||||
|
|
||||||
func demoFunc() error {
|
func demoFunc() error {
|
||||||
|
|
66
ants_test.go
66
ants_test.go
|
@ -30,9 +30,29 @@ import (
|
||||||
"github.com/panjf2000/ants"
|
"github.com/panjf2000/ants"
|
||||||
)
|
)
|
||||||
|
|
||||||
var n = 1000000
|
var n = 1000
|
||||||
|
|
||||||
func TestDefaultPool(t *testing.T) {
|
func TestAntsPoolWithFunc(t *testing.T) {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
p, _ := ants.NewPoolWithFunc(AntsSize, func(i interface{}) error {
|
||||||
|
demoPoolFunc(i)
|
||||||
|
wg.Done()
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
defer p.Release()
|
||||||
|
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
wg.Add(1)
|
||||||
|
p.Serve(n)
|
||||||
|
}
|
||||||
|
wg.Wait()
|
||||||
|
|
||||||
|
mem := runtime.MemStats{}
|
||||||
|
runtime.ReadMemStats(&mem)
|
||||||
|
t.Logf("memory usage:%d", mem.TotalAlloc/GiB)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAntsPool(t *testing.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++ {
|
||||||
|
@ -45,10 +65,6 @@ func TestDefaultPool(t *testing.T) {
|
||||||
}
|
}
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
//t.Logf("pool capacity:%d", ants.Cap())
|
|
||||||
//t.Logf("free workers number:%d", ants.Free())
|
|
||||||
|
|
||||||
t.Logf("running workers number:%d", ants.Running())
|
|
||||||
mem := runtime.MemStats{}
|
mem := runtime.MemStats{}
|
||||||
runtime.ReadMemStats(&mem)
|
runtime.ReadMemStats(&mem)
|
||||||
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
|
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
|
||||||
|
@ -70,27 +86,27 @@ func TestNoPool(t *testing.T) {
|
||||||
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
|
t.Logf("memory usage:%d MB", mem.TotalAlloc/MiB)
|
||||||
}
|
}
|
||||||
|
|
||||||
// func TestAntsPoolWithFunc(t *testing.T) {
|
func TestCodeCov(t *testing.T) {
|
||||||
// var wg sync.WaitGroup
|
defer ants.Release()
|
||||||
// p, _ := ants.NewPoolWithFunc(50000, func(i interface{}) error {
|
for i := 0; i < n; i++ {
|
||||||
// demoPoolFunc(i)
|
ants.Submit(demoFunc)
|
||||||
// wg.Done()
|
}
|
||||||
// return nil
|
t.Logf("pool, capacity:%d", ants.Cap())
|
||||||
// })
|
t.Logf("pool, running workers number:%d", ants.Running())
|
||||||
// for i := 0; i < n; i++ {
|
t.Logf("pool, free workers number:%d", ants.Free())
|
||||||
// wg.Add(1)
|
|
||||||
// p.Serve(n)
|
|
||||||
// }
|
|
||||||
// wg.Wait()
|
|
||||||
|
|
||||||
// //t.Logf("pool capacity:%d", ants.Cap())
|
p, _ := ants.NewPoolWithFunc(AntsSize, demoPoolFunc)
|
||||||
// //t.Logf("free workers number:%d", ants.Free())
|
defer p.Release()
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
p.Serve(n)
|
||||||
|
}
|
||||||
|
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, free workers number:%d", p.Free())
|
||||||
|
p.ReSize(AntsSize / 2)
|
||||||
|
t.Logf("pool with func, after resize, capacity:%d", p.Cap())
|
||||||
|
|
||||||
// t.Logf("running workers number:%d", p.Running())
|
}
|
||||||
// mem := runtime.MemStats{}
|
|
||||||
// runtime.ReadMemStats(&mem)
|
|
||||||
// t.Logf("memory usage:%d", mem.TotalAlloc/GiB)
|
|
||||||
// }
|
|
||||||
|
|
||||||
// func TestNoPool(t *testing.T) {
|
// func TestNoPool(t *testing.T) {
|
||||||
// var wg sync.WaitGroup
|
// var wg sync.WaitGroup
|
||||||
|
|
Loading…
Reference in New Issue