Skip to content

Commit c8ce604

Browse files
wpjuniorclaude
andcommitted
Fix data race in TestBuildRequestBodyWithProgressWithArchive
Use safe.Buffer instead of bytes.Buffer for stdout and cancel the context before reading, ensuring the progress goroutine has stopped writing before assertions run. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 649d574 commit c8ce604

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tsuru/client/build_test.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,17 @@ func (s *S) TestBuildRequestBodyWithProgressWithArchive(c *check.C) {
149149
buf := safe.NewBuffer(nil)
150150
request, _ := http.NewRequest("POST", "/apps/myapp/build", body)
151151
values := url.Values{"tag": []string{"mytag"}}
152-
var stdout bytes.Buffer
152+
stdout := safe.NewBuffer(nil)
153153
archive := bytes.NewBufferString("fake-archive-content")
154154

155-
err := buildRequestBodyWithProgress(context.Background(), &stdout, request, buf, body, values, archive)
155+
ctx, cancel := context.WithCancel(context.Background())
156+
err := buildRequestBodyWithProgress(ctx, stdout, request, buf, body, values, archive)
156157
c.Assert(err, check.IsNil)
158+
159+
// stop the progress goroutine before reading stdout
160+
cancel()
161+
time.Sleep(100 * time.Millisecond)
162+
157163
c.Assert(request.Header.Get("Content-Type"), check.Matches, "multipart/form-data; boundary=.*")
158164
c.Assert(body.Len() > 0, check.Equals, true)
159165
c.Assert(stdout.String(), check.Matches, `Uploading files \(\d+\.\d+MB\)\.\.\. .*`)

0 commit comments

Comments
 (0)