@@ -20,21 +20,35 @@ package service
20
20
21
21
import (
22
22
"testing"
23
+
24
+ "google.golang.org/grpc"
25
+ "google.golang.org/grpc/internal/grpctest"
23
26
)
24
27
28
+ type s struct {
29
+ grpctest.Tester
30
+ }
31
+
32
+ func Test (t * testing.T ) {
33
+ grpctest .RunSubTests (t , s {})
34
+ }
35
+
25
36
const (
26
37
testAddress1 = "some_address_1"
27
38
testAddress2 = "some_address_2"
28
39
)
29
40
30
- // TestDial verifies the behavior of the Dial function in managing gRPC connections
31
- // and checks the below scenarios:
32
- // - First call to Dial with an address creates a new connection and stores it.
33
- // - Second call to Dial with the same address returns the existing connection
34
- // and expects the returned connection matching with ƒirst connection.
35
- // - Third call to Dial with a different address creates a separate new connection
36
- // and expects a different connection from connnection1 and connection2.
37
- func TestDial (t * testing.T ) {
41
+ // TestDial verifies the behaviour of alts handshake when there are multiple Dials.
42
+ // If a connection has already been established, this function returns it.
43
+ // Otherwise, a new connection is created.
44
+ func (s ) TestDial (t * testing.T ) {
45
+ temp := hsDialer
46
+ hsDialer = func (target string , opts ... grpc.DialOption ) (* grpc.ClientConn , error ) {
47
+ return & grpc.ClientConn {}, nil
48
+ }
49
+ defer func () {
50
+ hsDialer = temp
51
+ }()
38
52
// First call to Dial, it should create a connection to the server running
39
53
// at the given address.
40
54
conn1 , err := Dial (testAddress1 )
@@ -60,8 +74,7 @@ func TestDial(t *testing.T) {
60
74
t .Fatalf ("hsConnMap[%v]=%v, want %v" , testAddress1 , got , want )
61
75
}
62
76
63
- // Third call to Dial using a different address should create a new
64
- // connection.
77
+ // Third call to Dial using a different address should create a new connection.
65
78
conn3 , err := Dial (testAddress2 )
66
79
if err != nil {
67
80
t .Fatalf ("third call to Dial(%v) failed: %v" , testAddress2 , err )
0 commit comments