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

Function TestSocketControlMessageSeqIDTimestamp

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

Source from the content-addressed store, hash-verified

425 require.NoError(t, err)
426
427 err = unix.SetNonblock(connFd, false)
428 require.NoError(t, err)
429
430 // Send a client request
431 timeout := 1 * time.Second
432 cconn, err := net.DialTimeout("udp", conn.LocalAddr().String(), timeout)
433 require.NoError(t, err)
434 defer cconn.Close()
435 _, err = cconn.Write(request)
436 require.NoError(t, err)
437
438 // read kernel timestamp from incoming packet
439 data, returnaddr, nowKernelTimestamp, err := ReadPacketWithRXTimestamp(connFd)
440 require.Equal(t, request, data, "We should have the same request arriving on the server")
441 require.Equal(t, time.Now().Unix()/10, nowKernelTimestamp.Unix()/10, "kernel timestamps should be within 10s")
442 requireEqualNetAddrSockAddr(t, cconn.LocalAddr(), returnaddr)
443 require.NoError(t, err)
444}
445
446func TestReadPacketWithRXTXTimestamp(t *testing.T) {
447 request := []byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 42}
448 // listen to incoming udp packets
449 conn, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("localhost"), Port: 0})
450 require.NoError(t, err)
451 defer conn.Close()
452
453 // get connection file descriptor
454 connFd, err := ConnFd(conn)
455 require.NoError(t, err)
456
457 // Allow reading of kernel timestamps via socket
458 err = EnableSWTimestamps(connFd)
459 require.NoError(t, err)
460
461 err = unix.SetNonblock(connFd, false)
462 require.NoError(t, err)

Callers

nothing calls this directly

Calls 2

SkipMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…