Skip to content

Commit

Permalink
provider/mediaconvert: use atomic.StorePointer (hack) to workaround race
Browse files Browse the repository at this point in the history
This allows us to enable the race detector.
  • Loading branch information
fsouza committed Jul 26, 2019
1 parent c65a71d commit 630e1a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions provider/mediaconvert/fake_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package mediaconvert

import (
"net/http"
"sync/atomic"
"testing"
"unsafe"

"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/service/mediaconvert"
Expand All @@ -14,7 +16,7 @@ type testMediaConvertClient struct {
t *testing.T

createPresetCalledWith *mediaconvert.CreatePresetInput
getPresetCalledWith string
getPresetCalledWith *string
deletePresetCalledWith string
createJobCalledWith mediaconvert.CreateJobInput
cancelJobCalledWith string
Expand Down Expand Up @@ -78,7 +80,10 @@ func (c *testMediaConvertClient) CancelJobRequest(input *mediaconvert.CancelJobI
}

func (c *testMediaConvertClient) GetPresetRequest(input *mediaconvert.GetPresetInput) mediaconvert.GetPresetRequest {
c.getPresetCalledWith = *input.Name
// atomically set the value of getPresetCalledWith to avoid data races,
// should probably take a different approach?
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&c.getPresetCalledWith)), unsafe.Pointer(input.Name))

return mediaconvert.GetPresetRequest{
Request: &aws.Request{HTTPRequest: &http.Request{}, Data: &mediaconvert.GetPresetOutput{
Preset: &mediaconvert.Preset{
Expand Down
2 changes: 1 addition & 1 deletion provider/mediaconvert/mediaconvert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func Test_mcProvider_GetPreset(t *testing.T) {
t.Fatalf("expected GetPreset() not to return an error, got: %v", err)
}

if g, e := client.getPresetCalledWith, presetID; g != e {
if g, e := *client.getPresetCalledWith, presetID; g != e {
t.Fatalf("got %q, expected %q", g, e)
}
}
Expand Down

0 comments on commit 630e1a1

Please sign in to comment.