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)
| 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. |
| 228 | func (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 | } |
nothing calls this directly
no test coverage detected