@@ -31,8 +31,6 @@ import (
31
31
32
32
const defaultTestTimeout = 10 * time .Second
33
33
34
- var ctx , cancel = context .WithTimeout (context .Background (), defaultTestTimeout )
35
-
36
34
type s struct {
37
35
grpctest.Tester
38
36
}
@@ -205,10 +203,11 @@ func (s) TestFromIncomingContext(t *testing.T) {
205
203
md := Pairs (
206
204
"X-My-Header-1" , "42" ,
207
205
)
206
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
207
+ defer cancel ()
208
208
// Verify that we lowercase if callers directly modify md
209
209
md ["X-INCORRECT-UPPERCASE" ] = []string {"foo" }
210
- ctx := NewIncomingContext (ctx , md )
211
- defer cancel ()
210
+ ctx = NewIncomingContext (ctx , md )
212
211
213
212
result , found := FromIncomingContext (ctx )
214
213
if ! found {
@@ -242,10 +241,11 @@ func (s) TestValueFromIncomingContext(t *testing.T) {
242
241
"X-My-Header-2" , "43-2" ,
243
242
"x-my-header-3" , "44" ,
244
243
)
244
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
245
+ defer cancel ()
245
246
// Verify that we lowercase if callers directly modify md
246
247
md ["X-INCORRECT-UPPERCASE" ] = []string {"foo" }
247
- ctx := NewIncomingContext (ctx , md )
248
- defer cancel ()
248
+ ctx = NewIncomingContext (ctx , md )
249
249
250
250
for _ , test := range []struct {
251
251
key string
@@ -401,9 +401,10 @@ func BenchmarkFromOutgoingContext(b *testing.B) {
401
401
}
402
402
403
403
func BenchmarkFromIncomingContext (b * testing.B ) {
404
- md := Pairs ("X-My-Header-1" , "42" )
405
- ctx := NewIncomingContext (ctx , md )
404
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
406
405
defer cancel ()
406
+ md := Pairs ("X-My-Header-1" , "42" )
407
+ ctx = NewIncomingContext (ctx , md )
407
408
408
409
b .ResetTimer ()
409
410
for n := 0 ; n < b .N ; n ++ {
@@ -412,9 +413,10 @@ func BenchmarkFromIncomingContext(b *testing.B) {
412
413
}
413
414
414
415
func BenchmarkValueFromIncomingContext (b * testing.B ) {
415
- md := Pairs ("X-My-Header-1" , "42" )
416
- ctx := NewIncomingContext (ctx , md )
416
+ ctx , cancel := context .WithTimeout (context .Background (), defaultTestTimeout )
417
417
defer cancel ()
418
+ md := Pairs ("X-My-Header-1" , "42" )
419
+ ctx = NewIncomingContext (ctx , md )
418
420
419
421
b .Run ("key-found" , func (b * testing.B ) {
420
422
for n := 0 ; n < b .N ; n ++ {
0 commit comments