Read a pull's held asks with Fetch, hand them back all through a build, and drop a duplicate only while its builder's key is fresh (issue 1649)
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package link
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -13,24 +12,24 @@ import (
|
||||
|
||||
type fakeHeld struct{ msgs []*nats.Msg }
|
||||
|
||||
func (f *fakeHeld) NextMsg(time.Duration) (*nats.Msg, error) {
|
||||
func (f *fakeHeld) Held() *nats.Msg {
|
||||
if len(f.msgs) == 0 {
|
||||
return nil, nats.ErrTimeout
|
||||
return nil
|
||||
}
|
||||
m := f.msgs[0]
|
||||
f.msgs = f.msgs[1:]
|
||||
return m, nil
|
||||
return m
|
||||
}
|
||||
|
||||
type brokenHeld struct{}
|
||||
type emptyHeld struct{}
|
||||
|
||||
func (brokenHeld) NextMsg(time.Duration) (*nats.Msg, error) { return nil, errors.New("closed") }
|
||||
func (emptyHeld) Held() *nats.Msg { return nil }
|
||||
|
||||
func TestEveryMessageAPullHoldsIsHandedBackBeforeABuildStarts(t *testing.T) {
|
||||
a := &fakeHeld{msgs: []*nats.Msg{{Subject: "a1"}, {Subject: "a2"}}}
|
||||
b := &fakeHeld{msgs: []*nats.Msg{{Subject: "b1"}}}
|
||||
var back []string
|
||||
n := handBackHeld([]heldSource{a, brokenHeld{}, b}, func(m *nats.Msg) { back = append(back, m.Subject) })
|
||||
n := handBackHeld([]heldSource{a, emptyHeld{}, b}, func(m *nats.Msg) { back = append(back, m.Subject) })
|
||||
if n != 3 || len(back) != 3 || back[0] != "a1" || back[2] != "b1" {
|
||||
t.Fatalf("handed back %d %v; want a1 a2 b1", n, back)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user