Skip to content

Commit ee0ee70

Browse files
committed
Fix context cancel for HTTP requests
1 parent 1a48bea commit ee0ee70

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

coderd/coderdtest/coderdtest.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"database/sql"
66
"io"
7+
"net"
78
"net/http/httptest"
89
"net/url"
910
"os"
@@ -59,7 +60,13 @@ func New(t *testing.T) *codersdk.Client {
5960
Database: db,
6061
Pubsub: pubsub,
6162
})
62-
srv := httptest.NewServer(handler)
63+
srv := httptest.NewUnstartedServer(handler)
64+
srv.Config.BaseContext = func(_ net.Listener) context.Context {
65+
ctx, cancelFunc := context.WithCancel(context.Background())
66+
t.Cleanup(cancelFunc)
67+
return ctx
68+
}
69+
srv.Start()
6370
serverURL, err := url.Parse(srv.URL)
6471
require.NoError(t, err)
6572
t.Cleanup(srv.Close)

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