Files
patrickandClaude Sonnet 5.5 e428de553d
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (pull_request) Canceled after 0s
CI / Core-Modul (Build/Vet/Test) (push) Successful in 39s
CI / Web-Barrierefreiheitspruefung (axe, Tastatur, Reflow, Textabstaende) (push) Canceled after 0s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (push) Successful in 3s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (push) Successful in 3s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (push) Failing after 14s
CI / Web (dms-browser) (push) Failing after 53s
CI / Web (pdf-viewer) (push) Failing after 38s
CI / Web (shl) (push) Failing after 7s
CI / Core-Modul (Build/Vet/Test) (pull_request) Successful in 37s
CI / DMS Security-Test-Gate (AC5, Merge-Gate) (pull_request) Successful in 3s
CI / Connect Security-Test-Gate (QA-01 AC4, Merge-Gate) (pull_request) Successful in 2s
CI / DMS-Modul Supply-Chain-Scan (govulncheck) (pull_request) Failing after 13s
CI / Web (dms-browser) (pull_request) Failing after 49s
CI / Web (pdf-viewer) (pull_request) Failing after 39s
CI / Web (shl) (pull_request) Failing after 7s
Supply-Chain-Scan (Go) / govulncheck (push) Failing after 1m15s
Core-Schnittstellen-Vertragstests / contract-tests (pull_request) Successful in 13m17s
Supply-Chain-Scan (Go) / govulncheck (pull_request) Failing after 53s
Supply-Chain-Scan (npm) / npm-audit (pull_request) Failing after 1m21s
Core-Pflichttest-Gate / pflichttest-gate (pull_request) Successful in 13m17s
RBAC-Rollenhierarchie-Pflichtgate / rbac-policy-invariant (pull_request) Successful in 12m42s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (pull_request) Canceled after 0s
CI / DMS-Modul (Lint/Build/Test/Coverage/Artefakt) (push) Canceled after 0s
account-api: DB-Start mit Backoff und Fehlerklassifizierung, systemd-Restart-Limits
Dauerhafte Fehler (28P01, 28000, 3D000) beenden mit Exit 2 und klarer Meldung,
transiente Fehler werden bis NEXARCH_ACCOUNT_DB_STARTUP_TIMEOUT_SECONDS wiederholt.
Unit-Template: RestartSec, StartLimit, RestartPreventExitStatus=2.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-28 14:22:40 +01:00

67 lines
1.9 KiB
Go

package main
import (
"context"
"errors"
"testing"
"time"
"github.com/jackc/pgx/v5/pgconn"
)
type fakePinger struct {
errs []error
calls int
}
func (f *fakePinger) Ping(context.Context) error {
i := f.calls
f.calls++
if i < len(f.errs) {
return f.errs[i]
}
return nil
}
func TestWaitForDB_PermanentAuthErrorStopsImmediately(t *testing.T) {
p := &fakePinger{errs: []error{&pgconn.PgError{Code: "28P01"}, nil}}
sleeps := 0
err := waitForDB(context.Background(), p, time.Minute, func(time.Duration) { sleeps++ })
if err == nil || !isPermanentDBError(err) {
t.Fatalf("erwartet dauerhaften fehler, war %v", err)
}
if p.calls != 1 || sleeps != 0 {
t.Fatalf("kein retry erwartet, calls=%d sleeps=%d", p.calls, sleeps)
}
}
func TestWaitForDB_TransientErrorRetriesWithBackoff(t *testing.T) {
p := &fakePinger{errs: []error{errors.New("connection refused"), errors.New("connection refused")}}
var delays []time.Duration
if err := waitForDB(context.Background(), p, time.Minute, func(d time.Duration) { delays = append(delays, d) }); err != nil {
t.Fatal(err)
}
if p.calls != 3 || len(delays) != 2 || delays[1] <= delays[0] {
t.Fatalf("calls=%d delays=%v", p.calls, delays)
}
}
func TestWaitForDB_GivesUpAfterTimeout(t *testing.T) {
p := &fakePinger{errs: []error{errors.New("x"), errors.New("x"), errors.New("x"), errors.New("x")}}
err := waitForDB(context.Background(), p, 0, func(time.Duration) {})
if err == nil || isPermanentDBError(err) {
t.Fatalf("erwartet transienten timeout-fehler, war %v", err)
}
}
func TestIsPermanentDBError(t *testing.T) {
for code, want := range map[string]bool{"28P01": true, "28000": true, "3D000": true, "57P03": false} {
if got := isPermanentDBError(&pgconn.PgError{Code: code}); got != want {
t.Errorf("%s: got %v", code, got)
}
}
if isPermanentDBError(errors.New("connection refused")) {
t.Error("verbindungsfehler ist transient")
}
}