Skip to content

Commit

Permalink
vodtester: Resumable upload to same region under test
Browse files Browse the repository at this point in the history
  • Loading branch information
victorges committed Dec 3, 2022
1 parent a8b75f3 commit fe687bf
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion internal/app/vodtester/vodtester_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package vodtester
import (
"context"
"fmt"
"net/url"
"os"
"strings"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -189,7 +191,7 @@ func (vt *vodTester) resumableUploadTester(fileName string, taskPollDuration tim
return fmt.Errorf("error requesting upload for assetName=%s: %w", assetName, err)
}

tusUploadEndpoint := requestUpload.TusEndpoint
tusUploadEndpoint := patchURLHost(requestUpload.TusEndpoint, vt.lapi.GetServer())
uploadAsset := requestUpload.Asset
uploadTask := api.Task{
ID: requestUpload.Task.ID,
Expand Down Expand Up @@ -244,6 +246,29 @@ func (vt *vodTester) checkTaskProcessing(taskPollDuration time.Duration, process
}
}

// Patches the target URL with the source URL host, only if the latter is not
// contained in the first. Used for doing resumable uploads to the same region
// under test.
func patchURLHost(target, src string) string {
targetURL, err := url.Parse(target)
if err != nil {
return target
}
srcURL, err := url.Parse(src)
if err != nil {
return target
}

// Only patch the host if the target doesn't arleady contain the source host,
// which would mean we are using a global endpoint for the API as well (e.g.
// API server is livepeer.com and tus endpoint is origin.livepeer.com).
if !strings.Contains(targetURL.Host, srcURL.Host) {
targetURL.Scheme = srcURL.Scheme
targetURL.Host = srcURL.Host
}
return targetURL.String()
}

func (vt *vodTester) isCancelled() error {
select {
case <-vt.ctx.Done():
Expand Down

0 comments on commit fe687bf

Please sign in to comment.