mirror of
https://github.com/panjf2000/ants.git
synced 2025-12-16 18:11:03 +00:00
* add loop queue
* add loop queue
* fix the bugs
add loop queue
move the worker queue to directory
按照新的接口实现 lifo 队列
添加新接口的环形队列实现
rename the slice queue
修复了 unlock
使用 queue 管理 goWorkerWithFunc
使用 dequeue 判断队列
add remainder
增加测试文件
循环队列需要一个空闲位
* remove interface{}
* Refine the logic of sync.Pool
* Add flowcharts of ants into READMEs
* Add the installation about ants v2
* Renew the functional options in READMEs
* Renew English and Chinese flowcharts
* rename package name
移动 worker queue 位置
worker queue 都修改为私有接口
考虑到性能问题,把 interface{} 改回到 *goworker
* 修改 releaseExpiry 和 releaseAll
* remove files
* fix some bug
74 lines
1.0 KiB
Go
74 lines
1.0 KiB
Go
package ants
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestNewLoopQueue(t *testing.T) {
|
|
size := 100
|
|
q := newLoopQueue(size)
|
|
if q.len() != 0 {
|
|
t.Fatalf("Len error")
|
|
}
|
|
|
|
if q.cap() != size {
|
|
t.Fatalf("Cap error")
|
|
}
|
|
|
|
if !q.isEmpty() {
|
|
t.Fatalf("IsEmpty error")
|
|
}
|
|
|
|
if q.dequeue() != nil {
|
|
t.Fatalf("Dequeue error")
|
|
}
|
|
}
|
|
|
|
func TestLoopQueue(t *testing.T) {
|
|
size := 10
|
|
q := newLoopQueue(size)
|
|
|
|
for i := 0; i < 5; i++ {
|
|
err := q.enqueue(&goWorker{recycleTime: time.Now()})
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
|
|
if q.len() != 5 {
|
|
t.Fatalf("Len error")
|
|
}
|
|
|
|
v := q.dequeue()
|
|
t.Log(v)
|
|
|
|
if q.len() != 4 {
|
|
t.Fatalf("Len error")
|
|
}
|
|
|
|
time.Sleep(time.Second)
|
|
|
|
for i := 0; i < 6; i++ {
|
|
err := q.enqueue(&goWorker{recycleTime: time.Now()})
|
|
if err != nil {
|
|
break
|
|
}
|
|
}
|
|
|
|
if q.len() != 10 {
|
|
t.Fatalf("Len error")
|
|
}
|
|
|
|
err := q.enqueue(&goWorker{recycleTime: time.Now()})
|
|
if err == nil {
|
|
t.Fatalf("Enqueue error")
|
|
}
|
|
|
|
q.releaseExpiry(time.Second)
|
|
|
|
if q.len() != 6 {
|
|
t.Fatalf("Len error: %d", q.len())
|
|
}
|
|
}
|