node_bench_test.go 514 B

12345678910111213141516171819202122232425
  1. package raft
  2. import (
  3. "testing"
  4. "github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
  5. )
  6. func BenchmarkOneNode(b *testing.B) {
  7. ctx, cancel := context.WithCancel(context.Background())
  8. defer cancel()
  9. n := StartNode(1, []Peer{{ID: 1}}, 0, 0)
  10. defer n.Stop()
  11. n.Campaign(ctx)
  12. for i := 0; i < b.N; i++ {
  13. <-n.Ready()
  14. n.Propose(ctx, []byte("foo"))
  15. }
  16. rd := <-n.Ready()
  17. if rd.HardState.Commit != uint64(b.N+1) {
  18. b.Errorf("commit = %d, want %d", rd.HardState.Commit, b.N+1)
  19. }
  20. }