(t *testing.T)
| 1021 | } |
| 1022 | |
| 1023 | func TestForceReconnectSubsequentCalls(t *testing.T) { |
| 1024 | s := RunDefaultServer() |
| 1025 | defer s.Shutdown() |
| 1026 | |
| 1027 | nc, err := nats.Connect(s.ClientURL(), nats.ReconnectWait(10*time.Second)) |
| 1028 | if err != nil { |
| 1029 | t.Fatalf("Unexpected error on connect: %v", err) |
| 1030 | } |
| 1031 | defer nc.Close() |
| 1032 | |
| 1033 | statusCh := nc.StatusChanged(nats.RECONNECTING, nats.CONNECTED) |
| 1034 | defer close(statusCh) |
| 1035 | newStatus := make(chan nats.Status, 10) |
| 1036 | // non-blocking channel, so we need to be constantly listening |
| 1037 | go func() { |
| 1038 | for { |
| 1039 | s, ok := <-statusCh |
| 1040 | if !ok { |
| 1041 | return |
| 1042 | } |
| 1043 | newStatus <- s |
| 1044 | } |
| 1045 | }() |
| 1046 | |
| 1047 | for range 10 { |
| 1048 | err = nc.ForceReconnect() |
| 1049 | if err != nil { |
| 1050 | t.Fatalf("Unexpected error on reconnect: %v", err) |
| 1051 | } |
| 1052 | } |
| 1053 | |
| 1054 | WaitOnChannel(t, newStatus, nats.RECONNECTING) |
| 1055 | WaitOnChannel(t, newStatus, nats.CONNECTED) |
| 1056 | |
| 1057 | // check that we did not try to reconnect again |
| 1058 | select { |
| 1059 | case <-newStatus: |
| 1060 | t.Fatal("Should not have received a new status") |
| 1061 | case <-time.After(200 * time.Millisecond): |
| 1062 | } |
| 1063 | |
| 1064 | // now force a reconnect again |
| 1065 | if err := nc.ForceReconnect(); err != nil { |
| 1066 | t.Fatalf("Unexpected error on reconnect: %v", err) |
| 1067 | } |
| 1068 | WaitOnChannel(t, newStatus, nats.RECONNECTING) |
| 1069 | WaitOnChannel(t, newStatus, nats.CONNECTED) |
| 1070 | } |
| 1071 | |
| 1072 | func TestAuthExpiredForceReconnect(t *testing.T) { |
| 1073 | ts := runTrustServer() |
nothing calls this directly
no test coverage detected