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

Function TestEnableTimestamps

timestamp/timestamp_linux_test.go:198–234  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

196 wantErr: false,
197 },
198 {
199 name: "zero timestamp",
200 data: noData,
201 want: 0,
202 wantErr: true,
203 },
204 }
205 for _, tt := range tests {
206 t.Run(tt.name, func(t *testing.T) {
207 res, err := scmDataToTime(tt.data)
208 if tt.wantErr {
209 require.Error(t, err)
210 } else {
211 require.Nil(t, err)
212 require.Equal(t, tt.want, res.UnixNano())
213 }
214 })
215 }
216}
217
218func TestEnableSWTimestampsRx(t *testing.T) {
219 // listen to incoming udp packets
220 conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 0})
221 require.NoError(t, err)
222 defer conn.Close()
223
224 connFd, err := ConnFd(conn)
225 require.NoError(t, err)
226
227 // Allow reading of kernel timestamps via socket
228 err = EnableSWTimestampsRx(connFd)
229 require.NoError(t, err)
230
231 // Check that socket option is set
232 timestampsEnabled, _ := unix.GetsockoptInt(connFd, unix.SOL_SOCKET, unix.SO_TIMESTAMPING)
233 newTimestampsEnabled, _ := unix.GetsockoptInt(connFd, unix.SOL_SOCKET, unix.SO_TIMESTAMPING_NEW)
234
235 // At least one of them should be set, which it > 0
236 require.Greater(t, timestampsEnabled+newTimestampsEnabled, 0, "None of the socket options is set")
237}

Callers

nothing calls this directly

Calls 3

ConnFdFunction · 0.85
EnableTimestampsFunction · 0.70
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…