mirror of
https://github.com/rqlite/rqlite.git
synced 2022-10-30 02:37:32 +03:00
Extend liveness testing
This commit is contained in:
@@ -289,6 +289,18 @@ func (n *Node) Ready() (bool, error) {
|
||||
return resp.StatusCode == 200, nil
|
||||
}
|
||||
|
||||
// Liveness returns the viveness status for the node, primarily
|
||||
// for use by Kubernetes.
|
||||
func (n *Node) Liveness() (bool, error) {
|
||||
v, _ := url.Parse("http://" + n.APIAddr + "/readyz?noleader")
|
||||
|
||||
resp, err := http.Get(v.String())
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
return resp.StatusCode == 200, nil
|
||||
}
|
||||
|
||||
// Expvar returns the expvar output for node.
|
||||
func (n *Node) Expvar() (string, error) {
|
||||
v, _ := url.Parse("http://" + n.APIAddr + "/debug/vars")
|
||||
|
||||
@@ -46,7 +46,7 @@ func Test_SingleNodeBasicEndpoint(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SingleNodeNotReady(t *testing.T) {
|
||||
func Test_SingleNodeNotReadyLive(t *testing.T) {
|
||||
node := mustNewNode(false)
|
||||
defer node.Deprovision()
|
||||
ready, err := node.Ready()
|
||||
@@ -56,6 +56,25 @@ func Test_SingleNodeNotReady(t *testing.T) {
|
||||
if ready {
|
||||
t.Fatalf("node is ready when it should not be")
|
||||
}
|
||||
|
||||
liveness, err := node.Liveness()
|
||||
if err != nil {
|
||||
t.Fatalf(`failed to retrieve liveness: %s`, err)
|
||||
}
|
||||
if !liveness {
|
||||
t.Fatalf("node is not live when it should not be")
|
||||
}
|
||||
|
||||
// Confirm that hitting various endpoints with a non-ready node
|
||||
// is OK.
|
||||
_, err = node.Nodes(false)
|
||||
if err != nil {
|
||||
t.Fatalf(`failed to retrieve Nodes: %s`, err)
|
||||
}
|
||||
_, err = node.Status()
|
||||
if err != nil {
|
||||
t.Fatalf(`failed to retrieve status: %s`, err)
|
||||
}
|
||||
}
|
||||
|
||||
func Test_SingleNode(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user