38 lines
691 B
Go
38 lines
691 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()
|
|
|
|
db := NewTestDBIn(t.TempDir())
|
|
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{}{}
|
|
}
|
|
}
|
|
}
|