etcd/raft/node_bench_test.go

26 lines
514 B
Go
Raw Normal View History

2014-09-18 06:41:31 +04:00
package raft
import (
"testing"
2014-10-21 23:46:39 +04:00
"github.com/coreos/etcd/Godeps/_workspace/src/code.google.com/p/go.net/context"
2014-09-18 06:41:31 +04:00
)
func BenchmarkOneNode(b *testing.B) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
2014-10-21 23:46:39 +04:00
n := StartNode(1, []Peer{{ID: 1}}, 0, 0)
2014-09-18 06:41:31 +04:00
defer n.Stop()
n.Campaign(ctx)
for i := 0; i < b.N; i++ {
<-n.Ready()
n.Propose(ctx, []byte("foo"))
}
rd := <-n.Ready()
2014-10-21 23:46:39 +04:00
if rd.HardState.Commit != uint64(b.N+1) {
b.Errorf("commit = %d, want %d", rd.HardState.Commit, b.N+1)
2014-09-18 06:41:31 +04:00
}
}