Bound MarkAbandoned's compare-and-set retries, giving up after 10 tries (issue 711)
This commit is contained in:
@@ -230,6 +230,40 @@ func TestNatsAFinishRacingTheSweepsWriteWins(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// alwaysMismatchKV wraps a jetstream.KeyValue whose Update always fails with a revision mismatch, as
|
||||
// if some other writer kept winning the race forever (novox/hq issue 711 review round 1).
|
||||
type alwaysMismatchKV struct {
|
||||
jetstream.KeyValue
|
||||
tries *int
|
||||
}
|
||||
|
||||
func (a alwaysMismatchKV) Update(ctx context.Context, key string, value []byte, revision uint64) (uint64, error) {
|
||||
*a.tries++
|
||||
return 0, jetstream.ErrKeyRevisionMismatch
|
||||
}
|
||||
|
||||
// **MarkAbandoned gives up after markAbandonedTries rather than loop forever** (novox/hq issue 711
|
||||
// review round 1): a record whose compare-and-set keeps losing is left as it stands, said in an
|
||||
// error naming the call, not retried without end.
|
||||
func TestNatsAMarkAbandonedGivesUpAfterTenTries(t *testing.T) {
|
||||
keeper := callsBucket(t)
|
||||
running := Call{ID: "call-711-4", Seat: "mesh-controller", Verb: "push", State: CallRunning, Holder: "controller@one"}
|
||||
if err := keeper.Keep(t.Context(), running); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
waitKept(t, keeper, running.ID, CallRunning)
|
||||
|
||||
tries := 0
|
||||
stuck := &BusCalls{kv: alwaysMismatchKV{KeyValue: keeper.kv, tries: &tries}}
|
||||
_, err := stuck.MarkAbandoned(t.Context(), running.ID)
|
||||
if err == nil || !strings.Contains(err.Error(), running.ID) {
|
||||
t.Fatalf("expected an error naming %s, got %v", running.ID, err)
|
||||
}
|
||||
if tries != markAbandonedTries {
|
||||
t.Fatalf("tried %d times, want %d", tries, markAbandonedTries)
|
||||
}
|
||||
}
|
||||
|
||||
// The bucket holds the last thousand calls or fourteen days: a call is two keys, so the stream under
|
||||
// it holds twice as many messages, and asserting it again keeps the count.
|
||||
func TestNatsTheCallsBucketIsBounded(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user