Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: content range order during upload #304

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 10 additions & 20 deletions fileuploader/large_file_upload_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"os"
"strconv"
"strings"
"sync"
"time"
)

Expand Down Expand Up @@ -57,28 +56,19 @@ func (l *largeFileUploadTask[T]) Upload(progress ProgressCallBack) UploadResult[
var itemResponse T
var location *string

var wg sync.WaitGroup
wg.Add(len(slices))

for _, slice := range slices {
uploadSlice := slice
go func() {
defer wg.Done()
response, uploadLocation, err := l.uploadWithRetry(uploadSlice, maxRetriesPerRequest)
if err != nil {
responseErrors = append(responseErrors, err)
} else {
progress(uploadSlice.RangeEnd, uploadSlice.TotalSessionLength)
}
if response != nil {
itemResponse = response.(T)
}
location = uploadLocation
}()
response, uploadLocation, err := l.uploadWithRetry(slice, maxRetriesPerRequest)
if err != nil {
responseErrors = append(responseErrors, err)
} else {
progress(slice.RangeEnd, slice.TotalSessionLength)
}
if response != nil {
itemResponse = response.(T)
}
location = uploadLocation
}

wg.Wait()

if len(responseErrors) > 0 {
result.SetUploadSucceeded(false)
result.SetResponseErrors(responseErrors)
Expand Down
5 changes: 5 additions & 0 deletions fileuploader/large_file_upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,13 @@ func TestLargeFileUploadTask(t *testing.T) {
// verify that the object was created correctly
// verify the number of sub upload tasks
progressCall := 0
var previousValue int64 = 0
progress := func(progress int64, total int64) {
progressCall++
if previousValue > progress {
assert.Fail(t, "progress should not decrease")
}
previousValue = progress
}
result := uploader.Upload(progress)

Expand Down