MCPcopy
hub / github.com/grpc/grpc-go / main

Function main

interop/xds_federation/client.go:74–152  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

72}
73
74func main() {
75 flag.Parse()
76 // validate flags
77 uris := strings.Split(*serverURIs, ",")
78 creds := strings.Split(*credentialsTypes, ",")
79 if len(uris) != len(creds) {
80 logger.Fatalf("Number of entries in --server_uris (%d) != number of entries in --credentials_types (%d)", len(uris), len(creds))
81 }
82 for _, c := range creds {
83 if c != computeEngineCredsName && c != insecureCredsName {
84 logger.Fatalf("Unsupported credentials type: %v", c)
85 }
86 }
87 var clients []clientConfig
88 for i := range uris {
89 var opts []grpc.DialOption
90 switch creds[i] {
91 case computeEngineCredsName:
92 opts = append(opts, grpc.WithCredentialsBundle(google.NewComputeEngineCredentials()))
93 case insecureCredsName:
94 opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()))
95 }
96 cc, err := grpc.NewClient(uris[i], opts...)
97 if err != nil {
98 logger.Fatalf("grpc.NewClient(%q) = %v", uris[i], err)
99 }
100 defer cc.Close()
101 clients = append(clients, clientConfig{
102 conn: cc,
103 tc: testgrpc.NewTestServiceClient(cc),
104 opts: opts,
105 uri: uris[i],
106 })
107 }
108
109 // run soak tests with the different clients
110 logger.Infof("Clients running with test case %q", *testCase)
111 var wg sync.WaitGroup
112 var channelForTest func() (*grpc.ClientConn, func())
113 ctx := context.Background()
114 for i := range clients {
115 wg.Add(1)
116 go func(c clientConfig) {
117 ctxWithDeadline, cancel := context.WithTimeout(ctx, time.Duration(*soakOverallTimeoutSeconds)*time.Second)
118 defer cancel()
119 switch *testCase {
120 case "rpc_soak":
121 channelForTest = func() (*grpc.ClientConn, func()) { return c.conn, func() {} }
122 case "channel_soak":
123 channelForTest = func() (*grpc.ClientConn, func()) {
124 cc, err := grpc.NewClient(c.uri, c.opts...)
125 if err != nil {
126 log.Fatalf("Failed to create shared channel: %v", err)
127 }
128 return cc, func() { cc.Close() }
129 }
130 default:
131 logger.Fatal("Unsupported test case: ", *testCase)

Callers

nothing calls this directly

Calls 15

WithCredentialsBundleFunction · 0.92
WithTransportCredentialsFunction · 0.92
NewCredentialsFunction · 0.92
NewClientFunction · 0.92
DoSoakTestFunction · 0.92
WaitMethod · 0.80
ParseMethod · 0.65
FatalfMethod · 0.65
CloseMethod · 0.65
InfofMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected