Skip to content

Commit

Permalink
debug: Fix node count bug from GH-9566 (#9625)
Browse files Browse the repository at this point in the history
* debug: update test to identify bug in GH-9566
* debug: range tests need fresh cmd each iteration
* debug: fix node count bug in GH-9566
  • Loading branch information
davemay99 committed Dec 14, 2020
1 parent fa4fb89 commit 8038641
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
5 changes: 3 additions & 2 deletions command/operator_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ func (c *OperatorDebugCommand) Run(args []string) int {
}

// Increment fail count if no nodes are found
nodesFound = len(nodes)
if nodesFound == 0 {
if len(nodes) == 0 {
c.Ui.Error(fmt.Sprintf("No node(s) with prefix %q found", id))
nodeLookupFailCount++
continue
}

nodesFound += len(nodes)

// Apply constraints to nodes found
for _, n := range nodes {
// Ignore nodes that do not match specified class
Expand Down
26 changes: 14 additions & 12 deletions command/operator_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,6 @@ func TestDebug_NodeClass(t *testing.T) {
testutil.WaitForClient(t, srv.Agent.RPC, client3NodeID)
t.Logf("[TEST] Client3 ready, id: %s", client3NodeID)

// Setup mock UI
ui := cli.NewMockUi()
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}

// Setup test cases struct
cases := []struct {
name string
Expand All @@ -164,10 +160,11 @@ func TestDebug_NodeClass(t *testing.T) {
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clienta", "-max-nodes", "2"},
expectedCode: 0,
expectedOutputs: []string{
"Starting debugger",
"Created debug archive",
"Servers: (1/1)",
"Clients: (2/3)",
"Max node count reached (2)",
"Node Class: clienta",
"Created debug archive",
},
expectedError: "",
},
Expand All @@ -176,16 +173,21 @@ func TestDebug_NodeClass(t *testing.T) {
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clientb", "-max-nodes", "2"},
expectedCode: 0,
expectedOutputs: []string{
"Starting debugger",
"Created debug archive",
"Servers: (1/1)",
"Clients: (1/3)",
"Node Class: clientb",
"Created debug archive",
},
expectedError: "",
},
}

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
// Setup mock UI
ui := cli.NewMockUi()
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}

// Run test case
code := cmd.Run(c.args)
out := ui.OutputWriter.String()
Expand Down Expand Up @@ -273,10 +275,6 @@ func TestDebug_ClientToServer(t *testing.T) {
t.Logf("[TEST] Server api address: %s", addrServer)
t.Logf("[TEST] Client1 api address: %s", addrClient1)

// Setup mock UI
ui := cli.NewMockUi()
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}

// Setup test cases struct
cases := []struct {
name string
Expand All @@ -298,6 +296,10 @@ func TestDebug_ClientToServer(t *testing.T) {

for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
// Setup mock UI
ui := cli.NewMockUi()
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}

// Run test case
code := cmd.Run([]string{"-address", c.url, "-duration", "250ms", "-server-id", "all", "-node-id", "all"})
out := ui.OutputWriter.String()
Expand Down

0 comments on commit 8038641

Please sign in to comment.