1 Star 0 Fork 14

夜丶丶/go-goes

forked from bits-chen/go-goes 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
worker_test.go 702 Bytes
一键复制 编辑 原始数据 按行查看 历史
yoojia.chen 提交于 2018-06-06 16:51 +08:00 . 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++
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/nt_night/go-goes.git
git@gitee.com:nt_night/go-goes.git
nt_night
go-goes
go-goes
master

搜索帮助