Skip to content

Commit 979951e

Browse files
committed
improve synchro
1 parent d3d0410 commit 979951e

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

cli/ssh_test.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,22 @@ func TestSSH(t *testing.T) {
154154
// a start build of the workspace.
155155
isFirstBuild := true
156156
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{})
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: pausing build")
165+
<-buildPause
166+
t.Log("buildSyncMW: resuming build")
163167
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")
168173
}()
169174
} else {
170175
isFirstBuild = false
@@ -213,10 +218,20 @@ func TestSSH(t *testing.T) {
213218
for _, pty := range ptys {
214219
pty.ExpectMatchContext(ctx, "Workspace was stopped, starting workspace to allow connecting to")
215220
}
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)
218232
}
219-
close(buildResume)
233+
// Allow all three endpoints to return.
234+
close(buildReturnSync)
220235

221236
var foundConflict int
222237
for _, pty := range ptys {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy