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

Method TestLBCacheClientConnReuse

balancer/grpclb/grpclb_util_test.go:143–224  ·  view source on GitHub ↗

Test that NewSubConn with the same address of a SubConn being shut down will reuse the SubConn and cancel the removing.

(t *testing.T)

Source from the content-addressed store, hash-verified

141// Test that NewSubConn with the same address of a SubConn being shut down will
142// reuse the SubConn and cancel the removing.
143func (s) TestLBCacheClientConnReuse(t *testing.T) {
144 mcc := newMockClientConn()
145 if err := checkMockCC(mcc, 0); err != nil {
146 t.Fatal(err)
147 }
148
149 ccc := newLBCacheClientConn(mcc)
150 ccc.timeout = testCacheTimeout
151 if err := checkCacheCC(ccc, 0, 0); err != nil {
152 t.Fatal(err)
153 }
154
155 sc, _ := ccc.NewSubConn([]resolver.Address{{Addr: "address1"}}, balancer.NewSubConnOptions{})
156 // One subconn in MockCC.
157 if err := checkMockCC(mcc, 1); err != nil {
158 t.Fatal(err)
159 }
160 // No subconn being deleted, and one in CacheCC.
161 if err := checkCacheCC(ccc, 0, 1); err != nil {
162 t.Fatal(err)
163 }
164
165 sc.Shutdown()
166 // One subconn in MockCC before timeout.
167 if err := checkMockCC(mcc, 1); err != nil {
168 t.Fatal(err)
169 }
170 // One subconn being deleted, and one in CacheCC.
171 if err := checkCacheCC(ccc, 1, 1); err != nil {
172 t.Fatal(err)
173 }
174
175 // Recreate the old subconn, this should cancel the deleting process.
176 sc, _ = ccc.NewSubConn([]resolver.Address{{Addr: "address1"}}, balancer.NewSubConnOptions{})
177 // One subconn in MockCC.
178 if err := checkMockCC(mcc, 1); err != nil {
179 t.Fatal(err)
180 }
181 // No subconn being deleted, and one in CacheCC.
182 if err := checkCacheCC(ccc, 0, 1); err != nil {
183 t.Fatal(err)
184 }
185
186 var err error
187 // Should not become empty after 2*timeout.
188 time.Sleep(2 * testCacheTimeout)
189 err = checkMockCC(mcc, 1)
190 if err != nil {
191 t.Fatal(err)
192 }
193 err = checkCacheCC(ccc, 0, 1)
194 if err != nil {
195 t.Fatal(err)
196 }
197
198 // Call Shutdown again, will delete after timeout.
199 sc.Shutdown()
200 // One subconn in MockCC before timeout.

Callers

nothing calls this directly

Calls 7

ShutdownMethod · 0.95
newMockClientConnFunction · 0.85
checkMockCCFunction · 0.85
newLBCacheClientConnFunction · 0.85
checkCacheCCFunction · 0.85
FatalMethod · 0.65
NewSubConnMethod · 0.65

Tested by

no test coverage detected