Skip to content

Commit

Permalink
change all context usage in metadata_test to context.WithTimeout
Browse files Browse the repository at this point in the history
  • Loading branch information
hasson82 committed Jun 20, 2024
1 parent befaa3d commit eaccdda
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions metadata/metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ func (s) TestFromIncomingContext(t *testing.T) {
)
// Verify that we lowercase if callers directly modify md
md["X-INCORRECT-UPPERCASE"] = []string{"foo"}
ctx := NewIncomingContext(context.Background(), md)
ctx, cancel := context.WithTimeout(NewIncomingContext(context.Background(), md), defaultTestTimeout)
defer cancel()

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

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

func BenchmarkFromIncomingContext(b *testing.B) {
md := Pairs("X-My-Header-1", "42")
ctx := NewIncomingContext(context.Background(), md)
ctx, cancel := context.WithTimeout(NewIncomingContext(context.Background(), md), defaultTestTimeout)
defer cancel()

b.ResetTimer()
for n := 0; n < b.N; n++ {
FromIncomingContext(ctx)
Expand All @@ -407,7 +411,8 @@ func BenchmarkFromIncomingContext(b *testing.B) {

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

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

0 comments on commit eaccdda

Please sign in to comment.