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

Method TestLBCache_ShutdownTimer_New_Race

balancer/grpclb/grpclb_util_test.go:228–267  ·  view source on GitHub ↗

Test that if the timer to shut down a SubConn fires at the same time NewSubConn cancels the timer, it doesn't cause deadlock.

(t *testing.T)

Source from the content-addressed store, hash-verified

226// Test that if the timer to shut down a SubConn fires at the same time
227// NewSubConn cancels the timer, it doesn't cause deadlock.
228func (s) TestLBCache_ShutdownTimer_New_Race(t *testing.T) {
229 mcc := newMockClientConn()
230 if err := checkMockCC(mcc, 0); err != nil {
231 t.Fatal(err)
232 }
233
234 ccc := newLBCacheClientConn(mcc)
235 ccc.timeout = time.Nanosecond
236 if err := checkCacheCC(ccc, 0, 0); err != nil {
237 t.Fatal(err)
238 }
239
240 sc, _ := ccc.NewSubConn([]resolver.Address{{Addr: "address1"}}, balancer.NewSubConnOptions{})
241 // One subconn in MockCC.
242 if err := checkMockCC(mcc, 1); err != nil {
243 t.Fatal(err)
244 }
245 // No subconn being deleted, and one in CacheCC.
246 if err := checkCacheCC(ccc, 0, 1); err != nil {
247 t.Fatal(err)
248 }
249
250 done := make(chan struct{})
251
252 go func() {
253 for i := 0; i < 1000; i++ {
254 // Shutdown starts a timer with 1 ns timeout, the NewSubConn will
255 // race with the timer.
256 sc.Shutdown()
257 sc, _ = ccc.NewSubConn([]resolver.Address{{Addr: "address1"}}, balancer.NewSubConnOptions{})
258 }
259 close(done)
260 }()
261
262 select {
263 case <-time.After(time.Second):
264 t.Fatalf("Test didn't finish within 1 second. Deadlock")
265 case <-done:
266 }
267}

Callers

nothing calls this directly

Calls 8

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

Tested by

no test coverage detected