Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8c44cd3

Browse files
authored
test(cli/ssh): fix ssh start conflict test by faking API response (#16082)
1 parent899836d commit8c44cd3

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

‎cli/ssh_test.go

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,16 +154,25 @@ 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(chanstruct{})
158-
buildResume:=make(chanstruct{})
157+
buildPause:=make(chanbool)
158+
buildDone:=make(chanstruct{})
159159
buildSyncMW:=func(next http.Handler) http.Handler {
160160
returnhttp.HandlerFunc(func(w http.ResponseWriter,r*http.Request) {
161161
ifr.Method==http.MethodPost&&buildURL.MatchString(r.URL.Path) {
162162
if!isFirstBuild {
163-
t.Log("buildSyncMW: blocking build")
164-
buildReq<-struct{}{}
165-
<-buildResume
163+
t.Log("buildSyncMW: pausing build")
164+
ifshouldContinue:=<-buildPause;!shouldContinue {
165+
// We can't force the API to trigger a build conflict (racy) so we fake it.
166+
t.Log("buildSyncMW: return conflict")
167+
w.WriteHeader(http.StatusConflict)
168+
return
169+
}
166170
t.Log("buildSyncMW: resuming build")
171+
deferfunc() {
172+
t.Log("buildSyncMW: sending build done")
173+
buildDone<-struct{}{}
174+
t.Log("buildSyncMW: done")
175+
}()
167176
}else {
168177
isFirstBuild=false
169178
}
@@ -211,10 +220,15 @@ func TestSSH(t *testing.T) {
211220
for_,pty:=rangeptys {
212221
pty.ExpectMatchContext(ctx,"Workspace was stopped, starting workspace to allow connecting to")
213222
}
214-
forrangeptys {
215-
testutil.RequireRecvCtx(ctx,t,buildReq)
223+
224+
// Allow one build to complete.
225+
testutil.RequireSendCtx(ctx,t,buildPause,true)
226+
testutil.RequireRecvCtx(ctx,t,buildDone)
227+
228+
// Allow the remaining builds to continue.
229+
fori:=0;i<len(ptys)-1;i++ {
230+
testutil.RequireSendCtx(ctx,t,buildPause,false)
216231
}
217-
close(buildResume)
218232

219233
varfoundConflictint
220234
for_,pty:=rangeptys {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp