diff --git a/etcdserver/server_test.go b/etcdserver/server_test.go index 6c5dbc647..3aa47e57e 100644 --- a/etcdserver/server_test.go +++ b/etcdserver/server_test.go @@ -13,6 +13,7 @@ import ( "github.com/coreos/etcd/raft" "github.com/coreos/etcd/raft/raftpb" "github.com/coreos/etcd/store" + "github.com/coreos/etcd/testutil" "github.com/coreos/etcd/third_party/code.google.com/p/go.net/context" ) @@ -519,7 +520,7 @@ func TestRecvSnapshot(t *testing.T) { s.Start() // make goroutines move forward to receive snapshot - forceGosched() + testutil.ForceGosched() s.Stop() waction := []string{"Recovery"} @@ -696,12 +697,3 @@ func TestGenID(t *testing.T) { t.Fatalf("GenID's rand seeded with 1!") } } - -// WARNING: This is a hack. -// Remove this when we are able to block/check the status of the go-routines. -func forceGosched() { - // possibility enough to sched upto 10 go routines. - for i := 0; i < 10000; i++ { - runtime.Gosched() - } -} diff --git a/raft/node_test.go b/raft/node_test.go index 92c23552a..a3f2470ce 100644 --- a/raft/node_test.go +++ b/raft/node_test.go @@ -2,11 +2,11 @@ package raft import ( "reflect" - "runtime" "testing" "time" "github.com/coreos/etcd/raft/raftpb" + "github.com/coreos/etcd/testutil" "github.com/coreos/etcd/third_party/code.google.com/p/go.net/context" ) @@ -96,7 +96,7 @@ func TestBlockProposal(t *testing.T) { errc <- n.Propose(context.TODO(), []byte("somedata")) }() - forceGosched() + testutil.ForceGosched() select { case err := <-errc: t.Errorf("err = %v, want blocking", err) @@ -104,7 +104,7 @@ func TestBlockProposal(t *testing.T) { } n.Campaign(context.TODO()) - forceGosched() + testutil.ForceGosched() select { case err := <-errc: if err != nil { @@ -216,7 +216,7 @@ func TestCompact(t *testing.T) { Nodes: []int64{1}, } - forceGosched() + testutil.ForceGosched() select { case <-n.Ready(): default: @@ -224,7 +224,7 @@ func TestCompact(t *testing.T) { } n.Compact(w.Data) - forceGosched() + testutil.ForceGosched() select { case rd := <-n.Ready(): if !reflect.DeepEqual(rd.Snapshot, w) { @@ -233,7 +233,7 @@ func TestCompact(t *testing.T) { default: t.Fatalf("unexpected compact failure: unable to create a snapshot") } - forceGosched() + testutil.ForceGosched() // TODO: this test the run updates the snapi correctly... should be tested // separately with other kinds of updates select { @@ -265,12 +265,3 @@ func TestIsStateEqual(t *testing.T) { } } } - -// WARNING: This is a hack. -// Remove this when we are able to block/check the status of the go-routines. -func forceGosched() { - // possibility enough to sched upto 10 go routines. - for i := 0; i < 10000; i++ { - runtime.Gosched() - } -} diff --git a/testutil/testutil.go b/testutil/testutil.go new file mode 100644 index 000000000..78ee24989 --- /dev/null +++ b/testutil/testutil.go @@ -0,0 +1,14 @@ +package testutil + +import ( + "runtime" +) + +// WARNING: This is a hack. +// Remove this when we are able to block/check the status of the go-routines. +func ForceGosched() { + // possibility enough to sched upto 10 go routines. + for i := 0; i < 10000; i++ { + runtime.Gosched() + } +}