Skip to content

Commit

Permalink
roachtest: add acceptance/status-server
Browse files Browse the repository at this point in the history
Move the status-server acceptance test to a new acceptance/status-server
roachtest.

See cockroachdb#29151

Release note: None
  • Loading branch information
petermattis committed Sep 1, 2018
1 parent d27dc18 commit 9f683d2
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 147 deletions.
147 changes: 0 additions & 147 deletions pkg/acceptance/status_server_test.go

This file was deleted.

1 change: 1 addition & 0 deletions pkg/cmd/roachtest/acceptance.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func registerAcceptance(r *registry) {
{"build-info", runBuildInfo},
{"cli/node-status", runCLINodeStatus},
{"event-log", runEventLog},
{"status-server", runStatusServer},
}
for _, tc := range testCases {
spec.SubTests = append(spec.SubTests, testSpec{
Expand Down
112 changes: 112 additions & 0 deletions pkg/cmd/roachtest/status_server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright 2018 The Cockroach Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
// implied. See the License for the specific language governing
// permissions and limitations under the License.

package main

import (
"context"
"fmt"
"io/ioutil"
"net/http"

"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/server/serverpb"
"github.com/cockroachdb/cockroach/pkg/util/httputil"
)

func runStatusServer(ctx context.Context, t *test, c *cluster) {
c.Put(ctx, cockroach, "./cockroach")
c.Wipe(ctx)
c.Start(ctx)

// Get the ids for each node.
idMap := make(map[int]roachpb.NodeID)
urlMap := make(map[int]string)
for i, addr := range c.ExternalAdminUIAddr(ctx, c.All()) {
var details serverpb.DetailsResponse
url := `http://` + addr + `/_status/details/local`
if err := httputil.GetJSON(http.Client{}, url, &details); err != nil {
t.Fatal(err)
}
idMap[i+1] = details.NodeID
urlMap[i+1] = `http://` + addr
}

// get performs an HTTP GET to the specified path for a specific node.
get := func(base, rel string) []byte {
url := base + rel
resp, err := http.Get(url)
if err != nil {
t.Fatalf("could not GET %s - %s", url, err)
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
t.Fatalf("could not read body for %s - %s", url, err)
}
if resp.StatusCode != http.StatusOK {
t.Fatalf("could not GET %s - statuscode: %d - body: %s", url, resp.StatusCode, body)
}
c.l.Printf("OK response from %s\n", url)
return body
}

// checkNode checks all the endpoints of the status server hosted by node and
// requests info for the node with otherNodeID. That node could be the same
// other node, the same node or "local".
checkNode := func(url string, nodeID, otherNodeID, expectedNodeID roachpb.NodeID) {
urlIDs := []string{otherNodeID.String()}
if nodeID == otherNodeID {
urlIDs = append(urlIDs, "local")
}
var details serverpb.DetailsResponse
for _, urlID := range urlIDs {
if err := httputil.GetJSON(http.Client{}, url+`/_status/details/`+urlID, &details); err != nil {
t.Fatalf("unable to parse details - %s", err)
}
if details.NodeID != expectedNodeID {
t.Fatalf("%d calling %s: node ids don't match - expected %d, actual %d",
nodeID, urlID, expectedNodeID, details.NodeID)
}

get(url, fmt.Sprintf("/_status/gossip/%s", urlID))
get(url, fmt.Sprintf("/_status/nodes/%s", urlID))
get(url, fmt.Sprintf("/_status/logfiles/%s", urlID))
get(url, fmt.Sprintf("/_status/logs/%s", urlID))
get(url, fmt.Sprintf("/_status/stacks/%s", urlID))
}

get(url, "/_status/vars")
}

// Check local response for the every node.
for i := 1; i <= c.nodes; i++ {
id := idMap[i]
checkNode(urlMap[i], id, id, id)
get(urlMap[i], "/_status/nodes")
}

// Proxy from the first node to the last node.
firstNode := 1
lastNode := c.nodes
firstID := idMap[firstNode]
lastID := idMap[lastNode]
checkNode(urlMap[firstNode], firstID, lastID, lastID)

// And from the last node to the first node.
checkNode(urlMap[lastNode], lastID, firstID, firstID)

// And from the last node to the last node.
checkNode(urlMap[lastNode], lastID, lastID, lastID)
}

0 comments on commit 9f683d2

Please sign in to comment.