MCPcopy Index your code
hub / github.com/koding/kite / TestSendError

Function TestSendError

kite_test.go:177–227  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

175}
176
177func 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.

Callers

nothing calls this directly

Calls 14

DialTimeoutMethod · 0.95
CloseMethod · 0.95
TellMethod · 0.95
newXhrKiteFunction · 0.85
HandleFuncMethod · 0.80
MustStringMethod · 0.80
OneMethod · 0.80
ServerReadyNotifyMethod · 0.80
NewClientMethod · 0.80
FatalMethod · 0.80
ErrorMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected