Skip to content

Commit

Permalink
Make invalid intervals fail
Browse files Browse the repository at this point in the history
Update tests to reflect interval validation
  • Loading branch information
davemay99 committed Mar 8, 2021
1 parent f6e8b73 commit 0f0e9a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
7 changes: 3 additions & 4 deletions command/operator_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,10 @@ func (c *OperatorDebugCommand) Run(args []string) int {
}
c.interval = i

// Sanity check interval
// Validate interval
if i.Seconds() > d.Seconds() {
c.Ui.Info(fmt.Sprintf("Interval %s is greater than duration %s, resetting to %s.", interval, duration, duration))
interval = duration // Update string for summary
c.interval = c.duration // Update parsed interval
c.Ui.Error(fmt.Sprintf("Error parsing interval: %s is greater than duration %s", interval, duration))
return 1
}

// Parse the pprof capture duration
Expand Down
27 changes: 16 additions & 11 deletions command/operator_debug_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestDebug_NodeClass(t *testing.T) {
cases := testCases{
{
name: "address=api, node-class=clienta, max-nodes=2",
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clienta", "-max-nodes", "2"},
args: []string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clienta", "-max-nodes", "2"},
expectedCode: 0,
expectedOutputs: []string{
"Servers: (1/1)",
Expand All @@ -132,7 +132,7 @@ func TestDebug_NodeClass(t *testing.T) {
},
{
name: "address=api, node-class=clientb, max-nodes=2",
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clientb", "-max-nodes", "2"},
args: []string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "all", "-node-id", "all", "-node-class", "clientb", "-max-nodes", "2"},
expectedCode: 0,
expectedOutputs: []string{
"Servers: (1/1)",
Expand Down Expand Up @@ -189,19 +189,19 @@ func TestDebug_ClientToServer(t *testing.T) {
var cases = testCases{
{
name: "testAgent api server",
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all", "-node-id", "all"},
args: []string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "all", "-node-id", "all"},
expectedCode: 0,
expectedOutputs: []string{"Created debug archive"},
},
{
name: "server address",
args: []string{"-address", addrServer, "-duration", "250ms", "-server-id", "all", "-node-id", "all"},
args: []string{"-address", addrServer, "-duration", "250ms", "-interval", "250ms", "-server-id", "all", "-node-id", "all"},
expectedCode: 0,
expectedOutputs: []string{"Created debug archive"},
},
{
name: "client1 address - verify no SIGSEGV panic",
args: []string{"-address", addrClient1, "-duration", "250ms", "-server-id", "all", "-node-id", "all"},
args: []string{"-address", addrClient1, "-duration", "250ms", "-interval", "250ms", "-server-id", "all", "-node-id", "all"},
expectedCode: 0,
expectedOutputs: []string{"Created debug archive"},
},
Expand All @@ -218,7 +218,7 @@ func TestDebug_SingleServer(t *testing.T) {
var cases = testCases{
{
name: "address=api, server-id=leader",
args: []string{"-address", url, "-duration", "250ms", "-server-id", "leader"},
args: []string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "leader"},
expectedCode: 0,
expectedOutputs: []string{
"Servers: (1/1)",
Expand All @@ -229,7 +229,7 @@ func TestDebug_SingleServer(t *testing.T) {
},
{
name: "address=api, server-id=all",
args: []string{"-address", url, "-duration", "250ms", "-server-id", "all"},
args: []string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "all"},
expectedCode: 0,
expectedOutputs: []string{
"Servers: (1/1)",
Expand Down Expand Up @@ -261,7 +261,7 @@ func TestDebug_Failures(t *testing.T) {
},
{
name: "Fails missing node ids",
args: []string{"-node-id", "abc,def", "-duration", "250ms"},
args: []string{"-node-id", "abc,def", "-duration", "250ms", "-interval", "250ms"},
expectedCode: 1,
},
{
Expand All @@ -274,6 +274,11 @@ func TestDebug_Failures(t *testing.T) {
args: []string{"-interval", "bar"},
expectedCode: 1,
},
{
name: "Fails intervals greater than duration",
args: []string{"-duration", "5m", "-interval", "10m"},
expectedCode: 1,
},
{
name: "Fails bad address",
args: []string{"-address", url + "bogus"},
Expand Down Expand Up @@ -307,7 +312,7 @@ func TestDebug_Bad_CSIPlugin_Names(t *testing.T) {
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}

// Debug on the leader and all client nodes
code := cmd.Run([]string{"-address", url, "-duration", "250ms", "-server-id", "leader", "-node-id", "all", "-output", os.TempDir()})
code := cmd.Run([]string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "leader", "-node-id", "all", "-output", os.TempDir()})
assert.Equal(t, 0, code)

// Bad plugin name should be escaped before it reaches the sandbox test
Expand Down Expand Up @@ -391,7 +396,7 @@ func TestDebug_ExistingOutput(t *testing.T) {
os.MkdirAll(path, 0755)
defer os.Remove(path)

code := cmd.Run([]string{"-output", os.TempDir(), "-duration", "50ms"})
code := cmd.Run([]string{"-output", os.TempDir(), "-duration", "50ms", "-interval", "50ms"})
require.Equal(t, 2, code)
}

Expand All @@ -413,7 +418,7 @@ func TestDebug_Fail_Pprof(t *testing.T) {
cmd := &OperatorDebugCommand{Meta: Meta{Ui: ui}}

// Debug on client - node class = "clienta"
code := cmd.Run([]string{"-address", url, "-duration", "250ms", "-server-id", "all"})
code := cmd.Run([]string{"-address", url, "-duration", "250ms", "-interval", "250ms", "-server-id", "all"})

assert.Equal(t, 0, code) // Pprof failure isn't fatal
require.Contains(t, ui.OutputWriter.String(), "Starting debugger")
Expand Down

0 comments on commit 0f0e9a0

Please sign in to comment.