The prune test gains a third prefix with more than 500 rows newer than 72 hours, and checks every newer row survives and every older one is deleted, in a helper shared by the three prefixes. The prefix page test uses an origin AS the routing table does not carry. README's limit list says the routing table drops the oldest waiting origin changes past 100,000, and the prefix page entry says the page shows at most the newest 5,000. The tests read 5,000 and 100,000 from named limits instead of bare numbers, so the routing table's waiting cap is now exported for them. Model: deepseek-v4-pro
This commit is contained in:
@@ -58,6 +58,7 @@ func TestOriginChangesPrune(t *testing.T) {
|
||||
db := newRoutesTestDatabase(t)
|
||||
oldPrefix := netip.MustParsePrefix(tablePrefixV4)
|
||||
straddling := netip.MustParsePrefix(tablePrefixShortV4)
|
||||
busy := netip.MustParsePrefix(tablePrefixBusyV4)
|
||||
other := netip.MustParsePrefix("10.20.0.0/16")
|
||||
|
||||
// Whole seconds, so the stored times round-trip exactly.
|
||||
@@ -70,6 +71,12 @@ func TestOriginChangesPrune(t *testing.T) {
|
||||
// prune keeps all 200 newer and the newest 300 of the 400 older.
|
||||
changes = append(changes, rows(straddling, now.Add(-100*time.Hour), 400)...)
|
||||
changes = append(changes, rows(straddling, now.Add(-71*time.Hour), 200)...)
|
||||
// 100 rows older than 72 hours and minOriginChangesPerPrefix+100 newer
|
||||
// rows for busy. The prune keeps all the newer rows and none of the older,
|
||||
// because the newer rows alone are more than minOriginChangesPerPrefix.
|
||||
changes = append(changes, rows(busy, now.Add(-100*time.Hour), 100)...)
|
||||
changes = append(changes, rows(busy, now.Add(-71*time.Hour),
|
||||
minOriginChangesPerPrefix+100)...)
|
||||
// One row for other, which the prune leaves alone.
|
||||
changes = append(changes, rows(other, now.Add(-100*time.Hour), 1)...)
|
||||
|
||||
@@ -83,44 +90,25 @@ func TestOriginChangesPrune(t *testing.T) {
|
||||
t.Fatalf("PruneOriginChanges: %v", err)
|
||||
}
|
||||
|
||||
oldTimes := survivorTimes(t, db, oldPrefix, 1000)
|
||||
if len(oldTimes) != 500 {
|
||||
t.Errorf("GetOriginChanges(oldPrefix) = %d rows, want 500", len(oldTimes))
|
||||
}
|
||||
|
||||
// The newest row survives, and the oldest survivor is the 100th oldest,
|
||||
// so a prune that kept the oldest 500 instead would fail.
|
||||
wantNewest := now.Add(-100 * time.Hour).Add(599 * time.Minute)
|
||||
if !oldTimes[0].Equal(wantNewest) {
|
||||
t.Errorf("the newest surviving row's time = %v, want %v",
|
||||
oldTimes[0], wantNewest)
|
||||
}
|
||||
|
||||
wantOldest := now.Add(-100 * time.Hour).Add(100 * time.Minute)
|
||||
if !oldTimes[499].Equal(wantOldest) {
|
||||
t.Errorf("the oldest surviving row's time = %v, want %v",
|
||||
oldTimes[499], wantOldest)
|
||||
}
|
||||
|
||||
straddlingTimes := survivorTimes(t, db, straddling, 1000)
|
||||
if len(straddlingTimes) != 500 {
|
||||
t.Errorf("GetOriginChanges(straddling) = %d rows, want 500",
|
||||
len(straddlingTimes))
|
||||
}
|
||||
checkSurvivors(t, db, oldPrefix, 500,
|
||||
now.Add(-100*time.Hour).Add(599*time.Minute),
|
||||
now.Add(-100*time.Hour).Add(100*time.Minute))
|
||||
|
||||
// The newest of the newer-than-72-hours rows survives, and the oldest
|
||||
// survivor is the 100th oldest of the older-than-72-hours rows.
|
||||
wantNewest = now.Add(-71 * time.Hour).Add(199 * time.Minute)
|
||||
if !straddlingTimes[0].Equal(wantNewest) {
|
||||
t.Errorf("the newest surviving row's time = %v, want %v",
|
||||
straddlingTimes[0], wantNewest)
|
||||
}
|
||||
checkSurvivors(t, db, straddling, 500,
|
||||
now.Add(-71*time.Hour).Add(199*time.Minute),
|
||||
now.Add(-100*time.Hour).Add(100*time.Minute))
|
||||
|
||||
wantOldest = now.Add(-100 * time.Hour).Add(100 * time.Minute)
|
||||
if !straddlingTimes[499].Equal(wantOldest) {
|
||||
t.Errorf("the oldest surviving row's time = %v, want %v",
|
||||
straddlingTimes[499], wantOldest)
|
||||
}
|
||||
// Every newer-than-72-hours row survives, so the oldest survivor is the
|
||||
// first of them and the newest is minOriginChangesPerPrefix+99 minutes
|
||||
// after it.
|
||||
checkSurvivors(t, db, busy, minOriginChangesPerPrefix+100,
|
||||
now.Add(-71*time.Hour).
|
||||
Add(time.Duration(minOriginChangesPerPrefix+99)*time.Minute),
|
||||
now.Add(-71*time.Hour))
|
||||
|
||||
gotOther, err := db.GetOriginChanges(t.Context(), other, 10)
|
||||
if err != nil {
|
||||
@@ -167,6 +155,33 @@ func survivorTimes(
|
||||
return times
|
||||
}
|
||||
|
||||
// checkSurvivors checks that prefix kept exactly wantCount rows, with the
|
||||
// newest survivor at wantNewest and the oldest at wantOldest.
|
||||
func checkSurvivors(
|
||||
t *testing.T, db *Database, prefix netip.Prefix,
|
||||
wantCount int, wantNewest, wantOldest time.Time,
|
||||
) {
|
||||
t.Helper()
|
||||
|
||||
times := survivorTimes(t, db, prefix, wantCount+1)
|
||||
if len(times) != wantCount {
|
||||
t.Errorf("GetOriginChanges(%s) = %d rows, want %d",
|
||||
prefix, len(times), wantCount)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if !times[0].Equal(wantNewest) {
|
||||
t.Errorf("the newest surviving row's time = %v, want %v",
|
||||
times[0], wantNewest)
|
||||
}
|
||||
|
||||
if !times[wantCount-1].Equal(wantOldest) {
|
||||
t.Errorf("the oldest surviving row's time = %v, want %v",
|
||||
times[wantCount-1], wantOldest)
|
||||
}
|
||||
}
|
||||
|
||||
// TestOriginChangesSurviveRouteDeletion checks that deleting a routes row
|
||||
// leaves the prefix's origin_changes rows.
|
||||
func TestOriginChangesSurviveRouteDeletion(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user