mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
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:
parent
0cb304ec61
commit
02b24c58fd
@ -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{
|
||||
|
@ -236,8 +236,6 @@ func (rc *raftNode) stop() {
|
||||
close(rc.commitC)
|
||||
close(rc.errorC)
|
||||
rc.node.Stop()
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
func (rc *raftNode) stopHTTP() {
|
||||
|
Loading…
x
Reference in New Issue
Block a user