diff --git a/go/test/endtoend/cluster/cluster_process.go b/go/test/endtoend/cluster/cluster_process.go index 2bb89525ed3..100ae50eb99 100644 --- a/go/test/endtoend/cluster/cluster_process.go +++ b/go/test/endtoend/cluster/cluster_process.go @@ -91,6 +91,7 @@ type Vttablet struct { HTTPPort int GrpcPort int MySQLPort int + Alias string // background executable processes mysqlctlProcess MysqlctlProcess @@ -199,6 +200,7 @@ func (cluster *LocalProcessCluster) StartKeyspace(keyspace Keyspace, shardNames cluster.TmpDirectory, cluster.VtTabletExtraArgs, cluster.EnableSemiSync) + tablet.Alias = tablet.vttabletProcess.TabletPath log.Info(fmt.Sprintf("Starting vttablet for tablet uid %d, grpc port %d", tablet.TabletUID, tablet.GrpcPort)) if err = tablet.vttabletProcess.Setup(); err != nil { diff --git a/go/test/endtoend/clustertest/vtcltd_test.go b/go/test/endtoend/clustertest/vtcltd_test.go index 4704fd7f99a..97a157f3458 100644 --- a/go/test/endtoend/clustertest/vtcltd_test.go +++ b/go/test/endtoend/clustertest/vtcltd_test.go @@ -18,11 +18,116 @@ limitations under the License. package clustertest import ( + "encoding/json" "fmt" + "io/ioutil" + "net/http" + "reflect" + "regexp" + "strings" "testing" + + "github.com/stretchr/testify/assert" +) + +var ( + oneTableOutput = `+---+ +| a | ++---+ +| 1 | ++---+ +` ) func TestVtctldProcess(t *testing.T) { - url := fmt.Sprintf("http://localhost:%d/api/keyspaces/", clusterInstance.VtctldHTTPPort) + url := fmt.Sprintf("http://%s:%d/api/keyspaces/", clusterInstance.Hostname, clusterInstance.VtctldHTTPPort) testURL(t, url, "keyspace url") + + healthCheckURL := fmt.Sprintf("http://%s:%d/debug/health/", clusterInstance.Hostname, clusterInstance.VtctldHTTPPort) + testURL(t, healthCheckURL, "vtctld health check url") + + url = fmt.Sprintf("http://%s:%d/api/topodata/", clusterInstance.Hostname, clusterInstance.VtctldHTTPPort) + + testTopoDataAPI(t, url) + testListAllTablets(t) + testTabletStatus(t) + testExecuteAsDba(t) + testExecuteAsApp(t) +} + +func testTopoDataAPI(t *testing.T, url string) { + resp, err := http.Get(url) + assert.Nil(t, err) + assert.Equal(t, resp.StatusCode, 200) + + resultMap := make(map[string]interface{}) + respByte, _ := ioutil.ReadAll(resp.Body) + err = json.Unmarshal(respByte, &resultMap) + assert.Nil(t, err) + + errorValue := reflect.ValueOf(resultMap["Error"]) + assert.Empty(t, errorValue.String()) + + assert.Contains(t, resultMap, "Children") + children := reflect.ValueOf(resultMap["Children"]) + childrenGot := fmt.Sprintf("%s", children) + assert.Contains(t, childrenGot, "global") + assert.Contains(t, childrenGot, clusterInstance.Cell) +} + +func testListAllTablets(t *testing.T) { + result, err := clusterInstance.VtctlclientProcess.ExecuteCommandWithOutput("ListAllTablets", clusterInstance.Cell) + assert.Nil(t, err) + + tablets := getAllTablets() + + tabletsFromCMD := strings.Split(result, "\n") + tabletCountFromCMD := 0 + + for _, line := range tabletsFromCMD { + if len(line) > 0 { + tabletCountFromCMD = tabletCountFromCMD + 1 + assert.Contains(t, tablets, strings.Split(line, " ")[0]) + } + } + assert.Equal(t, tabletCountFromCMD, len(tablets)) +} + +func testTabletStatus(t *testing.T) { + resp, err := http.Get(fmt.Sprintf("http://%s:%d", clusterInstance.Hostname, clusterInstance.Keyspaces[0].Shards[0].Vttablets[0].HTTPPort)) + assert.Nil(t, err) + respByte, err := ioutil.ReadAll(resp.Body) + assert.Nil(t, err) + result := string(respByte) + println(result) + println(strings.Contains(result, "Polling health information from.")) + matched, err := regexp.Match(`Polling health information from.+MySQLReplicationLag`, []byte(result)) + assert.Nil(t, err) + assert.True(t, matched) + assert.True(t, strings.Contains(result, `Alias: