-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
client: artifact errors are retry-able
0.9.0beta2 contains a regression where artifact download errors would not cause a task restart and instead immediately fail the task. This restores the pre-0.9 behavior of retrying all artifact errors and adds missing tests.
- Loading branch information
1 parent
38da167
commit 27c03c8
Showing
6 changed files
with
164 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package taskrunner | ||
|
||
import ( | ||
"context" | ||
"os" | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/client/allocdir" | ||
"github.com/hashicorp/nomad/client/allocrunner/interfaces" | ||
"github.com/hashicorp/nomad/client/taskenv" | ||
"github.com/hashicorp/nomad/helper/testlog" | ||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Statically assert the artifact hook implements the expected interface | ||
var _ interfaces.TaskPrestartHook = (*artifactHook)(nil) | ||
|
||
type mockEmitter struct { | ||
events []*structs.TaskEvent | ||
} | ||
|
||
func (m *mockEmitter) EmitEvent(ev *structs.TaskEvent) { | ||
m.events = append(m.events, ev) | ||
} | ||
|
||
// TestTaskRunner_ArtifactHook_Recoverable asserts that failures to download | ||
// artifacts are a recoverable error. | ||
func TestTaskRunner_ArtifactHook_Recoverable(t *testing.T) { | ||
t.Parallel() | ||
|
||
me := &mockEmitter{} | ||
artifactHook := newArtifactHook(me, testlog.HCLogger(t)) | ||
|
||
req := &interfaces.TaskPrestartRequest{ | ||
TaskEnv: taskenv.NewEmptyTaskEnv(), | ||
TaskDir: &allocdir.TaskDir{Dir: os.TempDir()}, | ||
Task: &structs.Task{ | ||
Artifacts: []*structs.TaskArtifact{ | ||
{ | ||
GetterSource: "http://127.0.0.1:0", | ||
GetterMode: structs.GetterModeAny, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
resp := interfaces.TaskPrestartResponse{} | ||
|
||
err := artifactHook.Prestart(context.Background(), req, &resp) | ||
|
||
require.False(t, resp.Done) | ||
require.NotNil(t, err) | ||
require.True(t, structs.IsRecoverable(err)) | ||
require.Len(t, me.events, 1) | ||
require.Equal(t, structs.TaskDownloadingArtifacts, me.events[0].Type) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package taskrunner | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/hashicorp/nomad/nomad/structs" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// Statically assert error implements the expected interfaces | ||
var _ structs.Recoverable = (*hookError)(nil) | ||
|
||
// TestHookError_Recoverable asserts that a NewHookError is recoverable if | ||
// passed a recoverable error. | ||
func TestHookError_Recoverable(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create root error | ||
root := errors.New("test error") | ||
|
||
// Make it recoverable | ||
recov := structs.NewRecoverableError(root, true) | ||
|
||
// Create a fake task event | ||
ev := structs.NewTaskEvent("test event") | ||
|
||
herr := NewHookError(recov, ev) | ||
|
||
require.Equal(t, ev, herr.(*hookError).taskEvent) | ||
require.True(t, structs.IsRecoverable(herr)) | ||
require.Equal(t, root.Error(), herr.Error()) | ||
require.Equal(t, recov.Error(), herr.Error()) | ||
} | ||
|
||
// TestHookError_Unrecoverable asserts that a NewHookError is not recoverable | ||
// unless it is passed a recoverable error. | ||
func TestHookError_Unrecoverable(t *testing.T) { | ||
t.Parallel() | ||
|
||
// Create error | ||
err := errors.New("test error") | ||
|
||
// Create a fake task event | ||
ev := structs.NewTaskEvent("test event") | ||
|
||
herr := NewHookError(err, ev) | ||
|
||
require.Equal(t, ev, herr.(*hookError).taskEvent) | ||
require.False(t, structs.IsRecoverable(herr)) | ||
require.Equal(t, err.Error(), herr.Error()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters