MCPcopy
hub / github.com/grpc/grpc-go / TestGetSocketOptions

Method TestGetSocketOptions

channelz/service/service_sktopt_test.go:44–98  ·  channelz/service/service_sktopt_test.go::s.TestGetSocketOptions
(t *testing.T)

Source from the content-addressed store, hash-verified

42)
43
44func (s) TestGetSocketOptions(t *testing.T) {
45 ss := &channelz.Socket{
46 SocketOptions: &channelz.SocketOptionData{
47 Linger: &unix.Linger{Onoff: 1, Linger: 2},
48 RecvTimeout: &unix.Timeval{Sec: 10, Usec: 1},
49 SendTimeout: &unix.Timeval{},
50 TCPInfo: &unix.TCPInfo{State: 1},
51 },
52 }
53 svr := newCZServer()
54 czServer := channelz.RegisterServer("test svr")
55 defer channelz.RemoveEntry(czServer.ID)
56 id := channelz.RegisterSocket(&channelz.Socket{SocketType: channelz.SocketTypeNormal, RefName: "0", Parent: czServer, SocketOptions: ss.SocketOptions})
57 defer channelz.RemoveEntry(id.ID)
58 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
59 defer cancel()
60 resp, _ := svr.GetSocket(ctx, &channelzpb.GetSocketRequest{SocketId: id.ID})
61 {
62 got, want := resp.GetSocket().GetRef(), &channelzpb.SocketRef{SocketId: id.ID, Name: "0"}
63 if diff := cmp.Diff(got, want, protocmp.Transform()); diff != "" {
64 t.Fatal("resp.GetSocket() ref (-got +want): ", diff)
65 }
66 }
67 {
68 got := resp.GetSocket().GetData().GetOption()
69 want := []*channelzpb.SocketOption{{
70 Name: "SO_LINGER",
71 Additional: testutils.MarshalAny(
72 t,
73 &channelzpb.SocketOptionLinger{Active: true, Duration: durationpb.New(2 * time.Second)},
74 ),
75 }, {
76 Name: "SO_RCVTIMEO",
77 Additional: testutils.MarshalAny(
78 t,
79 &channelzpb.SocketOptionTimeout{Duration: durationpb.New(10*time.Second + time.Microsecond)},
80 ),
81 }, {
82 Name: "SO_SNDTIMEO",
83 Additional: testutils.MarshalAny(
84 t,
85 &channelzpb.SocketOptionTimeout{Duration: durationpb.New(0)},
86 ),
87 }, {
88 Name: "TCP_INFO",
89 Additional: testutils.MarshalAny(
90 t,
91 &channelzpb.SocketOptionTcpInfo{TcpiState: 1},
92 ),
93 }}
94 if diff := cmp.Diff(got, want, protocmp.Transform()); diff != "" {
95 t.Fatal("resp.GetSocket() options (-got +want): ", diff)
96 }
97 }
98}

Callers

nothing calls this directly

Calls 10

RegisterServerFunction · 0.92
RemoveEntryFunction · 0.92
RegisterSocketFunction · 0.92
MarshalAnyFunction · 0.92
newCZServerFunction · 0.85
GetOptionMethod · 0.80
GetSocketMethod · 0.65
FatalMethod · 0.65
GetRefMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected