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

Function TestAffinity

internal/xds/test/e2e/e2e_test.go:128–258  ·  view source on GitHub ↗

TestAffinity covers the affinity tests with ringhash policy. - client is configured to use ringhash, with 3 backends - all RPCs will hash a specific metadata header - verify that - all RPCs with the same metadata value are sent to the same backend - only one backend is Ready - send more RPCs with d

(t *testing.T)

Source from the content-addressed store, hash-verified

126// - send more RPCs with different metadata values until a new backend is picked, and verify that
127// - only two backends are in Ready
128func TestAffinity(t *testing.T) {
129 const (
130 testName = "affinity"
131 backendCount = 3
132 testMDKey = "xds_md"
133 testMDValue = "unary_yranu"
134 )
135 cp, c, servers := setup(t, testOpts{
136 testName: testName,
137 backendCount: backendCount,
138 clientFlags: []string{"--rpc=EmptyCall", fmt.Sprintf("--metadata=EmptyCall:%s:%s", testMDKey, testMDValue)},
139 })
140
141 resources := e2e.DefaultClientResources(e2e.ResourceParams{
142 DialTarget: testName,
143 NodeID: cp.nodeID,
144 Host: "localhost",
145 Port: serverPort,
146 SecLevel: e2e.SecurityLevelNone,
147 })
148
149 // Update EDS to multiple backends.
150 var ports []uint32
151 for _, s := range servers {
152 ports = append(ports, uint32(s.port))
153 }
154 edsMsg := resources.Endpoints[0]
155 resources.Endpoints[0] = e2e.DefaultEndpoint(
156 edsMsg.ClusterName,
157 "localhost",
158 ports,
159 )
160
161 // Update CDS lbpolicy to ringhash.
162 cdsMsg := resources.Clusters[0]
163 cdsMsg.LbPolicy = v3clusterpb.Cluster_RING_HASH
164
165 // Update RDS to hash the header.
166 rdsMsg := resources.Routes[0]
167 rdsMsg.VirtualHosts[0].Routes[0].Action = &v3routepb.Route_Route{Route: &v3routepb.RouteAction{
168 ClusterSpecifier: &v3routepb.RouteAction_Cluster{Cluster: cdsMsg.Name},
169 HashPolicy: []*v3routepb.RouteAction_HashPolicy{{
170 PolicySpecifier: &v3routepb.RouteAction_HashPolicy_Header_{
171 Header: &v3routepb.RouteAction_HashPolicy_Header{
172 HeaderName: testMDKey,
173 },
174 },
175 }},
176 }}
177
178 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
179 defer cancel()
180 if err := cp.server.Update(ctx, resources); err != nil {
181 t.Fatalf("failed to update control plane resources: %v", err)
182 }
183
184 // Note: We can skip CSDS check because there's no long delay as in TD.
185 //

Callers

nothing calls this directly

Calls 9

DefaultClientResourcesFunction · 0.92
DefaultEndpointFunction · 0.92
verifySubConnStatesFunction · 0.85
clientStatsMethod · 0.80
channelzSubChannelsMethod · 0.80
configRPCsMethod · 0.80
setupFunction · 0.70
UpdateMethod · 0.65
FatalfMethod · 0.65

Tested by

no test coverage detected