(t *testing.T)
| 105 | } |
| 106 | |
| 107 | func TestWSControlFrames(t *testing.T) { |
| 108 | sopts := testWSGetDefaultOptions(t, false) |
| 109 | s := RunServerWithOptions(sopts) |
| 110 | defer s.Shutdown() |
| 111 | |
| 112 | rch := make(chan bool, 10) |
| 113 | ncSub, err := nats.Connect(s.ClientURL(), |
| 114 | nats.ReconnectWait(50*time.Millisecond), |
| 115 | nats.ReconnectHandler(func(_ *nats.Conn) { rch <- true }), |
| 116 | ) |
| 117 | if err != nil { |
| 118 | t.Fatalf("Error on connect: %v", err) |
| 119 | } |
| 120 | defer ncSub.Close() |
| 121 | |
| 122 | sub, err := ncSub.SubscribeSync("foo") |
| 123 | if err != nil { |
| 124 | t.Fatalf("Error on subscribe: %v", err) |
| 125 | } |
| 126 | if err := ncSub.Flush(); err != nil { |
| 127 | t.Fatalf("Error on flush: %v", err) |
| 128 | } |
| 129 | |
| 130 | dch := make(chan error, 10) |
| 131 | url := fmt.Sprintf("ws://127.0.0.1:%d", sopts.Websocket.Port) |
| 132 | nc, err := nats.Connect(url, |
| 133 | nats.ReconnectWait(50*time.Millisecond), |
| 134 | nats.DisconnectErrHandler(func(_ *nats.Conn, err error) { dch <- err }), |
| 135 | nats.ReconnectHandler(func(_ *nats.Conn) { rch <- true }), |
| 136 | ) |
| 137 | if err != nil { |
| 138 | t.Fatalf("Error on connect: %v", err) |
| 139 | } |
| 140 | defer nc.Close() |
| 141 | |
| 142 | // Shutdown the server, which should send a close message, which by |
| 143 | // spec the client will try to echo back. |
| 144 | s.Shutdown() |
| 145 | |
| 146 | select { |
| 147 | case <-dch: |
| 148 | // OK |
| 149 | case <-time.After(time.Second): |
| 150 | t.Fatal("Should have been disconnected") |
| 151 | } |
| 152 | |
| 153 | s = RunServerWithOptions(sopts) |
| 154 | defer s.Shutdown() |
| 155 | |
| 156 | // Wait for both connections to reconnect |
| 157 | if err := Wait(rch); err != nil { |
| 158 | t.Fatalf("Should have reconnected: %v", err) |
| 159 | } |
| 160 | if err := Wait(rch); err != nil { |
| 161 | t.Fatalf("Should have reconnected: %v", err) |
| 162 | } |
| 163 | // Even if the first connection reconnects, there is no guarantee |
| 164 | // that the resend of SUB has yet been processed by the server. |
nothing calls this directly
no test coverage detected