Assert UpdatedAtNanos in neighbor cache tests

Changes the neighbor_cache_test.go tests to always assert UpdatedAtNanos.

Completes the assertion of UpdatedAtNanos in every NUD test, a field that was
historically not checked due to the lack of a deterministic, controllable
clock. This is no longer true with the tcpip.Clock interface. While the tests
have been adjusted to use Clock, asserting by the UpdatedAtNanos was neglected.

Fixes #4663

PiperOrigin-RevId: 360730077
This commit is contained in:
Sam Balana
2021-03-03 12:26:30 -08:00
committed by gVisor bot
parent 3e69f5d088
commit 011ba4d4fe
2 changed files with 484 additions and 611 deletions
File diff suppressed because it is too large Load Diff
-19
View File
@@ -18,13 +18,11 @@ import (
"fmt"
"math"
"math/rand"
"strings"
"sync"
"testing"
"time"
"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"gvisor.dev/gvisor/pkg/tcpip"
"gvisor.dev/gvisor/pkg/tcpip/faketime"
"gvisor.dev/gvisor/pkg/tcpip/header"
@@ -52,23 +50,6 @@ func runImmediatelyScheduledJobs(clock *faketime.ManualClock) {
clock.Advance(immediateDuration)
}
// eventDiffOpts are the options passed to cmp.Diff to compare entry events.
// The UpdatedAtNanos field is ignored due to a lack of a deterministic method
// to predict the time that an event will be dispatched.
func eventDiffOpts() []cmp.Option {
return []cmp.Option{
cmpopts.IgnoreFields(NeighborEntry{}, "UpdatedAtNanos"),
}
}
// eventDiffOptsWithSort is like eventDiffOpts but also includes an option to
// sort slices of events for cases where ordering must be ignored.
func eventDiffOptsWithSort() []cmp.Option {
return append(eventDiffOpts(), cmpopts.SortSlices(func(a, b testEntryEventInfo) bool {
return strings.Compare(string(a.Entry.Addr), string(b.Entry.Addr)) < 0
}))
}
// The following unit tests exercise every state transition and verify its
// behavior with RFC 4681 and RFC 7048.
//