(t *testing.T)
| 263 | } |
| 264 | |
| 265 | func TestConcurrentStarts2B(t *testing.T) { |
| 266 | servers := 3 |
| 267 | cfg := make_config(t, servers, false, false) |
| 268 | defer cfg.cleanup() |
| 269 | |
| 270 | cfg.begin("Test (2B): concurrent Start()s") |
| 271 | |
| 272 | var success bool |
| 273 | loop: |
| 274 | for try := 0; try < 5; try++ { |
| 275 | if try > 0 { |
| 276 | // give solution some time to settle |
| 277 | time.Sleep(3 * time.Second) |
| 278 | } |
| 279 | |
| 280 | leader := cfg.checkOneLeader() |
| 281 | _, term, ok := cfg.rafts[leader].Start(1) |
| 282 | if !ok { |
| 283 | // leader moved on really quickly |
| 284 | continue |
| 285 | } |
| 286 | |
| 287 | iters := 5 |
| 288 | var wg sync.WaitGroup |
| 289 | is := make(chan int, iters) |
| 290 | for ii := 0; ii < iters; ii++ { |
| 291 | wg.Add(1) |
| 292 | go func(i int) { |
| 293 | defer wg.Done() |
| 294 | i, term1, ok := cfg.rafts[leader].Start(100 + i) |
| 295 | if term1 != term { |
| 296 | return |
| 297 | } |
| 298 | if ok != true { |
| 299 | return |
| 300 | } |
| 301 | is <- i |
| 302 | }(ii) |
| 303 | } |
| 304 | |
| 305 | wg.Wait() |
| 306 | close(is) |
| 307 | |
| 308 | for j := 0; j < servers; j++ { |
| 309 | if t, _ := cfg.rafts[j].GetState(); t != term { |
| 310 | // term changed -- can't expect low RPC counts |
| 311 | continue loop |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | failed := false |
| 316 | cmds := []int{} |
| 317 | for index := range is { |
| 318 | cmd := cfg.wait(index, servers, term) |
| 319 | if ix, ok := cmd.(int); ok { |
| 320 | if ix == -1 { |
| 321 | // peers have moved on to later terms |
| 322 | // so we can't expect all Start()s to |
nothing calls this directly
no test coverage detected