(t *testing.T)
| 175 | } |
| 176 | |
| 177 | func TestSendError(t *testing.T) { |
| 178 | const timeout = 5 * time.Second |
| 179 | |
| 180 | ksrv := newXhrKite("echo-server", "0.0.1") |
| 181 | ksrv.Config.DisableAuthentication = true |
| 182 | ksrv.HandleFunc("echo", func(r *Request) (interface{}, error) { |
| 183 | return r.Args.One().MustString(), nil |
| 184 | }) |
| 185 | |
| 186 | go ksrv.Run() |
| 187 | <-ksrv.ServerReadyNotify() |
| 188 | defer ksrv.Close() |
| 189 | |
| 190 | clientSession := make(chan sockjs.Session, 1) |
| 191 | |
| 192 | kcli := newXhrKite("echo-client", "0.0.1") |
| 193 | kcli.Config.DisableAuthentication = true |
| 194 | c := kcli.NewClient(fmt.Sprintf("http://127.0.0.1:%d/kite", ksrv.Port())) |
| 195 | c.testHookSetSession = func(s sockjs.Session) { |
| 196 | if _, ok := s.(*sockjsclient.XHRSession); ok { |
| 197 | clientSession <- s |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | if err := c.DialTimeout(timeout); err != nil { |
| 202 | t.Fatalf("DialTimeout()=%s", err) |
| 203 | } |
| 204 | |
| 205 | select { |
| 206 | case <-time.After(timeout): |
| 207 | t.Fatal("timed out waiting for session") |
| 208 | case c := <-clientSession: |
| 209 | c.Close(500, "transport closed") |
| 210 | } |
| 211 | |
| 212 | done := make(chan error) |
| 213 | |
| 214 | go func() { |
| 215 | _, err := c.Tell("echo", "should fail") |
| 216 | done <- err |
| 217 | }() |
| 218 | |
| 219 | select { |
| 220 | case err := <-done: |
| 221 | if err == nil { |
| 222 | t.Error("expected err != nil, was nil") |
| 223 | } |
| 224 | case <-time.After(timeout): |
| 225 | t.Fatal("timed out waiting for send failure") |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | // Call a single method with multiple clients. This test is implemented to be |
| 230 | // sure the method is calling back with in the same time and not timing out. |
nothing calls this directly
no test coverage detected