|
|
@@ -6,6 +6,8 @@ import (
|
|
|
"github.com/coreos/go-etcd/etcd"
|
|
|
"math/rand"
|
|
|
"net/http"
|
|
|
+ "net/http/httptest"
|
|
|
+ "net/url"
|
|
|
"os"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
@@ -54,6 +56,53 @@ func TestSingleNode(t *testing.T) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// TestInternalVersionFail will ensure that etcd does not come up if the internal raft
|
|
|
+// versions do not match.
|
|
|
+func TestInternalVersionFail(t *testing.T) {
|
|
|
+ checkedVersion := false
|
|
|
+ testMux := http.NewServeMux()
|
|
|
+
|
|
|
+ testMux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ fmt.Fprintln(w, "This is not a version number")
|
|
|
+ checkedVersion = true
|
|
|
+ })
|
|
|
+
|
|
|
+ testMux.HandleFunc("/join", func(w http.ResponseWriter, r *http.Request) {
|
|
|
+ t.Fatal("should not attempt to join!")
|
|
|
+ })
|
|
|
+
|
|
|
+ ts := httptest.NewServer(testMux)
|
|
|
+ defer ts.Close()
|
|
|
+
|
|
|
+ fakeURL, _ := url.Parse(ts.URL)
|
|
|
+
|
|
|
+ procAttr := new(os.ProcAttr)
|
|
|
+ procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
|
|
|
+ args := []string{"etcd", "-n=node1", "-f", "-d=/tmp/node1", "-vv", "-C="+fakeURL.Host}
|
|
|
+
|
|
|
+ process, err := os.StartProcess("etcd", args, procAttr)
|
|
|
+ if err != nil {
|
|
|
+ t.Fatal("start process failed:" + err.Error())
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer process.Kill()
|
|
|
+
|
|
|
+ time.Sleep(time.Second)
|
|
|
+
|
|
|
+ _, err = http.Get("http://127.0.0.1:4001")
|
|
|
+
|
|
|
+ if err == nil {
|
|
|
+ t.Fatal("etcd node should not be up")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if checkedVersion == false {
|
|
|
+ t.Fatal("etcd did not check the version")
|
|
|
+ return
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
// This test creates a single node and then set a value to it.
|
|
|
// Then this test kills the node and restart it and tries to get the value again.
|
|
|
func TestSingleNodeRecovery(t *testing.T) {
|