(t *testing.T)
| 456 | } |
| 457 | |
| 458 | func TestWSStress(t *testing.T) { |
| 459 | // Enable this test only when wanting to stress test the system, say after |
| 460 | // some changes in the library or if a bug is found. Also, don't run it |
| 461 | // with the `-race` flag! |
| 462 | t.SkipNow() |
| 463 | // Total producers (there will be 2 per subject) |
| 464 | prods := 4 |
| 465 | // Total messages sent |
| 466 | total := int64(1000000) |
| 467 | // Total messages received, there is 2 consumer per subject |
| 468 | totalRecv := 2 * total |
| 469 | // We will create a "golden" slice from which sent messages |
| 470 | // will be a subset of. Receivers will check that the content |
| 471 | // match the expected content. |
| 472 | maxPayloadSize := 100000 |
| 473 | mainPayload := make([]byte, maxPayloadSize) |
| 474 | for i := 0; i < len(mainPayload); i++ { |
| 475 | mainPayload[i] = 'A' + byte(rand.Intn(26)) |
| 476 | } |
| 477 | for _, test := range []struct { |
| 478 | name string |
| 479 | compress bool |
| 480 | }{ |
| 481 | {"no_compression", false}, |
| 482 | {"with_compression", true}, |
| 483 | } { |
| 484 | t.Run(test.name, func(t *testing.T) { |
| 485 | sopts := testWSGetDefaultOptions(t, false) |
| 486 | sopts.Websocket.Compression = test.compress |
| 487 | s := RunServerWithOptions(sopts) |
| 488 | defer s.Shutdown() |
| 489 | |
| 490 | var count int64 |
| 491 | consDoneCh := make(chan struct{}, 1) |
| 492 | errCh := make(chan error, 1) |
| 493 | prodDoneCh := make(chan struct{}, prods) |
| 494 | |
| 495 | pushErr := func(e error) { |
| 496 | select { |
| 497 | case errCh <- e: |
| 498 | default: |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | createConn := func() *nats.Conn { |
| 503 | t.Helper() |
| 504 | nc, err := nats.Connect(fmt.Sprintf("ws://127.0.0.1:%d", sopts.Websocket.Port), |
| 505 | nats.Compression(test.compress), |
| 506 | nats.ErrorHandler(func(_ *nats.Conn, sub *nats.Subscription, err error) { |
| 507 | if sub != nil { |
| 508 | err = fmt.Errorf("Subscription on %q - err=%v", sub.Subject, err) |
| 509 | } |
| 510 | pushErr(err) |
| 511 | })) |
| 512 | if err != nil { |
| 513 | t.Fatalf("Error connecting: %v", err) |
| 514 | } |
| 515 | return nc |
nothing calls this directly
no test coverage detected