1
0
Fork 0

Unit test zero join attempts

master
Philip O'Toole 4 years ago
parent 3f0182c8e8
commit 32a7625e69

@ -4,6 +4,7 @@ import (
"bytes"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"log"
@ -16,6 +17,11 @@ import (
httpd "github.com/rqlite/rqlite/http"
)
var (
// ErrJoinFailed is returned when a node fails to join a cluster
ErrJoinFailed = errors.New("failed to join cluster")
)
// Join attempts to join the cluster at one of the addresses given in joinAddr.
// It walks through joinAddr in order, and sets the node ID and Raft address of
// the joining node as id addr respectively. It returns the endpoint successfully
@ -41,7 +47,7 @@ func Join(joinAddr []string, id, addr string, voter bool, meta map[string]string
time.Sleep(attemptInterval)
}
logger.Printf("failed to join cluster at %s, after %d attempts", joinAddr, numAttempts)
return "", err
return "", ErrJoinFailed
}
func join(joinAddr, id, addr string, voter bool, meta map[string]string, tlsConfig *tls.Config, logger *log.Logger) (string, error) {

@ -55,6 +55,17 @@ func Test_SingleJoinOK(t *testing.T) {
}
}
func Test_SingleJoinZeroAttempts(t *testing.T) {
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
t.Fatalf("handler should not have been called")
}))
_, err := Join([]string{ts.URL}, "id0", "127.0.0.1:9090", false, nil, 0, attemptInterval, nil)
if err != ErrJoinFailed {
t.Fatalf("Incorrect error returned when zero attempts specified")
}
}
func Test_SingleJoinMetaOK(t *testing.T) {
var body map[string]interface{}

Loading…
Cancel
Save