MCPcopy
hub / github.com/chaozh/MIT-6.824 / TestConcurrentStarts2B

Function TestConcurrentStarts2B

src/raft/test_test.go:265–364  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

263}
264
265func 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
273loop:
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

Callers

nothing calls this directly

Calls 9

checkOneLeaderMethod · 0.80
StartMethod · 0.80
DoneMethod · 0.80
GetStateMethod · 0.80
waitMethod · 0.80
make_configFunction · 0.70
cleanupMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected