MCPcopy Create free account
hub / github.com/facebook/time / TestReadPacketWithRXTimestamp

Function TestReadPacketWithRXTimestamp

timestamp/timestamp_notlinux_test.go:87–119  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestReadPacketWithRXTimestamp(t *testing.T) {
88 request := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 42}
89 // listen to incoming udp packets
90 conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 0})
91 require.NoError(t, err)
92 defer conn.Close()
93
94 // get connection file descriptor
95 connFd, err := ConnFd(conn)
96 require.NoError(t, err)
97
98 // Allow reading of kernel timestamps via socket
99 err = EnableSWTimestampsRx(connFd)
100 require.NoError(t, err)
101
102 err = unix.SetNonblock(connFd, false)
103 require.NoError(t, err)
104
105 // Send a client request
106 timeout := 1 * time.Second
107 cconn, err := net.DialTimeout("udp", conn.LocalAddr().String(), timeout)
108 require.NoError(t, err)
109 defer cconn.Close()
110 _, err = cconn.Write(request)
111 require.NoError(t, err)
112
113 // read kernel timestamp from incoming packet
114 data, returnaddr, nowKernelTimestamp, err := ReadPacketWithRXTimestamp(connFd)
115 require.NoError(t, err)
116 require.Equal(t, request, data, "We should have the same request arriving on the server")
117 require.Equal(t, time.Now().Unix()/10, nowKernelTimestamp.Unix()/10, "kernel timestamps should be within 10s")
118 requireEqualNetAddrSockAddr(t, cconn.LocalAddr(), returnaddr)
119}

Callers

nothing calls this directly

Calls 8

ConnFdFunction · 0.85
UnixMethod · 0.80
EnableSWTimestampsRxFunction · 0.70
CloseMethod · 0.65
StringMethod · 0.45
WriteMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…