main
Bel LaPointe 2024-04-12 09:02:08 -06:00
parent 233ba8ae2b
commit 634255725a
1 changed files with 41 additions and 0 deletions

41
queue_test.go Normal file
View File

@ -0,0 +1,41 @@
package main
import (
"context"
"path"
"strconv"
"testing"
"time"
)
func TestQueue(t *testing.T) {
ctx, can := context.WithTimeout(context.Background(), time.Second*10)
defer can()
db, err := NewDB(path.Join(t.TempDir(), "q"))
if err != nil {
t.Fatal(err)
}
defer db.Close()
q := NewQueue(db)
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{}{}
}
}
}