mirror of
https://github.com/coder/coder.git
synced 2025-07-12 00:14:10 +00:00
test(cli/ssh): fix ssh start conflict test by faking API response (#16082)
This commit is contained in:
committed by
GitHub
parent
899836d47a
commit
8c44cd3dfd
@ -154,16 +154,25 @@ func TestSSH(t *testing.T) {
|
|||||||
// a start build of the workspace.
|
// a start build of the workspace.
|
||||||
isFirstBuild := true
|
isFirstBuild := true
|
||||||
buildURL := regexp.MustCompile("/api/v2/workspaces/.*/builds")
|
buildURL := regexp.MustCompile("/api/v2/workspaces/.*/builds")
|
||||||
buildReq := make(chan struct{})
|
buildPause := make(chan bool)
|
||||||
buildResume := make(chan struct{})
|
buildDone := make(chan struct{})
|
||||||
buildSyncMW := func(next http.Handler) http.Handler {
|
buildSyncMW := func(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method == http.MethodPost && buildURL.MatchString(r.URL.Path) {
|
if r.Method == http.MethodPost && buildURL.MatchString(r.URL.Path) {
|
||||||
if !isFirstBuild {
|
if !isFirstBuild {
|
||||||
t.Log("buildSyncMW: blocking build")
|
t.Log("buildSyncMW: pausing build")
|
||||||
buildReq <- struct{}{}
|
if shouldContinue := <-buildPause; !shouldContinue {
|
||||||
<-buildResume
|
// We can't force the API to trigger a build conflict (racy) so we fake it.
|
||||||
|
t.Log("buildSyncMW: return conflict")
|
||||||
|
w.WriteHeader(http.StatusConflict)
|
||||||
|
return
|
||||||
|
}
|
||||||
t.Log("buildSyncMW: resuming build")
|
t.Log("buildSyncMW: resuming build")
|
||||||
|
defer func() {
|
||||||
|
t.Log("buildSyncMW: sending build done")
|
||||||
|
buildDone <- struct{}{}
|
||||||
|
t.Log("buildSyncMW: done")
|
||||||
|
}()
|
||||||
} else {
|
} else {
|
||||||
isFirstBuild = false
|
isFirstBuild = false
|
||||||
}
|
}
|
||||||
@ -211,10 +220,15 @@ func TestSSH(t *testing.T) {
|
|||||||
for _, pty := range ptys {
|
for _, pty := range ptys {
|
||||||
pty.ExpectMatchContext(ctx, "Workspace was stopped, starting workspace to allow connecting to")
|
pty.ExpectMatchContext(ctx, "Workspace was stopped, starting workspace to allow connecting to")
|
||||||
}
|
}
|
||||||
for range ptys {
|
|
||||||
testutil.RequireRecvCtx(ctx, t, buildReq)
|
// Allow one build to complete.
|
||||||
|
testutil.RequireSendCtx(ctx, t, buildPause, true)
|
||||||
|
testutil.RequireRecvCtx(ctx, t, buildDone)
|
||||||
|
|
||||||
|
// Allow the remaining builds to continue.
|
||||||
|
for i := 0; i < len(ptys)-1; i++ {
|
||||||
|
testutil.RequireSendCtx(ctx, t, buildPause, false)
|
||||||
}
|
}
|
||||||
close(buildResume)
|
|
||||||
|
|
||||||
var foundConflict int
|
var foundConflict int
|
||||||
for _, pty := range ptys {
|
for _, pty := range ptys {
|
||||||
|
Reference in New Issue
Block a user