@@ -154,17 +154,22 @@ 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
- buildSync := make (chan struct {})
158
- buildResume := make (chan struct {})
157
+ buildPause := make (chan struct {})
158
+ buildDone := make (chan struct {})
159
+ buildReturnSync := make (chan struct {})
159
160
buildSyncMW := func (next http.Handler ) http.Handler {
160
161
return http .HandlerFunc (func (w http.ResponseWriter ,r * http.Request ) {
161
162
if r .Method == http .MethodPost && buildURL .MatchString (r .URL .Path ) {
162
163
if ! isFirstBuild {
164
+ t .Log ("buildSyncMW: pausing build" )
165
+ <- buildPause
166
+ t .Log ("buildSyncMW: resuming build" )
163
167
defer func () {
164
- t .Log ("buildSyncMW: blocking post-build" )
165
- buildSync <- struct {}{}
166
- <- buildResume
167
- t .Log ("buildSyncMW: resuming..." )
168
+ t .Log ("buildSyncMW: sending build done" )
169
+ buildDone <- struct {}{}
170
+ t .Log ("buildSyncMW: waiting for return sync" )
171
+ <- buildReturnSync
172
+ t .Log ("buildSyncMW: returning" )
168
173
}()
169
174
}else {
170
175
isFirstBuild = false
@@ -213,10 +218,20 @@ func TestSSH(t *testing.T) {
213
218
for _ ,pty := range ptys {
214
219
pty .ExpectMatchContext (ctx ,"Workspace was stopped, starting workspace to allow connecting to" )
215
220
}
216
- for range ptys {
217
- testutil .RequireRecvCtx (ctx ,t ,buildSync )
221
+
222
+ // Allow one build to complete.
223
+ testutil .RequireSendCtx (ctx ,t ,buildPause ,struct {}{})
224
+ testutil .RequireRecvCtx (ctx ,t ,buildDone )
225
+
226
+ // Allow the remaining builds to continue.
227
+ 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 )
218
232
}
219
- close (buildResume )
233
+ // Allow all three endpoints to return.
234
+ close (buildReturnSync )
220
235
221
236
var foundConflict int
222
237
for _ ,pty := range ptys {