fix(dispenser): tolerate unusable AP observations during card preparation
This commit is contained in:
@@ -121,11 +121,11 @@ func TestIssueDoorCardPhysicalOutcomeContract(t *testing.T) {
|
||||
wantCardWell string
|
||||
}{
|
||||
{
|
||||
name: "initial dispenser preparation failure is unavailable",
|
||||
name: "initial dispenser preparation failure is retryable",
|
||||
dispenser: fakeDoorCardDispenser{
|
||||
prepareCurrent: dispenserCallResult{status: "Card jammed", err: errors.New("card jammed")},
|
||||
},
|
||||
wantHTTP: http.StatusServiceUnavailable,
|
||||
wantHTTP: http.StatusBadGateway,
|
||||
wantMessage: "Dispense error: card jammed",
|
||||
wantCalls: []string{"prepare current"},
|
||||
wantCardWell: "Card jammed",
|
||||
@@ -353,3 +353,27 @@ func TestIssueDoorCardLogsDeliveryFailureWithoutReplacingEncoderOutcome(t *testi
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssueDoorCardOnlyEmptyPreparationReturns503(t *testing.T) {
|
||||
for _, failure := range []error{
|
||||
dispenser.ErrCardWellEmpty, errors.Join(errors.New("wrapped"), dispenser.ErrCardWellEmpty),
|
||||
dispenser.ErrPreparationExhausted, context.Canceled, context.DeadlineExceeded,
|
||||
errors.New("malformed AP"), errors.New("truncated AP"), errors.New("no response"),
|
||||
errors.New("serial read failed"), errors.New("serial write failed"), errors.New("FC7 dispatch failed"),
|
||||
errors.New("RS dispatch failed"), errors.New(dispenser.CardWellEmptyMessage), errors.New("other preparation error"),
|
||||
} {
|
||||
d := &fakeDoorCardDispenser{prepareCurrent: dispenserCallResult{err: failure}}
|
||||
lock := &fakeDoorCardLockServer{}
|
||||
recorder, response, _ := performIssueDoorCardRequest(t, d, lock)
|
||||
want := http.StatusBadGateway
|
||||
if errors.Is(failure, dispenser.ErrCardWellEmpty) {
|
||||
want = http.StatusServiceUnavailable
|
||||
}
|
||||
if recorder.Code != want || response.Code != want {
|
||||
t.Errorf("preparation %v HTTP=%d body=%d, want %d", failure, recorder.Code, response.Code, want)
|
||||
}
|
||||
if lock.sequenceCalls != 0 || !reflect.DeepEqual(d.calls, []string{"prepare current"}) {
|
||||
t.Errorf("preparation %v encoder=%d calls=%v, want no physical continuation", failure, lock.sequenceCalls, d.calls)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user