Skip to content

test: Return early and avoid using nil handler #7411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 4, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add comment
  • Loading branch information
Emyrk committed May 4, 2023
commit a6d4d60fed5d4953e30866c24ddc8fd615d78f3b
4 changes: 2 additions & 2 deletions enterprise/coderd/coderdenttest/proxytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func NewWorkspaceProxy(t *testing.T, coderdAPI *coderd.API, owner *codersdk.Clie
}

// HTTP Server. We have to start this once to get the access URL to start
// the workspace proxy with. We need the workspace proxy to pass in the
// handler here.
// the workspace proxy with. The workspace proxy has the handler, so the
// http server will start with a 503 until the proxy is started.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A strategy that avoids the mutex is to create a listener, then pass that to http.Serve()

l := net.Listen("tcp", "127.0.0.1:")
url := "http://" + l.Addr().String()

I guess it gets a bit more complex if we need TLS. Does the wsproxy care whether its TLS?

var mutex sync.RWMutex
var handler http.Handler
srv := httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
Expand Down