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

Function TestCount2B

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

Source from the content-addressed store, hash-verified

474}
475
476func TestCount2B(t *testing.T) {
477 servers := 3
478 cfg := make_config(t, servers, false, false)
479 defer cfg.cleanup()
480
481 cfg.begin("Test (2B): RPC counts aren't too high")
482
483 rpcs := func() (n int) {
484 for j := 0; j < servers; j++ {
485 n += cfg.rpcCount(j)
486 }
487 return
488 }
489
490 leader := cfg.checkOneLeader()
491
492 total1 := rpcs()
493
494 if total1 > 30 || total1 < 1 {
495 t.Fatalf("too many or few RPCs (%v) to elect initial leader\n", total1)
496 }
497
498 var total2 int
499 var success bool
500loop:
501 for try := 0; try < 5; try++ {
502 if try > 0 {
503 // give solution some time to settle
504 time.Sleep(3 * time.Second)
505 }
506
507 leader = cfg.checkOneLeader()
508 total1 = rpcs()
509
510 iters := 10
511 starti, term, ok := cfg.rafts[leader].Start(1)
512 if !ok {
513 // leader moved on really quickly
514 continue
515 }
516 cmds := []int{}
517 for i := 1; i < iters+2; i++ {
518 x := int(rand.Int31())
519 cmds = append(cmds, x)
520 index1, term1, ok := cfg.rafts[leader].Start(x)
521 if term1 != term {
522 // Term changed while starting
523 continue loop
524 }
525 if !ok {
526 // No longer the leader, so term has changed
527 continue loop
528 }
529 if starti+i != index1 {
530 t.Fatalf("Start() failed")
531 }
532 }
533

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected