Skip to content

Commit 3954f5b

Browse files
committed
improve synchro
1 parent d3d0410 commit 3954f5b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

cli/ssh_test.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,19 @@ func TestSSH(t *testing.T) {
155155
isFirstBuild := true
156156
buildURL := regexp.MustCompile("/api/v2/workspaces/.*/builds")
157157
buildSync := make(chan struct{})
158+
buildDone := make(chan struct{})
158159
buildResume := make(chan struct{})
159160
buildSyncMW := func(next http.Handler) http.Handler {
160161
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
161162
if r.Method == http.MethodPost && buildURL.MatchString(r.URL.Path) {
162163
if !isFirstBuild {
164+
t.Log("buildSyncMW: blocking post-build")
165+
<-buildSync
163166
defer func() {
164-
t.Log("buildSyncMW: blocking post-build")
165-
buildSync <- struct{}{}
167+
buildDone <- struct{}{}
166168
<-buildResume
167-
t.Log("buildSyncMW: resuming...")
168169
}()
170+
t.Log("buildSyncMW: resuming...")
169171
} else {
170172
isFirstBuild = false
171173
}
@@ -213,9 +215,19 @@ func TestSSH(t *testing.T) {
213215
for _, pty := range ptys {
214216
pty.ExpectMatchContext(ctx, "Workspace was stopped, starting workspace to allow connecting to")
215217
}
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)
218229
}
230+
// Allow all three endpoints to return.
219231
close(buildResume)
220232

221233
var foundConflict int

0 commit comments

Comments
 (0)