MCPcopy Create free account
hub / github.com/CPChain/chain / TestClientSubscribeClose

Function TestClientSubscribeClose

api/rpc/client_test.go:288–324  ·  view source on GitHub ↗

In this test, the connection drops while EthSubscribe is waiting for a response.

(t *testing.T)

Source from the content-addressed store, hash-verified

286// In this test, the connection drops while EthSubscribe is
287// waiting for a response.
288func 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.

Callers

nothing calls this directly

Calls 6

newTestServerFunction · 0.85
DialInProcFunction · 0.85
EthSubscribeMethod · 0.80
StopMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected