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)
| 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. |
| 231 | func 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 | |
| 278 | func TestNoConcurrentCallbacks(t *testing.T) { |
| 279 | const timeout = 2 * time.Second |
nothing calls this directly
no test coverage detected