Skip to content

Commit 4289488

Browse files
Minor changes
1 parent 8ba4cf5 commit 4289488

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

pkg/workflows/artifacts/upload.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,15 @@ func (a *Artifacts) upload(uploadInput *UploadInput) error {
148148
return nil
149149
}
150150

151+
var backOffSleep time.Duration = 1 * time.Second
152+
151153
// DurableUpload uploads an artifact with up to 3 attempts and exponential backoff.
152154
func (a *Artifacts) DurableUpload(uploadInput *UploadInput) error {
153155
var lastErr error
154156
const maxUploadAttempts = 3
155-
for attempt := 0; attempt < maxUploadAttempts; attempt++ {
157+
for attempt := range maxUploadAttempts {
156158
if attempt > 0 {
157-
backoff := time.Duration(1<<(attempt)) * time.Second
159+
backoff := backOffSleep * time.Duration(1<<(attempt-1))
158160
a.log.Debug("Retrying upload after backoff", "attempt", attempt+1, "backoff", backoff)
159161
time.Sleep(backoff)
160162
}

pkg/workflows/artifacts/upload_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,33 @@ func (s *UploadTestSuite) TestUpload() {
8181
// If the binary is smaller than 100 bytes, compare the whole thing
8282
s.Equal(expected, actual, "binary data do not match")
8383
}
84+
85+
// SadPath: Bad filepath
86+
backOffSleep = 1 * time.Millisecond
87+
badFilepathUploadInput := &UploadInput{
88+
PresignedURL: fmt.Sprintf("http://localhost:%s/artifacts/%s/binary.wasm", testServerPort, artifacts.GetWorkflowID()),
89+
PresignedFields: []Field{
90+
{Key: "key1", Value: "value1"},
91+
},
92+
Filepath: "testdata/binary",
93+
Timeout: 10 * time.Second,
94+
}
95+
err = artifacts.DurableUpload(badFilepathUploadInput)
96+
s.ErrorContains(err, "upload failed after 3 attempts: failed to read file: open",
97+
"failed to upload artifact")
98+
99+
// SadPath: Bad presigned URL
100+
badPresignedURLUploadInput := &UploadInput{
101+
PresignedURL: fmt.Sprintf("http://localhost:%s/artifacts2/%s/binary.wasm", testServerPort, artifacts.GetWorkflowID()),
102+
PresignedFields: []Field{
103+
{Key: "key1", Value: "value1"},
104+
},
105+
Filepath: artifacts.GetBinaryPath(),
106+
Timeout: 10 * time.Second,
107+
}
108+
err = artifacts.DurableUpload(badPresignedURLUploadInput)
109+
s.ErrorContains(err, "upload failed after 3 attempts: expected status 204 or 201, got 404",
110+
"failed to upload artifact")
84111
}
85112

86113
func TestUploadTestSuite(t *testing.T) {

0 commit comments

Comments
 (0)