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

Function TestClientNotificationStorm

api/rpc/client_test.go:328–375  ·  view source on GitHub ↗

This test checks that Client doesn't lock up when a single subscriber doesn't read subscription events.

(t *testing.T)

Source from the content-addressed store, hash-verified

326// This test checks that Client doesn't lock up when a single subscriber
327// doesn't read subscription events.
328func TestClientNotificationStorm(t *testing.T) {
329 server := newTestServer("eth", new(NotificationTestService))
330 defer server.Stop()
331
332 doTest := func(count int, wantError bool) {
333 client := DialInProc(server)
334 defer client.Close()
335 ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
336 defer cancel()
337
338 // Subscribe on the server. It will start sending many notifications
339 // very quickly.
340 nc := make(chan int)
341 sub, err := client.EthSubscribe(ctx, nc, "someSubscription", count, 0)
342 if err != nil {
343 t.Fatal("can't subscribe:", err)
344 }
345 defer sub.Unsubscribe()
346
347 // Process each notification, try to run a call in between each of them.
348 for i := 0; i < count; i++ {
349 select {
350 case val := <-nc:
351 if val != i {
352 t.Fatalf("(%d/%d) unexpected value %d", i, count, val)
353 }
354 case err := <-sub.Err():
355 if wantError && err != ErrSubscriptionQueueOverflow {
356 t.Fatalf("(%d/%d) got error %q, want %q", i, count, err, ErrSubscriptionQueueOverflow)
357 } else if !wantError {
358 t.Fatalf("(%d/%d) got unexpected error %q", i, count, err)
359 }
360 return
361 }
362 var r int
363 err := client.CallContext(ctx, &r, "eth_echo", i)
364 if err != nil {
365 if !wantError {
366 t.Fatalf("(%d/%d) call error: %v", i, count, err)
367 }
368 return
369 }
370 }
371 }
372
373 doTest(8000, false)
374 doTest(10000, true)
375}
376
377func TestClientHTTP(t *testing.T) {
378 server := newTestServer("service", new(Service))

Callers

nothing calls this directly

Calls 9

newTestServerFunction · 0.85
DialInProcFunction · 0.85
EthSubscribeMethod · 0.80
CallContextMethod · 0.80
StopMethod · 0.65
CloseMethod · 0.65
FatalMethod · 0.65
UnsubscribeMethod · 0.65
ErrMethod · 0.65

Tested by

no test coverage detected