Skip to content

Commit 92c651b

Browse files
committed
remove build race by faking conflict @ api
1 parent 979951e commit 92c651b

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

cli/ssh_test.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -154,22 +154,24 @@ func TestSSH(t *testing.T) {
154154
// a start build of the workspace.
155155
isFirstBuild := true
156156
buildURL := regexp.MustCompile("/api/v2/workspaces/.*/builds")
157-
buildPause := make(chan struct{})
157+
buildPause := make(chan bool)
158158
buildDone := make(chan struct{})
159-
buildReturnSync := make(chan struct{})
160159
buildSyncMW := func(next http.Handler) http.Handler {
161160
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
162161
if r.Method == http.MethodPost && buildURL.MatchString(r.URL.Path) {
163162
if !isFirstBuild {
164163
t.Log("buildSyncMW: pausing build")
165-
<-buildPause
164+
if shouldContinue := <-buildPause; !shouldContinue {
165+
// We can't force the API to trigger a build conflict (racy) so we fake it.
166+
t.Log("buildSyncMW: return conflict")
167+
w.WriteHeader(http.StatusConflict)
168+
return
169+
}
166170
t.Log("buildSyncMW: resuming build")
167171
defer func() {
168172
t.Log("buildSyncMW: sending build done")
169173
buildDone <- struct{}{}
170-
t.Log("buildSyncMW: waiting for return sync")
171-
<-buildReturnSync
172-
t.Log("buildSyncMW: returning")
174+
t.Log("buildSyncMW: done")
173175
}()
174176
} else {
175177
isFirstBuild = false
@@ -220,18 +222,13 @@ func TestSSH(t *testing.T) {
220222
}
221223

222224
// Allow one build to complete.
223-
testutil.RequireSendCtx(ctx, t, buildPause, struct{}{})
225+
testutil.RequireSendCtx(ctx, t, buildPause, true)
224226
testutil.RequireRecvCtx(ctx, t, buildDone)
225227

226228
// Allow the remaining builds to continue.
227229
for i := 0; i < len(ptys)-1; i++ {
228-
testutil.RequireSendCtx(ctx, t, buildPause, struct{}{})
229-
}
230-
for i := 0; i < len(ptys)-1; i++ {
231-
testutil.RequireRecvCtx(ctx, t, buildDone)
230+
testutil.RequireSendCtx(ctx, t, buildPause, false)
232231
}
233-
// Allow all three endpoints to return.
234-
close(buildReturnSync)
235232

236233
var foundConflict int
237234
for _, pty := range ptys {

0 commit comments

Comments
 (0)