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

Function startServer

balancer/weightedroundrobin/balancer_test.go:111–158  ·  view source on GitHub ↗
(t *testing.T, r reportType)

Source from the content-addressed store, hash-verified

109)
110
111func startServer(t *testing.T, r reportType) *testServer {
112 t.Helper()
113
114 smr := orca.NewServerMetricsRecorder()
115 cmr := orca.NewServerMetricsRecorder().(orca.CallMetricsRecorder)
116
117 ss := &stubserver.StubServer{
118 EmptyCallF: func(ctx context.Context, _ *testpb.Empty) (*testpb.Empty, error) {
119 if r := orca.CallMetricsRecorderFromContext(ctx); r != nil {
120 // Copy metrics from what the test set in cmr into r.
121 sm := cmr.(orca.ServerMetricsProvider).ServerMetrics()
122 r.SetApplicationUtilization(sm.AppUtilization)
123 r.SetQPS(sm.QPS)
124 r.SetEPS(sm.EPS)
125 }
126 return &testpb.Empty{}, nil
127 },
128 }
129
130 var sopts []grpc.ServerOption
131 if r == reportCall || r == reportBoth {
132 sopts = append(sopts, orca.CallMetricsServerOption(nil))
133 }
134
135 if r == reportOOB || r == reportBoth {
136 oso := orca.ServiceOptions{
137 ServerMetricsProvider: smr,
138 MinReportingInterval: 10 * time.Millisecond,
139 }
140 internal.ORCAAllowAnyMinReportingInterval.(func(so *orca.ServiceOptions))(&oso)
141 sopts = append(sopts, stubserver.RegisterServiceServerOption(func(s grpc.ServiceRegistrar) {
142 if err := orca.Register(s, oso); err != nil {
143 t.Fatalf("Failed to register orca service: %v", err)
144 }
145 }))
146 }
147
148 if err := ss.StartServer(sopts...); err != nil {
149 t.Fatalf("Error starting server: %v", err)
150 }
151 t.Cleanup(ss.Stop)
152
153 return &testServer{
154 StubServer: ss,
155 oobMetrics: smr,
156 callMetrics: cmr,
157 }
158}
159
160func svcConfig(t *testing.T, wrrCfg iwrr.LBConfig) string {
161 t.Helper()

Calls 11

StartServerMethod · 0.95
NewServerMetricsRecorderFunction · 0.92
CallMetricsServerOptionFunction · 0.92
RegisterFunction · 0.92
ServerMetricsMethod · 0.65
SetQPSMethod · 0.65
SetEPSMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected