Skip to content

Commit 96345b1

Browse files
committed
change all usage of context in server_test.go to context.WithTimeout
1 parent 40a54fb commit 96345b1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

server_test.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,21 @@ func (s) TestRetryChainedInterceptor(t *testing.T) {
153153
handler := func(ctx context.Context, req any) (any, error) {
154154
return nil, nil
155155
}
156-
ii(context.Background(), nil, nil, handler)
156+
157+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
158+
defer cancel()
159+
160+
ii(ctx, nil, nil, handler)
157161
if !cmp.Equal(records, []int{1, 2, 3, 2, 3}) {
158162
t.Fatalf("retry failed on chained interceptors: %v", records)
159163
}
160164
}
161165

162166
func (s) TestStreamContext(t *testing.T) {
163167
expectedStream := &transport.Stream{}
164-
ctx := NewContextWithServerTransportStream(context.Background(), expectedStream)
168+
ctx, cancel := context.WithTimeout(NewContextWithServerTransportStream(context.Background(), expectedStream), defaultTestTimeout)
169+
defer cancel()
170+
165171
s := ServerTransportStreamFromContext(ctx)
166172
stream, ok := s.(*transport.Stream)
167173
if !ok || expectedStream != stream {
@@ -186,7 +192,10 @@ func BenchmarkChainUnaryInterceptor(b *testing.B) {
186192
b.ReportAllocs()
187193
b.ResetTimer()
188194
for i := 0; i < b.N; i++ {
189-
if _, err := s.opts.unaryInt(context.Background(), nil, nil,
195+
ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout)
196+
defer cancel()
197+
198+
if _, err := s.opts.unaryInt(ctx, nil, nil,
190199
func(ctx context.Context, req any) (any, error) {
191200
return nil, nil
192201
},

0 commit comments

Comments
 (0)