test q
This commit is contained in:
41
queue_test.go
Normal file
41
queue_test.go
Normal 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{}{}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user