MCPcopy
hub / github.com/nats-io/nats.go / TestProperFalloutAfterMaxAttemptsWithAuthMismatch

Function TestProperFalloutAfterMaxAttemptsWithAuthMismatch

test/cluster_test.go:470–544  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

468}
469
470func TestProperFalloutAfterMaxAttemptsWithAuthMismatch(t *testing.T) {
471 var myServers = []string{
472 "nats://127.0.0.1:1222",
473 "nats://127.0.0.1:4443",
474 }
475 s1 := RunServerOnPort(1222)
476 defer s1.Shutdown()
477
478 s2, _ := RunServerWithConfig("./configs/tlsverify.conf")
479 defer s2.Shutdown()
480
481 opts := nats.GetDefaultOptions()
482 opts.Servers = myServers
483 opts.NoRandomize = true
484 if runtime.GOOS == "windows" {
485 opts.MaxReconnect = 2
486 opts.Timeout = 100 * time.Millisecond
487 } else {
488 opts.MaxReconnect = 5
489 }
490 opts.ReconnectWait = (25 * time.Millisecond)
491 nats.ReconnectJitter(0, 0)(&opts)
492
493 dch := make(chan bool)
494 opts.DisconnectedErrCB = func(_ *nats.Conn, _ error) {
495 dch <- true
496 }
497
498 closedCbCalled := false
499 cch := make(chan bool)
500
501 opts.ClosedCB = func(_ *nats.Conn) {
502 closedCbCalled = true
503 cch <- true
504 }
505
506 nc, err := opts.Connect()
507 if err != nil {
508 t.Fatalf("Expected to connect, got err: %v\n", err)
509 }
510 defer nc.Close()
511
512 s1.Shutdown()
513
514 // On Windows, creating a TCP connection to a server not running takes more than
515 // a second. So be generous with the WaitTime.
516
517 // wait for disconnect
518 if e := WaitTime(dch, 5*time.Second); e != nil {
519 t.Fatal("Did not receive a disconnect callback message")
520 }
521
522 // Wait for ClosedCB
523 if e := WaitTime(cch, 5*time.Second); e != nil {
524 reconnects := nc.Stats().Reconnects
525 t.Fatalf("Did not receive a closed callback message, #reconnects: %v", reconnects)
526 }
527

Callers

nothing calls this directly

Calls 9

ConnectMethod · 0.80
FatalfMethod · 0.80
IsClosedMethod · 0.80
RunServerOnPortFunction · 0.70
RunServerWithConfigFunction · 0.70
WaitTimeFunction · 0.70
StatsMethod · 0.65
StatusMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected