mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-09-30 11:46:16 +00:00
Fix hook timeout review feedback
Signed-off-by: chlins <chlins.zhang@gmail.com>
This commit is contained in:
@@ -177,6 +177,15 @@ func TestExecutePodCommand(t *testing.T) {
|
||||
hookError: errors.New("hook error"),
|
||||
expectedError: "hook error",
|
||||
},
|
||||
{
|
||||
name: "stream deadline exceeded before local timeout",
|
||||
command: []string{"some", "command"},
|
||||
expectedContainerName: "foo",
|
||||
expectedErrorMode: v1.HookErrorModeFail,
|
||||
expectedTimeout: defaultTimeout,
|
||||
hookError: context.DeadlineExceeded,
|
||||
expectedError: context.DeadlineExceeded.Error(),
|
||||
},
|
||||
{
|
||||
// Timeouts from pod annotations go through time.ParseDuration, which accepts
|
||||
// negative values. Without clamping, the hook would run with no timeout at all.
|
||||
@@ -264,6 +273,54 @@ func TestExecutePodCommand(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeExecHookError(t *testing.T) {
|
||||
hookErr := errors.New("hook error")
|
||||
tests := []struct {
|
||||
name string
|
||||
streamErr error
|
||||
contextErr error
|
||||
expectedError string
|
||||
preserveStreamErr bool
|
||||
}{
|
||||
{
|
||||
name: "local context deadline exceeded",
|
||||
streamErr: context.DeadlineExceeded,
|
||||
contextErr: context.DeadlineExceeded,
|
||||
expectedError: "timed out after 30s",
|
||||
},
|
||||
{
|
||||
name: "stream deadline exceeded before local timeout",
|
||||
streamErr: context.DeadlineExceeded,
|
||||
expectedError: context.DeadlineExceeded.Error(),
|
||||
preserveStreamErr: true,
|
||||
},
|
||||
{
|
||||
name: "ordinary hook error",
|
||||
streamErr: hookErr,
|
||||
expectedError: hookErr.Error(),
|
||||
preserveStreamErr: true,
|
||||
},
|
||||
{
|
||||
name: "no errors",
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
err := normalizeExecHookError(test.streamErr, test.contextErr, defaultTimeout)
|
||||
if test.expectedError == "" {
|
||||
require.NoError(t, err)
|
||||
return
|
||||
}
|
||||
|
||||
require.EqualError(t, err, test.expectedError)
|
||||
if test.preserveStreamErr && err != test.streamErr {
|
||||
t.Fatalf("expected stream error to be returned unchanged")
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnsureContainerExists(t *testing.T) {
|
||||
pod := &corev1api.Pod{
|
||||
Spec: corev1api.PodSpec{
|
||||
|
||||
Reference in New Issue
Block a user