@@ -154,16 +154,25 @@ 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
- buildReq := make (chan struct {} )
158
- buildResume := make (chan struct {})
157
+ buildPause := make (chan bool )
158
+ buildDone := make (chan struct {})
159
159
buildSyncMW := func (next http.Handler ) http.Handler {
160
160
return http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
161
161
if r .Method == http .MethodPost && buildURL .MatchString (r .URL .Path ) {
162
162
if ! isFirstBuild {
163
- t .Log ("buildSyncMW: blocking build" )
164
- buildReq <- struct {}{}
165
- <- buildResume
163
+ t .Log ("buildSyncMW: pausing build" )
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" )
171
+ defer func () {
172
+ t .Log ("buildSyncMW: sending build done" )
173
+ buildDone <- struct {}{}
174
+ t .Log ("buildSyncMW: done" )
175
+ }()
167
176
} else {
168
177
isFirstBuild = false
169
178
}
@@ -211,10 +220,15 @@ func TestSSH(t *testing.T) {
211
220
for _ , pty := range ptys {
212
221
pty .ExpectMatchContext (ctx , "Workspace was stopped, starting workspace to allow connecting to" )
213
222
}
214
- for range ptys {
215
- testutil .RequireRecvCtx (ctx , t , buildReq )
223
+
224
+ // Allow one build to complete.
225
+ testutil .RequireSendCtx (ctx , t , buildPause , true )
226
+ testutil .RequireRecvCtx (ctx , t , buildDone )
227
+
228
+ // Allow the remaining builds to continue.
229
+ for i := 0 ; i < len (ptys )- 1 ; i ++ {
230
+ testutil .RequireSendCtx (ctx , t , buildPause , false )
216
231
}
217
- close (buildResume )
218
232
219
233
var foundConflict int
220
234
for _ , pty := range ptys {
0 commit comments