Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 

99 wiersze
3.0 KiB

  1. // +build go1.10,linux,!appengine
  2. /*
  3. *
  4. * Copyright 2018 gRPC authors.
  5. *
  6. * Licensed under the Apache License, Version 2.0 (the "License");
  7. * you may not use this file except in compliance with the License.
  8. * You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. *
  18. */
  19. // The test in this file should be run in an environment that has go1.10 or later,
  20. // as the function SyscallConn() (required to get socket option) was
  21. // introduced to net.TCPListener in go1.10.
  22. package test
  23. import (
  24. "testing"
  25. "time"
  26. "google.golang.org/grpc/internal/channelz"
  27. testpb "google.golang.org/grpc/test/grpc_testing"
  28. )
  29. func (s) TestCZSocketMetricsSocketOption(t *testing.T) {
  30. envs := []env{tcpClearRREnv, tcpTLSRREnv}
  31. for _, e := range envs {
  32. testCZSocketMetricsSocketOption(t, e)
  33. }
  34. }
  35. func testCZSocketMetricsSocketOption(t *testing.T, e env) {
  36. channelz.NewChannelzStorage()
  37. te := newTest(t, e)
  38. te.startServer(&testServer{security: e.security})
  39. defer te.tearDown()
  40. cc := te.clientConn()
  41. tc := testpb.NewTestServiceClient(cc)
  42. doSuccessfulUnaryCall(tc, t)
  43. time.Sleep(10 * time.Millisecond)
  44. ss, _ := channelz.GetServers(0, 0)
  45. if len(ss) != 1 {
  46. t.Fatalf("There should be one server, not %d", len(ss))
  47. }
  48. if len(ss[0].ListenSockets) != 1 {
  49. t.Fatalf("There should be one listen socket, not %d", len(ss[0].ListenSockets))
  50. }
  51. for id := range ss[0].ListenSockets {
  52. sm := channelz.GetSocket(id)
  53. if sm == nil || sm.SocketData == nil || sm.SocketData.SocketOptions == nil {
  54. t.Fatalf("Unable to get server listen socket options")
  55. }
  56. }
  57. ns, _ := channelz.GetServerSockets(ss[0].ID, 0, 0)
  58. if len(ns) != 1 {
  59. t.Fatalf("There should be one server normal socket, not %d", len(ns))
  60. }
  61. if ns[0] == nil || ns[0].SocketData == nil || ns[0].SocketData.SocketOptions == nil {
  62. t.Fatalf("Unable to get server normal socket options")
  63. }
  64. tchan, _ := channelz.GetTopChannels(0, 0)
  65. if len(tchan) != 1 {
  66. t.Fatalf("There should only be one top channel, not %d", len(tchan))
  67. }
  68. if len(tchan[0].SubChans) != 1 {
  69. t.Fatalf("There should only be one subchannel under top channel %d, not %d", tchan[0].ID, len(tchan[0].SubChans))
  70. }
  71. var id int64
  72. for id = range tchan[0].SubChans {
  73. break
  74. }
  75. sc := channelz.GetSubChannel(id)
  76. if sc == nil {
  77. t.Fatalf("There should only be one socket under subchannel %d, not 0", id)
  78. }
  79. if len(sc.Sockets) != 1 {
  80. t.Fatalf("There should only be one socket under subchannel %d, not %d", sc.ID, len(sc.Sockets))
  81. }
  82. for id = range sc.Sockets {
  83. break
  84. }
  85. skt := channelz.GetSocket(id)
  86. if skt == nil || skt.SocketData == nil || skt.SocketData.SocketOptions == nil {
  87. t.Fatalf("Unable to get client normal socket options")
  88. }
  89. }