internal_version_test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // +build ignore
  2. package test
  3. import (
  4. "fmt"
  5. "net/http"
  6. "net/http/httptest"
  7. "net/url"
  8. "os"
  9. "sync"
  10. "testing"
  11. "time"
  12. )
  13. // Ensure that etcd does not come up if the internal raft versions do not match.
  14. func TestInternalVersion(t *testing.T) {
  15. var mu sync.Mutex
  16. checkedVersion := false
  17. testMux := http.NewServeMux()
  18. testMux.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
  19. fmt.Fprintln(w, "This is not a version number")
  20. mu.Lock()
  21. defer mu.Unlock()
  22. checkedVersion = true
  23. })
  24. testMux.HandleFunc("/join", func(w http.ResponseWriter, r *http.Request) {
  25. t.Fatal("should not attempt to join!")
  26. })
  27. ts := httptest.NewServer(testMux)
  28. defer ts.Close()
  29. fakeURL, _ := url.Parse(ts.URL)
  30. procAttr := new(os.ProcAttr)
  31. procAttr.Files = []*os.File{nil, os.Stdout, os.Stderr}
  32. args := []string{"etcd", "-name=node1", "-f", "-data-dir=/tmp/node1", "-peers=" + fakeURL.Host}
  33. process, err := os.StartProcess(EtcdBinPath, args, procAttr)
  34. if err != nil {
  35. t.Fatal("start process failed:" + err.Error())
  36. return
  37. }
  38. time.Sleep(time.Second)
  39. process.Kill()
  40. _, err = http.Get("http://127.0.0.1:4001")
  41. if err == nil {
  42. t.Fatal("etcd node should not be up")
  43. return
  44. }
  45. mu.Lock()
  46. defer mu.Unlock()
  47. if checkedVersion == false {
  48. t.Fatal("etcd did not check the version")
  49. return
  50. }
  51. }