Skip to content

Commit aa71ff0

Browse files
committed
add context.WithTimeout to peer_test
1 parent a4e7742 commit aa71ff0

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

peer/peer_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@ import (
2222
"context"
2323
"fmt"
2424
"testing"
25+
"time"
2526

2627
"google.golang.org/grpc/credentials"
2728
)
2829

30+
const defaultTestTimeout = 10 * time.Second
31+
2932
// A struct that implements AuthInfo interface and implements CommonAuthInfo() method.
3033
type testAuthInfo struct {
3134
credentials.CommonAuthInfo
@@ -82,7 +85,9 @@ func TestPeerStringer(t *testing.T) {
8285
}
8386
for _, tc := range testCases {
8487
t.Run(tc.name, func(t *testing.T) {
85-
ctx := NewContext(context.Background(), tc.peer)
88+
ctx, cancel := context.WithTimeout(NewContext(context.Background(), tc.peer), defaultTestTimeout)
89+
defer cancel()
90+
8691
p, ok := FromContext(ctx)
8792
if !ok {
8893
t.Fatalf("Unable to get peer from context")

0 commit comments

Comments
 (0)