(t *testing.T)
| 377 | } |
| 378 | |
| 379 | func TestMultiple(t *testing.T) { |
| 380 | testDuration := time.Second * 10 |
| 381 | |
| 382 | // number of kites that will be queried. Means if there are 50 example |
| 383 | // kites available only 10 of them will be queried. Increasing this number |
| 384 | // makes the test fail. |
| 385 | kiteNumber := runtime.GOMAXPROCS(0) |
| 386 | |
| 387 | // number of clients that will query example kites |
| 388 | clientNumber := 10 |
| 389 | |
| 390 | for i := 0; i < kiteNumber; i++ { |
| 391 | m := kite.New("example"+strconv.Itoa(i), "0.1."+strconv.Itoa(i)) |
| 392 | m.Config = conf.Config.Copy() |
| 393 | |
| 394 | kiteURL := &url.URL{Scheme: "http", Host: "localhost:4444", Path: "/kite"} |
| 395 | err := m.RegisterForever(kiteURL) |
| 396 | if err != nil { |
| 397 | t.Error(err) |
| 398 | } |
| 399 | defer m.Close() |
| 400 | } |
| 401 | |
| 402 | clients := make([]*kite.Kite, clientNumber) |
| 403 | for i := 0; i < clientNumber; i++ { |
| 404 | c := kite.New("client"+strconv.Itoa(i), "0.0.1") |
| 405 | c.Config = conf.Config.Copy() |
| 406 | c.SetupKontrolClient() |
| 407 | clients[i] = c |
| 408 | defer c.Close() |
| 409 | } |
| 410 | |
| 411 | var wg sync.WaitGroup |
| 412 | |
| 413 | timeout := time.After(testDuration) |
| 414 | |
| 415 | // every one second |
| 416 | for { |
| 417 | select { |
| 418 | case <-time.Tick(time.Second): |
| 419 | for i := 0; i < clientNumber; i++ { |
| 420 | wg.Add(1) |
| 421 | |
| 422 | go func(i int) { |
| 423 | defer wg.Done() |
| 424 | |
| 425 | time.Sleep(time.Millisecond * time.Duration(rand.Intn(500))) |
| 426 | |
| 427 | query := &protocol.KontrolQuery{ |
| 428 | Username: conf.Config.Username, |
| 429 | Environment: conf.Config.Environment, |
| 430 | Name: "example" + strconv.Itoa(rand.Intn(kiteNumber)), |
| 431 | } |
| 432 | |
| 433 | start := time.Now() |
| 434 | k, err := clients[i].GetKites(query) |
| 435 | elapsedTime := time.Since(start) |
| 436 | if err != nil { |
nothing calls this directly
no test coverage detected