summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/faketime/faketime_test.go
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@google.com>2021-05-25 12:57:59 -0700
committergVisor bot <gvisor-bot@google.com>2021-05-25 13:00:29 -0700
commit4f2439fb0ed4a6efda2637417c7137d27e4c4d26 (patch)
treedf81c4518f6b6d3da501a7182024c95a0ef66e08 /pkg/tcpip/faketime/faketime_test.go
parentb8052176db03f5d357ca50adf1e90cfecccbc001 (diff)
Use opaque types to represent time
Introduce tcpip.MonotonicTime; replace int64 in tcpip.Clock method returns with time.Time and MonotonicTime to improve type safety and ensure that monotonic clock readings are never compared to wall clock readings. PiperOrigin-RevId: 375775907
Diffstat (limited to 'pkg/tcpip/faketime/faketime_test.go')
-rw-r--r--pkg/tcpip/faketime/faketime_test.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/pkg/tcpip/faketime/faketime_test.go b/pkg/tcpip/faketime/faketime_test.go
index c2704df2c..fd2bb470a 100644
--- a/pkg/tcpip/faketime/faketime_test.go
+++ b/pkg/tcpip/faketime/faketime_test.go
@@ -26,7 +26,7 @@ func TestManualClockAdvance(t *testing.T) {
clock := faketime.NewManualClock()
start := clock.NowMonotonic()
clock.Advance(timeout)
- if got, want := time.Duration(clock.NowMonotonic()-start)*time.Nanosecond, timeout; got != want {
+ if got, want := clock.NowMonotonic().Sub(start), timeout; got != want {
t.Errorf("got = %d, want = %d", got, want)
}
}
@@ -87,7 +87,7 @@ func TestManualClockAfterFunc(t *testing.T) {
if got, want := counter2, test.wantCounter2; got != want {
t.Errorf("got counter2 = %d, want = %d", got, want)
}
- if got, want := time.Duration(clock.NowMonotonic()-start)*time.Nanosecond, test.advance; got != want {
+ if got, want := clock.NowMonotonic().Sub(start), test.advance; got != want {
t.Errorf("got elapsed = %d, want = %d", got, want)
}
})