In this test, the connection drops while EthSubscribe is waiting for a response.
(t *testing.T)
| 286 | // In this test, the connection drops while EthSubscribe is |
| 287 | // waiting for a response. |
| 288 | func TestClientSubscribeClose(t *testing.T) { |
| 289 | service := &NotificationTestService{ |
| 290 | gotHangSubscriptionReq: make(chan struct{}), |
| 291 | unblockHangSubscription: make(chan struct{}), |
| 292 | } |
| 293 | server := newTestServer("eth", service) |
| 294 | defer server.Stop() |
| 295 | client := DialInProc(server) |
| 296 | defer client.Close() |
| 297 | |
| 298 | var ( |
| 299 | nc = make(chan int) |
| 300 | errc = make(chan error) |
| 301 | sub *ClientSubscription |
| 302 | err error |
| 303 | ) |
| 304 | go func() { |
| 305 | sub, err = client.EthSubscribe(context.Background(), nc, "hangSubscription", 999) |
| 306 | errc <- err |
| 307 | }() |
| 308 | |
| 309 | <-service.gotHangSubscriptionReq |
| 310 | client.Close() |
| 311 | service.unblockHangSubscription <- struct{}{} |
| 312 | |
| 313 | select { |
| 314 | case err := <-errc: |
| 315 | if err == nil { |
| 316 | t.Errorf("EthSubscribe returned nil error after Close") |
| 317 | } |
| 318 | if sub != nil { |
| 319 | t.Error("EthSubscribe returned non-nil subscription after Close") |
| 320 | } |
| 321 | case <-time.After(1 * time.Second): |
| 322 | t.Fatalf("EthSubscribe did not return within 1s after Close") |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | // This test checks that Client doesn't lock up when a single subscriber |
| 327 | // doesn't read subscription events. |
nothing calls this directly
no test coverage detected