Hold the 100,000-row cap after a failed write's rows are put back, dropping and counting the oldest rows past it. Stop counts the unwritten origin changes. The prefix handler's per-write origin change limit is a field, so a test checks that one write leaves the rest. The server and README now say where origin changes come from. README, TODO and schema say 72 hours or 500 rows, whichever keeps more. The prefix page and TODO list the origin change columns and say what the peer count counts. The page takes its 5,000-row note from the constant. Model: deepseek-v4-pro
This commit is contained in:
@@ -3,6 +3,7 @@ package routewatch
|
||||
import (
|
||||
"errors"
|
||||
"net/netip"
|
||||
"slices"
|
||||
"testing"
|
||||
|
||||
"git.eeqj.de/sneak/routewatch/internal/database"
|
||||
@@ -82,3 +83,45 @@ func TestPrefixHandlerWritesAFailedOriginChangeWriteAgain(t *testing.T) {
|
||||
got, testASNB)
|
||||
}
|
||||
}
|
||||
|
||||
// originChangesWriteSizesStore is a real database that records how many
|
||||
// changes each write of the origin changes holds.
|
||||
type originChangesWriteSizesStore struct {
|
||||
*database.Database
|
||||
|
||||
counts []int
|
||||
}
|
||||
|
||||
func (s *originChangesWriteSizesStore) WriteOriginChanges(
|
||||
changes []routetable.OriginChange,
|
||||
) error {
|
||||
s.counts = append(s.counts, len(changes))
|
||||
|
||||
return s.Database.WriteOriginChanges(changes)
|
||||
}
|
||||
|
||||
// TestPrefixHandlerWritesManyOriginChangesOverSeveralFlushes has more origin
|
||||
// changes than one write takes, then flushes three times. The first write must
|
||||
// hold one write's worth, the second the rest, and the third nothing. The
|
||||
// handler's limit is small.
|
||||
func TestPrefixHandlerWritesManyOriginChangesOverSeveralFlushes(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const perWrite = 10
|
||||
|
||||
db := newTestDatabase(t)
|
||||
store := &originChangesWriteSizesStore{Database: db}
|
||||
h := prefixHandlerWithoutTimer(store)
|
||||
h.originChangesPerWrite = perWrite
|
||||
|
||||
announceManyPrefixes(h.table, perWrite*3/2)
|
||||
|
||||
h.flushBatch()
|
||||
h.flushBatch()
|
||||
h.flushBatch()
|
||||
|
||||
want := []int{perWrite, perWrite*3/2 - perWrite}
|
||||
if !slices.Equal(store.counts, want) {
|
||||
t.Errorf("WriteOriginChanges held %v changes, want %v", store.counts, want)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user