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

Method TestMaxStreams

internal/transport/transport_test.go:1111–1186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

1109}
1110
1111func (s) TestMaxStreams(t *testing.T) {
1112 serverConfig := &ServerConfig{
1113 BufferPool: mem.DefaultBufferPool(),
1114 MaxStreams: 1,
1115 }
1116 copts := ConnectOptions{
1117 BufferPool: mem.DefaultBufferPool(),
1118 }
1119 server, ct, cancel := setUpWithOptions(t, 0, serverConfig, suspended, copts)
1120 defer cancel()
1121 defer ct.Close(fmt.Errorf("closed manually by test"))
1122 defer server.stop()
1123 callHdr := &CallHdr{
1124 Host: "localhost",
1125 Method: "foo.Large",
1126 }
1127 ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
1128 defer cancel()
1129 s, err := ct.NewStream(ctx, callHdr, nil)
1130 if err != nil {
1131 t.Fatalf("Failed to open stream: %v", err)
1132 }
1133 // Keep creating streams until one fails with deadline exceeded, marking the application
1134 // of server settings on client.
1135 slist := []*ClientStream{}
1136 pctx, cancel := context.WithCancel(context.Background())
1137 defer cancel()
1138 timer := time.NewTimer(time.Second * 10)
1139 expectedErr := status.Error(codes.DeadlineExceeded, context.DeadlineExceeded.Error())
1140 for {
1141 select {
1142 case <-timer.C:
1143 t.Fatalf("Test timeout: client didn't receive server settings.")
1144 default:
1145 }
1146 ctx, cancel := context.WithDeadline(pctx, time.Now().Add(time.Second))
1147 // This is only to get rid of govet. All these context are based on a base
1148 // context which is canceled at the end of the test.
1149 defer cancel()
1150 if str, err := ct.NewStream(ctx, callHdr, nil); err == nil {
1151 slist = append(slist, str)
1152 continue
1153 } else if err.Error() != expectedErr.Error() {
1154 t.Fatalf("ct.NewStream(_,_) = _, %v, want _, %v", err, expectedErr)
1155 }
1156 timer.Stop()
1157 break
1158 }
1159 done := make(chan struct{})
1160 // Try and create a new stream.
1161 go func() {
1162 defer close(done)
1163 ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
1164 defer cancel()
1165 if _, err := ct.NewStream(ctx, callHdr, nil); err != nil {
1166 t.Errorf("Failed to open stream: %v", err)
1167 }
1168 }()

Callers

nothing calls this directly

Calls 13

StopMethod · 0.95
DefaultBufferPoolFunction · 0.92
ErrorFunction · 0.92
setUpWithOptionsFunction · 0.85
NewTimerMethod · 0.80
NowMethod · 0.80
CloseMethod · 0.65
ErrorfMethod · 0.65
stopMethod · 0.65
NewStreamMethod · 0.65
FatalfMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected