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
This commit is contained in:
parent
6bfa3e93ce
commit
5f50c1d0c1
|
@ -328,13 +328,14 @@ func (c *OperatorDebugCommand) Run(args []string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment fail count if no nodes are found
|
// Increment fail count if no nodes are found
|
||||||
nodesFound = len(nodes)
|
if len(nodes) == 0 {
|
||||||
if nodesFound == 0 {
|
|
||||||
c.Ui.Error(fmt.Sprintf("No node(s) with prefix %q found", id))
|
c.Ui.Error(fmt.Sprintf("No node(s) with prefix %q found", id))
|
||||||
nodeLookupFailCount++
|
nodeLookupFailCount++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nodesFound += len(nodes)
|
||||||
|
|
||||||
// Apply constraints to nodes found
|
// Apply constraints to nodes found
|
||||||
for _, n := range nodes {
|
for _, n := range nodes {
|
||||||
// Ignore nodes that do not match specified class
|
// Ignore nodes that do not match specified class
|
||||||
|
|
|
@ -147,10 +147,6 @@ func TestDebug_NodeClass(t *testing.T) {
|
||||||
testutil.WaitForClient(t, srv.Agent.RPC, client3NodeID)
|
testutil.WaitForClient(t, srv.Agent.RPC, client3NodeID)
|
||||||
t.Logf("[TEST] Client3 ready, id: %s", 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
|
// Setup test cases struct
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
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"},
|
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clienta", "-max-nodes", "2"},
|
||||||
expectedCode: 0,
|
expectedCode: 0,
|
||||||
expectedOutputs: []string{
|
expectedOutputs: []string{
|
||||||
"Starting debugger",
|
"Servers: (1/1)",
|
||||||
"Created debug archive",
|
"Clients: (2/3)",
|
||||||
"Max node count reached (2)",
|
"Max node count reached (2)",
|
||||||
"Node Class: clienta",
|
"Node Class: clienta",
|
||||||
|
"Created debug archive",
|
||||||
},
|
},
|
||||||
expectedError: "",
|
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"},
|
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clientb", "-max-nodes", "2"},
|
||||||
expectedCode: 0,
|
expectedCode: 0,
|
||||||
expectedOutputs: []string{
|
expectedOutputs: []string{
|
||||||
"Starting debugger",
|
"Servers: (1/1)",
|
||||||
"Created debug archive",
|
"Clients: (1/3)",
|
||||||
"Node Class: clientb",
|
"Node Class: clientb",
|
||||||
|
"Created debug archive",
|
||||||
},
|
},
|
||||||
expectedError: "",
|
expectedError: "",
|
||||||
},
|
},
|
||||||
|
@ -186,6 +184,10 @@ func TestDebug_NodeClass(t *testing.T) {
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
// Setup mock UI
|
||||||
|
ui := cli.NewMockUi()
|
||||||
|
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}
|
||||||
|
|
||||||
// Run test case
|
// Run test case
|
||||||
code := cmd.Run(c.args)
|
code := cmd.Run(c.args)
|
||||||
out := ui.OutputWriter.String()
|
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] Server api address: %s", addrServer)
|
||||||
t.Logf("[TEST] Client1 api address: %s", addrClient1)
|
t.Logf("[TEST] Client1 api address: %s", addrClient1)
|
||||||
|
|
||||||
// Setup mock UI
|
|
||||||
ui := cli.NewMockUi()
|
|
||||||
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}
|
|
||||||
|
|
||||||
// Setup test cases struct
|
// Setup test cases struct
|
||||||
cases := []struct {
|
cases := []struct {
|
||||||
name string
|
name string
|
||||||
|
@ -298,6 +296,10 @@ func TestDebug_ClientToServer(t *testing.T) {
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
t.Run(c.name, func(t *testing.T) {
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
// Setup mock UI
|
||||||
|
ui := cli.NewMockUi()
|
||||||
|
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}
|
||||||
|
|
||||||
// Run test case
|
// Run test case
|
||||||
code := cmd.Run([]string{"-address", c.url, "-duration", "250ms", "-server-id", "all", "-node-id", "all"})
|
code := cmd.Run([]string{"-address", c.url, "-duration", "250ms", "-server-id", "all", "-node-id", "all"})
|
||||||
out := ui.OutputWriter.String()
|
out := ui.OutputWriter.String()
|
||||||
|
|
Loading…
Reference in New Issue