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

Function TestConcurrency

kite_test.go:231–276  ·  view source on GitHub ↗

Call a single method with multiple clients. This test is implemented to be sure the method is calling back with in the same time and not timing out.

(t *testing.T)

Source from the content-addressed store, hash-verified

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.
231func TestConcurrency(t *testing.T) {
232 // Create a mathworker kite
233 mathKite := newXhrKite("mathworker", "0.0.1")
234 mathKite.Config.DisableAuthentication = true
235 mathKite.Config.Port = 3637
236 mathKite.HandleFunc("ping", func(r *Request) (interface{}, error) {
237 time.Sleep(time.Second)
238 return "pong", nil
239 })
240 go mathKite.Run()
241 <-mathKite.ServerReadyNotify()
242 defer mathKite.Close()
243
244 // number of exp kites that will call mathworker kite
245 clientNumber := 3
246
247 clients := make([]*Client, clientNumber)
248 for i := range clients {
249 c := newXhrKite("exp", "0.0.1").NewClient("http://127.0.0.1:3637/kite")
250 if err := c.Dial(); err != nil {
251 t.Fatal(err)
252 }
253
254 clients[i] = c
255 defer c.Close()
256 }
257
258 var wg sync.WaitGroup
259
260 for i := range clients {
261 wg.Add(1)
262 go func(i int) {
263 defer wg.Done()
264 result, err := clients[i].TellWithTimeout("ping", 4*time.Second)
265 if err != nil {
266 t.Fatal(err)
267 }
268
269 if result.MustString() != "pong" {
270 t.Errorf("Got %s want: pong", result.MustString())
271 }
272 }(i)
273 }
274
275 wg.Wait()
276}
277
278func TestNoConcurrentCallbacks(t *testing.T) {
279 const timeout = 2 * time.Second

Callers

nothing calls this directly

Calls 12

DialMethod · 0.95
CloseMethod · 0.95
newXhrKiteFunction · 0.85
HandleFuncMethod · 0.80
ServerReadyNotifyMethod · 0.80
NewClientMethod · 0.80
FatalMethod · 0.80
TellWithTimeoutMethod · 0.80
MustStringMethod · 0.80
AddMethod · 0.65
RunMethod · 0.45
CloseMethod · 0.45

Tested by

no test coverage detected