contrib/raftexample: fix tests

os.Exit() on raft stop breaks out of the test fixture; instead,
monitor the error channel and exit on close
This commit is contained in:
Anthony Romano 2016-02-10 10:21:34 -08:00
parent 0cb304ec61
commit 02b24c58fd
2 changed files with 9 additions and 2 deletions

View File

@ -18,6 +18,7 @@ import (
"io/ioutil"
"log"
"net/http"
"os"
"strconv"
"github.com/coreos/etcd/raft/raftpb"
@ -104,6 +105,14 @@ func (h *httpKVAPI) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func serveHttpKVAPI(port int, proposeC chan<- string, confChangeC chan<- raftpb.ConfChange,
commitC <-chan *string, errorC <-chan error) {
// exit when raft goes down
go func() {
if err, ok := <-errorC; ok {
log.Fatal(err)
}
os.Exit(0)
}()
srv := http.Server{
Addr: ":" + strconv.Itoa(port),
Handler: &httpKVAPI{

View File

@ -236,8 +236,6 @@ func (rc *raftNode) stop() {
close(rc.commitC)
close(rc.errorC)
rc.node.Stop()
os.Exit(0)
}
func (rc *raftNode) stopHTTP() {