Skip to content

Commit

Permalink
Changes from self review
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Mar 20, 2024
1 parent a698f86 commit 2f3eaea
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions go/test/endtoend/vreplication/vreplication_vtctldclient_cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ func TestVtctldclientCLI(t *testing.T) {
t.Run("MoveTablesCreateFlags2", func(t *testing.T) {
testMoveTablesFlags2(t, &mt, sourceKeyspaceName, targetKeyspaceName, workflowName, targetTabs)
})
t.Run("WorkflowList", func(t *testing.T) {
testMoveTablesList(t, sourceKeyspaceName, targetKeyspaceName, workflowName, targetTabs)
})
t.Run("MoveTablesCompleteFlags3", func(t *testing.T) {
testMoveTablesFlags3(t, sourceKeyspaceName, targetKeyspaceName, targetTabs)
})
Expand All @@ -86,6 +83,9 @@ func TestVtctldclientCLI(t *testing.T) {
}
splitShard(t, targetKeyspaceName, reshardWorkflowName, sourceShard, newShards, tablets)
})
t.Run("WorkflowList", func(t *testing.T) {
testWorkflowList(t, sourceKeyspaceName, targetKeyspaceName, workflowName, targetTabs)
})
}

// Tests several create flags and some complete flags and validates that some of them are set correctly for the workflow.
Expand Down Expand Up @@ -113,27 +113,6 @@ func testMoveTablesFlags1(t *testing.T, mt *iMoveTables, sourceKeyspace, targetK
confirmNoRoutingRules(t)
}

// Tests several create workflows in order to confirm the listing works.
func testMoveTablesList(t *testing.T, sourceKeyspace, targetKeyspace, workflowName string, targetTabs map[string]*cluster.VttabletProcess) {
tables := []string{"customer", "customer2"}
createFlags1 := []string{"--auto-start=false", "--tablet-types",
"primary,rdonly", "--tablet-types-in-preference-order=true", "--all-cells",
}
createFlags2 := []string{"--auto-start=false", "--tablet-types",
"primary,rdonly", "--tablet-types-in-preference-order=true", "--all-cells",
}
// Test one set of MoveTable flags.
mt1 := createMoveTables(t, sourceKeyspace, targetKeyspace, "list1", tables[0], createFlags1, nil, nil)
defer mt1.Cancel()
mt2 := createMoveTables(t, sourceKeyspace, targetKeyspace, "list2", tables[1], createFlags2, nil, nil)
defer mt2.Cancel()

workflowNames := workflowList(targetKeyspace)
require.Len(t, workflowNames, 2)
workflowList := getWorkflows(targetKeyspace)
require.Len(t, workflowList.Workflows, 2)
}

func getMoveTablesShowResponse(mt *iMoveTables) *vtctldatapb.GetWorkflowsResponse {
moveTablesOutput := (*mt).GetLastOutput()
var moveTablesResponse vtctldatapb.GetWorkflowsResponse
Expand Down Expand Up @@ -201,6 +180,24 @@ func testMoveTablesFlags3(t *testing.T, sourceKeyspace, targetKeyspace string, t
require.False(t, checkTablesExist(t, "zone1-100", []string{"customer2"}))
}

// Create two workflows in order to confirm that listing all workflows works.
func testWorkflowList(t *testing.T, sourceKeyspace, targetKeyspace, workflowName string, targetTabs map[string]*cluster.VttabletProcess) {
createFlags := []string{"--auto-start=false", "--tablet-types",
"primary,rdonly", "--tablet-types-in-preference-order=true", "--all-cells",
}
wfNames := []string{"list1", "list2"}
tables := []string{"customer", "customer2"}
for i := range wfNames {
mt := createMoveTables(t, sourceKeyspace, targetKeyspace, wfNames[i], tables[i], createFlags, nil, nil)
defer mt.Cancel()
}

workflowNames := workflowList(targetKeyspace)
require.Len(t, workflowNames, len(wfNames))
workflows := getWorkflows(targetKeyspace)
require.Len(t, workflows.Workflows, len(wfNames))
}

func createMoveTables(t *testing.T, sourceKeyspace, targetKeyspace, workflowName, tables string,
createFlags, completeFlags, switchFlags []string) iMoveTables {
mt := newMoveTables(vc, &moveTablesWorkflow{
Expand Down Expand Up @@ -349,13 +346,12 @@ func getWorkflow(targetKeyspace, workflow string) *vtctldatapb.GetWorkflowsRespo
}

func getWorkflows(targetKeyspace string) *vtctldatapb.GetWorkflowsResponse {
//workflowsOutput, err := vc.VtctldClient.ExecuteCommandWithOutput("GetWorkflows", targetKeyspace, "--compact", "--include-logs=false")
workflowsOutput, err := vc.VtctldClient.ExecuteCommandWithOutput("GetWorkflows", targetKeyspace, "--show-all", "--compact", "--include-logs=false")
getWorkflowsOutput, err := vc.VtctldClient.ExecuteCommandWithOutput("GetWorkflows", targetKeyspace, "--show-all", "--compact", "--include-logs=false")
require.NoError(vc.t, err)
var workflowsResponse vtctldatapb.GetWorkflowsResponse
err = protojson.Unmarshal([]byte(workflowsOutput), &workflowsResponse)
var getWorkflowsResponse vtctldatapb.GetWorkflowsResponse
err = protojson.Unmarshal([]byte(getWorkflowsOutput), &getWorkflowsResponse)
require.NoError(vc.t, err)
return workflowsResponse.CloneVT()
return getWorkflowsResponse.CloneVT()
}

func workflowList(targetKeyspace string) []string {
Expand Down

0 comments on commit 2f3eaea

Please sign in to comment.