@@ -154,22 +154,24 @@ func TestSSH(t *testing.T) {
154
154
// a start build of the workspace.
155
155
isFirstBuild := true
156
156
buildURL := regexp .MustCompile ("/api/v2/workspaces/.*/builds" )
157
- buildPause := make (chan struct {} )
157
+ buildPause := make (chan bool )
158
158
buildDone := make (chan struct {})
159
- buildReturnSync := make (chan struct {})
160
159
buildSyncMW := func (next http.Handler ) http.Handler {
161
160
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
162
161
if r .Method == http .MethodPost && buildURL .MatchString (r .URL .Path ) {
163
162
if ! isFirstBuild {
164
163
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
+ }
166
170
t .Log ("buildSyncMW: resuming build" )
167
171
defer func () {
168
172
t .Log ("buildSyncMW: sending build done" )
169
173
buildDone <- struct {}{}
170
- t .Log ("buildSyncMW: waiting for return sync" )
171
- <- buildReturnSync
172
- t .Log ("buildSyncMW: returning" )
174
+ t .Log ("buildSyncMW: done" )
173
175
}()
174
176
} else {
175
177
isFirstBuild = false
@@ -220,18 +222,13 @@ func TestSSH(t *testing.T) {
220
222
}
221
223
222
224
// Allow one build to complete.
223
- testutil .RequireSendCtx (ctx , t , buildPause , struct {}{} )
225
+ testutil .RequireSendCtx (ctx , t , buildPause , true )
224
226
testutil .RequireRecvCtx (ctx , t , buildDone )
225
227
226
228
// Allow the remaining builds to continue.
227
229
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 )
232
231
}
233
- // Allow all three endpoints to return.
234
- close (buildReturnSync )
235
232
236
233
var foundConflict int
237
234
for _ , pty := range ptys {
0 commit comments