(t *testing.T, wantStates []connectivity.State, server func(net.Listener) net.Conn)
| 174 | } |
| 175 | |
| 176 | func testStateTransitionSingleAddress(t *testing.T, wantStates []connectivity.State, server func(net.Listener) net.Conn) { |
| 177 | pl := testutils.NewPipeListener() |
| 178 | defer pl.Close() |
| 179 | |
| 180 | // Launch the server. |
| 181 | var conn net.Conn |
| 182 | var connMu sync.Mutex |
| 183 | go func() { |
| 184 | connMu.Lock() |
| 185 | conn = server(pl) |
| 186 | connMu.Unlock() |
| 187 | }() |
| 188 | |
| 189 | dopts := []grpc.DialOption{ |
| 190 | grpc.WithTransportCredentials(insecure.NewCredentials()), |
| 191 | grpc.WithDialer(pl.Dialer()), |
| 192 | grpc.WithConnectParams(grpc.ConnectParams{ |
| 193 | Backoff: backoff.Config{}, |
| 194 | MinConnectTimeout: 100 * time.Millisecond, |
| 195 | }), |
| 196 | } |
| 197 | cc, err := grpc.NewClient("passthrough:///", dopts...) |
| 198 | if err != nil { |
| 199 | t.Fatal(err) |
| 200 | } |
| 201 | defer cc.Close() |
| 202 | |
| 203 | // Ensure that the client is in IDLE before connecting. |
| 204 | ctx, cancel := context.WithTimeout(context.Background(), defaultTestTimeout) |
| 205 | defer cancel() |
| 206 | testutils.AwaitState(ctx, t, cc, connectivity.Idle) |
| 207 | |
| 208 | // Subscribe to state updates. |
| 209 | stateCh := make(chan connectivity.State, 1) |
| 210 | s := &funcConnectivityStateSubscriber{ |
| 211 | onMsg: func(s connectivity.State) { |
| 212 | select { |
| 213 | case stateCh <- s: |
| 214 | case <-ctx.Done(): |
| 215 | } |
| 216 | }, |
| 217 | } |
| 218 | internal.SubscribeToConnectivityStateChanges.(func(cc *grpc.ClientConn, s grpcsync.Subscriber) func())(cc, s) |
| 219 | |
| 220 | cc.Connect() |
| 221 | for _, wantState := range wantStates { |
| 222 | waitForState(ctx, t, stateCh, wantState) |
| 223 | } |
| 224 | |
| 225 | connMu.Lock() |
| 226 | defer connMu.Unlock() |
| 227 | if conn != nil { |
| 228 | err = conn.Close() |
| 229 | if err != nil { |
| 230 | t.Fatal(err) |
| 231 | } |
| 232 | } |
| 233 | } |
no test coverage detected