check / check (push) Canceled after 0s
Five prefix handler tests gave HandleMessage two seconds to apply a full batch of 25,000 prefixes, which under the race detector on a loaded host takes longer. A test now waits up to stepTimeout, 15 seconds, for each step it expects. The slowest tests filled production limits, such as the peering handler's 500,000 paths. The peering handler now takes its path limit, and the prefix handler its limit on one write of the table's changes, as they take their timer interval. Those tests give small limits, and the tests of the maximum batch size lower it to one batch. This also fixes #215. The test helpers bound every wait, Stop included, so a test that hangs in one fails with its own message. Model: opus-5-5
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package routewatch
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"git.eeqj.de/sneak/routewatch/internal/database"
|
|
"git.eeqj.de/sneak/routewatch/internal/logger"
|
|
)
|
|
|
|
// peerBatchStore keeps the peers of the last UpdatePeerBatch call. The
|
|
// database has no read of the peer table, so the peer handler's test checks
|
|
// what the handler writes.
|
|
type peerBatchStore struct {
|
|
*mockStore
|
|
|
|
peers map[string]database.PeerUpdate
|
|
}
|
|
|
|
func (s *peerBatchStore) UpdatePeerBatch(
|
|
peers map[string]database.PeerUpdate,
|
|
) error {
|
|
s.peers = peers
|
|
|
|
return nil
|
|
}
|
|
|
|
// TestPeerHandlerWritesTheEarliestAndLatestTimesOfANewPeer handles two updates
|
|
// from one peer, the second 5 seconds after the first, in one batch. The peer
|
|
// handler writes the peer first seen at the time of the first update and last
|
|
// seen at the time of the second.
|
|
func TestPeerHandlerWritesTheEarliestAndLatestTimesOfANewPeer(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
store := &peerBatchStore{mockStore: newMockStore()}
|
|
|
|
// Built without NewPeerHandler's flush goroutine, so the test flushes
|
|
// itself.
|
|
h := &PeerHandler{db: store, logger: logger.New(), batchMaxSize: peerBatchMaxSize}
|
|
|
|
first := peerAnnouncement(testPeerIP, testV4Prefix)
|
|
second := peerAnnouncement(testPeerIP, testV4Prefix)
|
|
second.ParsedTimestamp = first.ParsedTimestamp.Add(secondUpdateAfter)
|
|
|
|
h.HandleMessage(first)
|
|
h.HandleMessage(second)
|
|
h.flushBatch()
|
|
|
|
seen := store.peers[testPeerIP].Seen
|
|
|
|
if !seen.First.Equal(first.ParsedTimestamp) {
|
|
t.Errorf("first_seen of peer %s = %s, want %s", testPeerIP,
|
|
seen.First, first.ParsedTimestamp)
|
|
}
|
|
|
|
if !seen.Last.Equal(second.ParsedTimestamp) {
|
|
t.Errorf("last_seen of peer %s = %s, want %s", testPeerIP,
|
|
seen.Last, second.ParsedTimestamp)
|
|
}
|
|
}
|