@@ -155,17 +155,19 @@ func TestSSH(t *testing.T) {
155
155
isFirstBuild := true
156
156
buildURL := regexp .MustCompile ("/api/v2/workspaces/.*/builds" )
157
157
buildSync := make (chan struct {})
158
+ buildDone := make (chan struct {})
158
159
buildResume := 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: blocking post-build" )
165
+ <- buildSync
163
166
defer func () {
164
- t .Log ("buildSyncMW: blocking post-build" )
165
- buildSync <- struct {}{}
167
+ buildDone <- struct {}{}
166
168
<- buildResume
167
- t .Log ("buildSyncMW: resuming..." )
168
169
}()
170
+ t .Log ("buildSyncMW: resuming..." )
169
171
} else {
170
172
isFirstBuild = false
171
173
}
@@ -213,9 +215,19 @@ func TestSSH(t *testing.T) {
213
215
for _ , pty := range ptys {
214
216
pty .ExpectMatchContext (ctx , "Workspace was stopped, starting workspace to allow connecting to" )
215
217
}
216
- for range ptys {
217
- testutil .RequireRecvCtx (ctx , t , buildSync )
218
+
219
+ // Allow one build to complete.
220
+ testutil .RequireSendCtx (ctx , t , buildSync , struct {}{})
221
+ testutil .RequireRecvCtx (ctx , t , buildDone )
222
+
223
+ // Allow the remaining builds to continue.
224
+ for i := 0 ; i < len (ptys )- 1 ; i ++ {
225
+ testutil .RequireSendCtx (ctx , t , buildSync , struct {}{})
226
+ }
227
+ for i := 0 ; i < len (ptys )- 1 ; i ++ {
228
+ testutil .RequireRecvCtx (ctx , t , buildDone )
218
229
}
230
+ // Allow all three endpoints to return.
219
231
close (buildResume )
220
232
221
233
var foundConflict int
0 commit comments