Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3d0410

Browse files
committed
test(cli/ssh): sync post-build to fix build race on slow runners
Fixes coder/internal#269
1 parent f4994ca commit d3d0410

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

cli/ssh_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,18 @@ func TestSSH(t *testing.T) {
154154
// a start build of the workspace.
155155
isFirstBuild := true
156156
buildURL := regexp.MustCompile("/api/v2/workspaces/.*/builds")
157-
buildReq := make(chan struct{})
157+
buildSync := make(chan struct{})
158158
buildResume := make(chan struct{})
159159
buildSyncMW := func(next http.Handler) http.Handler {
160160
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
161161
if r.Method == http.MethodPost && buildURL.MatchString(r.URL.Path) {
162162
if !isFirstBuild {
163-
t.Log("buildSyncMW: blocking build")
164-
buildReq <- struct{}{}
165-
<-buildResume
166-
t.Log("buildSyncMW: resuming build")
163+
defer func() {
164+
t.Log("buildSyncMW: blocking post-build")
165+
buildSync <- struct{}{}
166+
<-buildResume
167+
t.Log("buildSyncMW: resuming...")
168+
}()
167169
} else {
168170
isFirstBuild = false
169171
}
@@ -212,7 +214,7 @@ func TestSSH(t *testing.T) {
212214
pty.ExpectMatchContext(ctx, "Workspace was stopped, starting workspace to allow connecting to")
213215
}
214216
for range ptys {
215-
testutil.RequireRecvCtx(ctx, t, buildReq)
217+
testutil.RequireRecvCtx(ctx, t, buildSync)
216218
}
217219
close(buildResume)
218220

0 commit comments

Comments
 (0)