(t *testing.T)
| 349 | } |
| 350 | |
| 351 | func TestProperReconnectDelay(t *testing.T) { |
| 352 | s1 := RunServerOnPort(1222) |
| 353 | defer s1.Shutdown() |
| 354 | |
| 355 | var srvs string |
| 356 | opts := nats.GetDefaultOptions() |
| 357 | if runtime.GOOS == "windows" { |
| 358 | srvs = strings.Join(testServers[:2], ",") |
| 359 | } else { |
| 360 | srvs = strings.Join(testServers, ",") |
| 361 | } |
| 362 | opts.NoRandomize = true |
| 363 | |
| 364 | dcbCalled := false |
| 365 | closedCbCalled := false |
| 366 | dch := make(chan bool) |
| 367 | |
| 368 | dcb := func(nc *nats.Conn) { |
| 369 | // Suppress any additional calls |
| 370 | if dcbCalled { |
| 371 | return |
| 372 | } |
| 373 | dcbCalled = true |
| 374 | dch <- true |
| 375 | } |
| 376 | |
| 377 | ccb := func(_ *nats.Conn) { |
| 378 | closedCbCalled = true |
| 379 | } |
| 380 | |
| 381 | nc, err := nats.Connect(srvs, nats.DontRandomize(), nats.DisconnectHandler(dcb), nats.ClosedHandler(ccb)) |
| 382 | if err != nil { |
| 383 | t.Fatalf("Expected to connect, got err: %v\n", err) |
| 384 | } |
| 385 | defer nc.Close() |
| 386 | |
| 387 | s1.Shutdown() |
| 388 | |
| 389 | // wait for disconnect |
| 390 | if e := WaitTime(dch, 2*time.Second); e != nil { |
| 391 | t.Fatal("Did not receive a disconnect callback message") |
| 392 | } |
| 393 | |
| 394 | // Wait, want to make sure we don't spin on reconnect to non-existent servers. |
| 395 | time.Sleep(1 * time.Second) |
| 396 | |
| 397 | // Make sure we are still reconnecting.. |
| 398 | if closedCbCalled { |
| 399 | t.Fatal("Closed CB was triggered, should not have been.") |
| 400 | } |
| 401 | if status := nc.Status(); status != nats.RECONNECTING { |
| 402 | t.Fatalf("Wrong status: %d\n", status) |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | func TestProperFalloutAfterMaxAttempts(t *testing.T) { |
| 407 | s1 := RunServerOnPort(1222) |
nothing calls this directly
no test coverage detected