check / check (push) Canceled after 0s
Each handler took the latest time per key in a batch and inserted it as a new row's first_seen, so a key updated twice in one batch, seconds apart, was stored first seen at the later time, and the IP lookup could answer with a prefix first_seen after the route's last_seen. The prefix handler now keeps the earliest time of all of the batch's updates for each prefix. The AS, peer and peering handlers keep the earliest and the latest time per key in database.SeenTimes, and GetOrCreateASNBatch, UpdatePeerBatch and RecordPeering store a new row first seen at the earliest and last seen at the latest. A stored row still has only its last_seen set, to the latest. Model: opus-5-5
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
package routewatch
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.eeqj.de/sneak/routewatch/internal/logger"
|
|
)
|
|
|
|
// TestASHandlerStoresTheEarliestAndLatestTimesOfANewAS handles two updates
|
|
// whose path carries an AS the database does not hold yet, the second 5
|
|
// seconds after the first, in one batch into a real database. The AS is stored
|
|
// first seen at the time of the first update and last seen at the time of the
|
|
// second.
|
|
func TestASHandlerStoresTheEarliestAndLatestTimesOfANewAS(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
db := newTestDatabase(t)
|
|
|
|
// Built without NewASHandler's flush goroutine, so the test flushes itself.
|
|
h := &ASHandler{db: db, logger: logger.New()}
|
|
|
|
first := peerAnnouncement(testPeerIP, testV4Prefix)
|
|
second := peerAnnouncement(testPeerIP, testV4Prefix)
|
|
second.ParsedTimestamp = first.ParsedTimestamp.Add(secondUpdateAfter)
|
|
|
|
h.HandleMessage(first)
|
|
h.HandleMessage(second)
|
|
h.flushBatch()
|
|
|
|
asn, _, err := db.GetASDetails(testASNA)
|
|
if err != nil {
|
|
t.Fatalf("GetASDetails(%d): %v", testASNA, err)
|
|
}
|
|
|
|
if !asn.FirstSeen.Equal(first.ParsedTimestamp) {
|
|
t.Errorf("first_seen of AS%d = %s, want %s", testASNA,
|
|
asn.FirstSeen, first.ParsedTimestamp)
|
|
}
|
|
|
|
if !asn.LastSeen.Equal(second.ParsedTimestamp) {
|
|
t.Errorf("last_seen of AS%d = %s, want %s", testASNA,
|
|
asn.LastSeen, second.ParsedTimestamp)
|
|
}
|
|
}
|