88 "github.com/stretchr/testify/suite"
99 metricsspb "go.temporal.io/server/api/metrics/v1"
1010 "go.temporal.io/server/common/log"
11+ "go.temporal.io/server/common/testing/rpctest"
1112 "go.uber.org/mock/gomock"
1213 "google.golang.org/grpc"
1314 "google.golang.org/grpc/metadata"
@@ -36,7 +37,7 @@ func (s *grpcSuite) TearDownTest() {}
3637func (s * grpcSuite ) TestMetadataMetricInjection () {
3738 logger := log .NewMockLogger (s .controller )
3839 ctx := context .Background ()
39- ssts := newMockServerTransportStream ( )
40+ ssts := rpctest . NewMockServerTransportStream ( "/temporal.test/MetadataMetricInjection" )
4041 ctx = grpc .NewContextWithServerTransportStream (ctx , ssts )
4142 anyMetricName := "any_metric_name"
4243
@@ -73,8 +74,9 @@ func (s *grpcSuite) TestMetadataMetricInjection() {
7374 )
7475
7576 s .Nil (err )
76- s .Equal (len (ssts .trailers ), 1 )
77- propagationContextBlobs := ssts .trailers [0 ].Get (metricsTrailerKey )
77+ trailers := ssts .CapturedTrailers ()
78+ s .Equal (1 , len (trailers ))
79+ propagationContextBlobs := trailers [0 ].Get (metricsTrailerKey )
7880 s .NotNil (propagationContextBlobs )
7981 s .Equal (1 , len (propagationContextBlobs ))
8082 baggage := & metricsspb.Baggage {}
@@ -93,7 +95,7 @@ func (s *grpcSuite) TestMetadataMetricInjection() {
9395func (s * grpcSuite ) TestMetadataMetricInjection_NoMetricPresent () {
9496 logger := log .NewMockLogger (s .controller )
9597 ctx := context .Background ()
96- ssts := newMockServerTransportStream ( )
98+ ssts := rpctest . NewMockServerTransportStream ( "/temporal.test/MetadataMetricInjectionNoMetric" )
9799 ctx = grpc .NewContextWithServerTransportStream (ctx , ssts )
98100
99101 smcii := NewServerMetricsContextInjectorInterceptor ()
@@ -128,8 +130,9 @@ func (s *grpcSuite) TestMetadataMetricInjection_NoMetricPresent() {
128130 )
129131
130132 s .Nil (err )
131- s .Equal (len (ssts .trailers ), 1 )
132- propagationContextBlobs := ssts .trailers [0 ].Get (metricsTrailerKey )
133+ trailers := ssts .CapturedTrailers ()
134+ s .Equal (1 , len (trailers ))
135+ propagationContextBlobs := trailers [0 ].Get (metricsTrailerKey )
133136 s .NotNil (propagationContextBlobs )
134137 s .Equal (1 , len (propagationContextBlobs ))
135138 baggage := & metricsspb.Baggage {}
@@ -162,26 +165,3 @@ func (s *grpcSuite) TestContextCounterAddNoMetricsContext() {
162165 testCounterName := "test_counter"
163166 ContextCounterAdd (context .Background (), testCounterName , 3 )
164167}
165-
166- func newMockServerTransportStream () * mockServerTransportStream {
167- return & mockServerTransportStream {trailers : []* metadata.MD {}}
168- }
169-
170- type mockServerTransportStream struct {
171- trailers []* metadata.MD
172- }
173-
174- func (s * mockServerTransportStream ) Method () string {
175- return "mockssts"
176- }
177- func (s * mockServerTransportStream ) SetHeader (md metadata.MD ) error {
178- return nil
179- }
180- func (s * mockServerTransportStream ) SendHeader (md metadata.MD ) error {
181- return nil
182- }
183- func (s * mockServerTransportStream ) SetTrailer (md metadata.MD ) error {
184- mdCopy := md .Copy ()
185- s .trailers = append (s .trailers , & mdCopy )
186- return nil
187- }
0 commit comments