Skip to content

Commit

Permalink
fix: content range order during upload (#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev authored Jul 10, 2024
1 parent a9931ff commit f241e94
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
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

0 comments on commit f241e94

Please sign in to comment.