Skip to content

Commit

Permalink
test: add retry on system error test
Browse files Browse the repository at this point in the history
Add a test to cover the retry on system error test.

Update test to use empty context to prevent knock on failures being
logged confusing the output and check the error returned.
  • Loading branch information
stevenh committed Aug 6, 2024
1 parent 8b42143 commit 8447275
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
17 changes: 15 additions & 2 deletions docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1973,7 +1973,6 @@ func terminateContainerOnEnd(tb testing.TB, ctx context.Context, ctr Container)
return
}
tb.Cleanup(func() {
tb.Log("terminating container")
require.NoError(tb, ctr.Terminate(ctx))
})
}
Expand Down Expand Up @@ -2141,6 +2140,11 @@ func TestDockerProvider_BuildImage_Retries(t *testing.T) {
errReturned: errdefs.NotImplemented(errors.New("unknown method")),
shouldRetry: false,
},
{
name: "no retry on system error",
errReturned: errdefs.System(errors.New("system error")),
shouldRetry: false,
},
{
name: "retry on non-permanent error",
errReturned: errors.New("whoops"),
Expand All @@ -2158,7 +2162,16 @@ func TestDockerProvider_BuildImage_Retries(t *testing.T) {
// give a chance to retry
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
_, _ = p.BuildImage(ctx, &ContainerRequest{})
_, err = p.BuildImage(ctx, &ContainerRequest{
FromDockerfile: FromDockerfile{
Context: filepath.Join(".", "testdata", "retry"),
},
})
if tt.errReturned != nil {
require.Error(t, err)
} else {
require.NoError(t, err)
}

assert.Positive(t, m.imageBuildCount)
assert.Equal(t, tt.shouldRetry, m.imageBuildCount > 1)
Expand Down
1 change: 1 addition & 0 deletions testdata/retry/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FROM scratch

0 comments on commit 8447275

Please sign in to comment.