|
|
|
@ -7,8 +7,12 @@ import (
|
|
|
|
|
"net/http"
|
|
|
|
|
"net/http/httptest"
|
|
|
|
|
"testing"
|
|
|
|
|
"time"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const numAttempts int = 3
|
|
|
|
|
const attemptInterval time.Duration = 5 * time.Second
|
|
|
|
|
|
|
|
|
|
func Test_SingleJoinOK(t *testing.T) {
|
|
|
|
|
var body map[string]interface{}
|
|
|
|
|
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
@ -31,7 +35,8 @@ func Test_SingleJoinOK(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
|
|
j, err := Join([]string{ts.URL}, "id0", "127.0.0.1:9090", false, nil, nil)
|
|
|
|
|
j, err := Join([]string{ts.URL}, "id0", "127.0.0.1:9090", false, nil,
|
|
|
|
|
numAttempts, attemptInterval, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
@ -74,7 +79,8 @@ func Test_SingleJoinMetaOK(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
nodeAddr := "127.0.0.1:9090"
|
|
|
|
|
md := map[string]string{"foo": "bar"}
|
|
|
|
|
j, err := Join([]string{ts.URL}, "id0", nodeAddr, true, md, nil)
|
|
|
|
|
j, err := Join([]string{ts.URL}, "id0", nodeAddr, true, md,
|
|
|
|
|
numAttempts, attemptInterval, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
@ -100,7 +106,8 @@ func Test_SingleJoinFail(t *testing.T) {
|
|
|
|
|
}))
|
|
|
|
|
defer ts.Close()
|
|
|
|
|
|
|
|
|
|
_, err := Join([]string{ts.URL}, "id0", "127.0.0.1:9090", true, nil, nil)
|
|
|
|
|
_, err := Join([]string{ts.URL}, "id0", "127.0.0.1:9090", true, nil,
|
|
|
|
|
numAttempts, attemptInterval, nil)
|
|
|
|
|
if err == nil {
|
|
|
|
|
t.Fatalf("expected error when joining bad node")
|
|
|
|
|
}
|
|
|
|
@ -114,7 +121,8 @@ func Test_DoubleJoinOK(t *testing.T) {
|
|
|
|
|
}))
|
|
|
|
|
defer ts2.Close()
|
|
|
|
|
|
|
|
|
|
j, err := Join([]string{ts1.URL, ts2.URL}, "id0", "127.0.0.1:9090", true, nil, nil)
|
|
|
|
|
j, err := Join([]string{ts1.URL, ts2.URL}, "id0", "127.0.0.1:9090", true, nil,
|
|
|
|
|
numAttempts, attemptInterval, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
@ -132,7 +140,8 @@ func Test_DoubleJoinOKSecondNode(t *testing.T) {
|
|
|
|
|
}))
|
|
|
|
|
defer ts2.Close()
|
|
|
|
|
|
|
|
|
|
j, err := Join([]string{ts1.URL, ts2.URL}, "id0", "127.0.0.1:9090", true, nil, nil)
|
|
|
|
|
j, err := Join([]string{ts1.URL, ts2.URL}, "id0", "127.0.0.1:9090", true, nil,
|
|
|
|
|
numAttempts, attemptInterval, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
@ -152,7 +161,8 @@ func Test_DoubleJoinOKSecondNodeRedirect(t *testing.T) {
|
|
|
|
|
}))
|
|
|
|
|
defer ts2.Close()
|
|
|
|
|
|
|
|
|
|
j, err := Join([]string{ts2.URL}, "id0", "127.0.0.1:9090", true, nil, nil)
|
|
|
|
|
j, err := Join([]string{ts2.URL}, "id0", "127.0.0.1:9090", true, nil,
|
|
|
|
|
numAttempts, attemptInterval, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("failed to join a single node: %s", err.Error())
|
|
|
|
|
}
|
|
|
|
|