This test checks that Client doesn't lock up when a single subscriber doesn't read subscription events.
(t *testing.T)
| 326 | // This test checks that Client doesn't lock up when a single subscriber |
| 327 | // doesn't read subscription events. |
| 328 | func 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 | |
| 377 | func TestClientHTTP(t *testing.T) { |
| 378 | server := newTestServer("service", new(Service)) |
nothing calls this directly
no test coverage detected