go-study/lock_free/delay_queue_test.go

34 lines
529 B
Go

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},
}
q := NewDelayLkQueue[int](WithGap(time.Millisecond * 100))
for _, c := range cases {
q.DelayEnqueue(c.value, c.duration)
}
notify := make(chan int)
go func() {
for data := range notify {
t.Log(data)
t.Log(time.Now().Unix())
}
}()
go q.ContinuousDequeue(notify)
time.Sleep(time.Second * 5)
close(notify)
}