diff options
| author | Paul Buetow <paul@buetow.org> | 2026-02-08 10:57:45 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-02-08 10:57:45 +0200 |
| commit | 81db39feafdc491658f8a10dc604be851a533ffc (patch) | |
| tree | 9f84bcaaaef120520ebfc9823f0807abaadcd858 /internal/peer_test.go | |
| parent | 9c78a3666eddf3a6a3b82581e0353665aa3f6320 (diff) | |
feat: add peer failover alertingv1.4.0
Introduce peer URL monitoring with active/passive alert suppression, skip checks when passive, and bump version to v1.4.0.
Co-authored-by: Cursor <cursoragent@cursor.com>
Diffstat (limited to 'internal/peer_test.go')
| -rw-r--r-- | internal/peer_test.go | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/internal/peer_test.go b/internal/peer_test.go new file mode 100644 index 0000000..2cada60 --- /dev/null +++ b/internal/peer_test.go @@ -0,0 +1,83 @@ +package internal + +import ( + "context" + "errors" + "testing" + "time" +) + +func TestPeerActiveAtStale(t *testing.T) { + now := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC) + conf := config{ + PeerURL: "https://peer.example/gogios/index.json", + PeerStaleThresholdS: 600, + PeerPrimaryName: "primary", + PeerSecondaryName: "secondary", + } + + lastUpdated := now.Add(-11 * time.Minute) + active, _ := peerActiveAt(context.Background(), conf, now, "secondary", + func(context.Context, string) (time.Time, error) { + return lastUpdated, nil + }) + + if !active { + t.Fatalf("expected active when peer is stale") + } +} + +func TestPeerActiveAtFreshStandby(t *testing.T) { + now := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC) + conf := config{ + PeerURL: "https://peer.example/gogios/index.json", + PeerStaleThresholdS: 600, + PeerPrimaryName: "primary", + PeerSecondaryName: "secondary", + } + + lastUpdated := now.Add(-1 * time.Minute) + active, _ := peerActiveAt(context.Background(), conf, now, "secondary", + func(context.Context, string) (time.Time, error) { + return lastUpdated, nil + }) + + if active { + t.Fatalf("expected passive when peer is healthy and local is standby") + } +} + +func TestPeerActiveAtFetchError(t *testing.T) { + now := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC) + conf := config{ + PeerURL: "https://peer.example/gogios/index.json", + PeerStaleThresholdS: 600, + PeerPrimaryName: "primary", + PeerSecondaryName: "secondary", + } + + active, _ := peerActiveAt(context.Background(), conf, now, "secondary", + func(context.Context, string) (time.Time, error) { + return time.Time{}, errors.New("boom") + }) + + if !active { + t.Fatalf("expected active on peer fetch error") + } +} + +func TestScheduledMasterWeekParity(t *testing.T) { + primary := "primary" + secondary := "secondary" + + weekOne := time.Date(2023, 1, 1, 0, 0, 0, 0, time.UTC) // Sunday + weekTwo := time.Date(2023, 1, 8, 0, 0, 0, 0, time.UTC) // Next Sunday + + if master := scheduledMaster(primary, secondary, weekOne); master != primary { + t.Fatalf("expected primary to be master in week 1, got %s", master) + } + + if master := scheduledMaster(primary, secondary, weekTwo); master != secondary { + t.Fatalf("expected secondary to be master in week 2, got %s", master) + } +} |
