15 Star 55 Fork 14

bits-chen / go-goes

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
worker_test.go 702 Bytes
一键复制 编辑 原始数据 按行查看 历史
yoojia.chen 提交于 2018-06-06 16:51 . Update a beautiful impl
package goes
import (
"testing"
"time"
)
//
// Author: 陈永佳 chenyongjia@parkingwang.com, yoojiachen@gmail.com
//
func TestWorker_Run(t *testing.T) {
w := newWorker()
defer close(w.tasks)
idles := make(chan *worker, 1)
go w.work(idles)
done := make(chan bool)
w.tasks <- func() {
done <- true
}
time.AfterFunc(time.Millisecond, func() {
t.Error("Timeout")
})
<-done
select {
case <-idles:
t.Log("Test ok")
default:
t.Error("Notify idle not call")
}
}
func BenchmarkWorker(b *testing.B) {
w := newWorker()
defer close(w.tasks)
idles := make(chan *worker, b.N)
go w.work(idles)
count := 0
for i := 0; i < b.N; i++ {
w.tasks <- func() {
count++
}
}
}
Go
1
https://gitee.com/bitschen/go-goes.git
git@gitee.com:bitschen/go-goes.git
bitschen
go-goes
go-goes
master

搜索帮助