spoc-bot-vr/queue_test.go

35 lines
646 B
Go

package main
import (
"context"
"strconv"
"testing"
"time"
)
func TestQueue(t *testing.T) {
ctx, can := context.WithTimeout(context.Background(), time.Second*10)
defer can()
q := NewQueue(NewRAM())
for i := 0; i < 39; i++ {
if err := q.Push(ctx, Message{ID: strconv.Itoa(i), TS: uint64(i)}); err != nil {
t.Fatal(i, err)
}
}
found := map[uint64]struct{}{}
for i := 0; i < 39; i++ {
if m, err := q.PeekFirst(ctx); err != nil {
t.Fatal(i, err)
} else if _, ok := found[m.TS]; ok {
t.Error(i, m.TS)
} else if err := q.Ack(ctx, m.ID); err != nil {
t.Fatal(i, err)
} else {
found[m.TS] = struct{}{}
}
}
}