Test that SubConn won't be immediately shut down.
(t *testing.T)
| 89 | |
| 90 | // Test that SubConn won't be immediately shut down. |
| 91 | func (s) TestLBCacheClientConnExpire(t *testing.T) { |
| 92 | mcc := newMockClientConn() |
| 93 | if err := checkMockCC(mcc, 0); err != nil { |
| 94 | t.Fatal(err) |
| 95 | } |
| 96 | |
| 97 | ccc := newLBCacheClientConn(mcc) |
| 98 | ccc.timeout = testCacheTimeout |
| 99 | if err := checkCacheCC(ccc, 0, 0); err != nil { |
| 100 | t.Fatal(err) |
| 101 | } |
| 102 | |
| 103 | sc, _ := ccc.NewSubConn([]resolver.Address{{Addr: "address1"}}, balancer.NewSubConnOptions{}) |
| 104 | // One subconn in MockCC. |
| 105 | if err := checkMockCC(mcc, 1); err != nil { |
| 106 | t.Fatal(err) |
| 107 | } |
| 108 | // No subconn being deleted, and one in CacheCC. |
| 109 | if err := checkCacheCC(ccc, 0, 1); err != nil { |
| 110 | t.Fatal(err) |
| 111 | } |
| 112 | |
| 113 | sc.Shutdown() |
| 114 | // One subconn in MockCC before timeout. |
| 115 | if err := checkMockCC(mcc, 1); err != nil { |
| 116 | t.Fatal(err) |
| 117 | } |
| 118 | // One subconn being deleted, and one in CacheCC. |
| 119 | if err := checkCacheCC(ccc, 1, 1); err != nil { |
| 120 | t.Fatal(err) |
| 121 | } |
| 122 | |
| 123 | // Should all become empty after timeout. |
| 124 | var err error |
| 125 | for i := 0; i < 2; i++ { |
| 126 | time.Sleep(testCacheTimeout) |
| 127 | err = checkMockCC(mcc, 0) |
| 128 | if err != nil { |
| 129 | continue |
| 130 | } |
| 131 | err = checkCacheCC(ccc, 0, 0) |
| 132 | if err != nil { |
| 133 | continue |
| 134 | } |
| 135 | } |
| 136 | if err != nil { |
| 137 | t.Fatal(err) |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | // Test that NewSubConn with the same address of a SubConn being shut down will |
| 142 | // reuse the SubConn and cancel the removing. |
nothing calls this directly
no test coverage detected