Skip to content

Commit eaccdda

Browse files
committed
change all context usage in metadata_test to context.WithTimeout
1 parent befaa3d commit eaccdda

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

metadata/metadata_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ func (s) TestFromIncomingContext(t *testing.T) {
205205
)
206206
// Verify that we lowercase if callers directly modify md
207207
md["X-INCORRECT-UPPERCASE"] = []string{"foo"}
208-
ctx := NewIncomingContext(context.Background(), md)
208+
ctx, cancel := context.WithTimeout(NewIncomingContext(context.Background(), md), defaultTestTimeout)
209+
defer cancel()
209210

210211
result, found := FromIncomingContext(ctx)
211212
if !found {
@@ -241,7 +242,8 @@ func (s) TestValueFromIncomingContext(t *testing.T) {
241242
)
242243
// Verify that we lowercase if callers directly modify md
243244
md["X-INCORRECT-UPPERCASE"] = []string{"foo"}
244-
ctx := NewIncomingContext(context.Background(), md)
245+
ctx, cancel := context.WithTimeout(NewIncomingContext(context.Background(), md), defaultTestTimeout)
246+
defer cancel()
245247

246248
for _, test := range []struct {
247249
key string
@@ -398,7 +400,9 @@ func BenchmarkFromOutgoingContext(b *testing.B) {
398400

399401
func BenchmarkFromIncomingContext(b *testing.B) {
400402
md := Pairs("X-My-Header-1", "42")
401-
ctx := NewIncomingContext(context.Background(), md)
403+
ctx, cancel := context.WithTimeout(NewIncomingContext(context.Background(), md), defaultTestTimeout)
404+
defer cancel()
405+
402406
b.ResetTimer()
403407
for n := 0; n < b.N; n++ {
404408
FromIncomingContext(ctx)
@@ -407,7 +411,8 @@ func BenchmarkFromIncomingContext(b *testing.B) {
407411

408412
func BenchmarkValueFromIncomingContext(b *testing.B) {
409413
md := Pairs("X-My-Header-1", "42")
410-
ctx := NewIncomingContext(context.Background(), md)
414+
ctx, cancel := context.WithTimeout(NewIncomingContext(context.Background(), md), defaultTestTimeout)
415+
defer cancel()
411416

412417
b.Run("key-found", func(b *testing.B) {
413418
for n := 0; n < b.N; n++ {

0 commit comments

Comments
 (0)