go-study/lock_free/delay_queue_test.go

34 lines
529 B
Go
Raw Normal View History

package lock_free
import (
"testing"
"time"
)
func TestDelayLkQueue(t *testing.T) {
cases := []struct {
value int
duration time.Duration
}{
{1, time.Second},
{3, time.Second * 3},
}
2024-12-03 11:14:58 +08:00
q := NewDelayLkQueue[int](WithGap(time.Millisecond * 100))
for _, c := range cases {
q.DelayEnqueue(c.value, c.duration)
}
2024-12-03 10:49:09 +08:00
notify := make(chan int)
go func() {
2024-12-03 10:49:09 +08:00
for data := range notify {
t.Log(data)
t.Log(time.Now().Unix())
}
}()
2024-12-03 10:49:09 +08:00
go q.ContinuousDequeue(notify)
time.Sleep(time.Second * 5)
2024-12-03 10:49:09 +08:00
close(notify)
}