Skip to content

Commit fb1adfa

Browse files
committed
fix race in windows test
1 parent c7c1698 commit fb1adfa

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

internal/batches/service/remote_windows_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,15 @@ func TestService_UploadBatchSpecWorkspaceFiles_Windows_Path(t *testing.T) {
4444
svc := service.New(&service.Opts{Client: client})
4545

4646
// Body will get set with the body argument to NewHTTPRequest
47+
// We must consume the pipe reader synchronously to avoid a data race between
48+
// the goroutine writing to the pipe and testify/mock inspecting arguments via reflection.
49+
var bodyContent bytes.Buffer
4750
req := httptest.NewRequest(http.MethodPost, "http://fake.com/.api/files/batch-changes/123", nil)
4851
client.On("NewHTTPRequest", mock.Anything, http.MethodPost, ".api/files/batch-changes/123", mock.Anything).
4952
Run(func(args mock.Arguments) {
50-
req.Body = args[3].(*io.PipeReader)
53+
pipeReader := args[3].(*io.PipeReader)
54+
io.Copy(&bodyContent, pipeReader)
55+
req.Body = io.NopCloser(&bodyContent)
5156
}).
5257
Return(req, nil).
5358
Once()

0 commit comments

Comments
 (0)