From 5f50c1d0c10042048125c858a15671f0e8b07587 Mon Sep 17 00:00:00 2001 From: Dave May Date: Mon, 14 Dec 2020 15:02:48 -0500 Subject: [PATCH] debug: Fix node count bug from GH-9566 (#9625) * 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 --- command/operator_debug.go | 5 +++-- command/operator_debug_test.go | 26 ++++++++++++++------------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/command/operator_debug.go b/command/operator_debug.go index 8a3037004..5c4ea36a1 100644 --- a/command/operator_debug.go +++ b/command/operator_debug.go @@ -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 diff --git a/command/operator_debug_test.go b/command/operator_debug_test.go index 72c543cfc..8329ca305 100644 --- a/command/operator_debug_test.go +++ b/command/operator_debug_test.go @@ -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 @@ -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: "", }, @@ -176,9 +173,10 @@ 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: "", }, @@ -186,6 +184,10 @@ func TestDebug_NodeClass(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(c.args) out := ui.OutputWriter.String() @@ -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 @@ -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()