Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

debug: Fix node count bug from GH-9566 #9625

Merged
merged 3 commits into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The order of these outputs don't seem to reflect the order they're emitted? The test doesn't assert an order either, but do we care about that at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I rearranged the outputs to match the order they are written to the screen, but that was just for clarity and consistency. The order really doesn't matter.

},
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