queue from Dequeue to Syn for SynAck
parent
8193bf7377
commit
e85a2d25a1
6
queue.go
6
queue.go
|
|
@ -35,9 +35,9 @@ func (q Queue) Enqueue(ctx context.Context, b []byte) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q Queue) Dequeue(ctx context.Context) (string, []byte, error) {
|
func (q Queue) Syn(ctx context.Context) (string, []byte, error) {
|
||||||
for {
|
for {
|
||||||
reservation, m, err := q.dequeue(ctx)
|
reservation, m, err := q.syn(ctx)
|
||||||
if reservation != nil || err != nil {
|
if reservation != nil || err != nil {
|
||||||
return string(reservation), m, err
|
return string(reservation), m, err
|
||||||
}
|
}
|
||||||
|
|
@ -50,7 +50,7 @@ func (q Queue) Dequeue(ctx context.Context) (string, []byte, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q Queue) dequeue(ctx context.Context) ([]byte, []byte, error) {
|
func (q Queue) syn(ctx context.Context) ([]byte, []byte, error) {
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
reservation := []byte(uuid.New().String())
|
reservation := []byte(uuid.New().String())
|
||||||
var payload []byte
|
var payload []byte
|
||||||
|
|
|
||||||
|
|
@ -25,13 +25,13 @@ func TestQueue(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("dequeue", func(t *testing.T) {
|
t.Run("syn ack", func(t *testing.T) {
|
||||||
found := map[string]struct{}{}
|
found := map[string]struct{}{}
|
||||||
for i := 0; i < 39; i++ {
|
for i := 0; i < 39; i++ {
|
||||||
if reservation, b, err := q.Dequeue(ctx); err != nil {
|
if reservation, b, err := q.Syn(ctx); err != nil {
|
||||||
t.Fatal(i, "dequeue err", err)
|
t.Fatal(i, "syn err", err)
|
||||||
} else if _, ok := found[string(b)]; ok {
|
} else if _, ok := found[string(b)]; ok {
|
||||||
t.Errorf("dequeued %q twice (%+v)", b, found)
|
t.Errorf("syn'd %q twice (%+v)", b, found)
|
||||||
} else if err := q.Ack(ctx, reservation); err != nil {
|
} else if err := q.Ack(ctx, reservation); err != nil {
|
||||||
t.Fatal(i, "failed to ack", err)
|
t.Fatal(i, "failed to ack", err)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue