Skip to content

Commit 3f0738e

Browse files
committed
Begin adding tests for external registration
1 parent 59b842b commit 3f0738e

File tree

5 files changed

+44
-33
lines changed

5 files changed

+44
-33
lines changed

coderd/coderd.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -599,18 +599,20 @@ type API struct {
599599
// RootHandler serves "/"
600600
RootHandler chi.Router
601601

602-
metricsCache *metricscache.Cache
603-
siteHandler http.Handler
604-
websocketWaitMutex sync.Mutex
605-
websocketWaitGroup sync.WaitGroup
602+
metricsCache *metricscache.Cache
603+
siteHandler http.Handler
604+
605+
WebsocketWaitMutex sync.Mutex
606+
WebsocketWaitGroup sync.WaitGroup
607+
606608
workspaceAgentCache *wsconncache.Cache
607609
}
608610

609611
// Close waits for all WebSocket connections to drain before returning.
610612
func (api *API) Close() error {
611-
api.websocketWaitMutex.Lock()
612-
api.websocketWaitGroup.Wait()
613-
api.websocketWaitMutex.Unlock()
613+
api.WebsocketWaitMutex.Lock()
614+
api.WebsocketWaitGroup.Wait()
615+
api.WebsocketWaitMutex.Unlock()
614616

615617
api.metricsCache.Close()
616618
coordinator := api.TailnetCoordinator.Load()

coderd/provisionerjobs.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ func (api *API) provisionerJobLogs(rw http.ResponseWriter, r *http.Request, job
130130
return
131131
}
132132

133-
api.websocketWaitMutex.Lock()
134-
api.websocketWaitGroup.Add(1)
135-
api.websocketWaitMutex.Unlock()
136-
defer api.websocketWaitGroup.Done()
133+
api.WebsocketWaitMutex.Lock()
134+
api.WebsocketWaitGroup.Add(1)
135+
api.WebsocketWaitMutex.Unlock()
136+
defer api.WebsocketWaitGroup.Done()
137137
conn, err := websocket.Accept(rw, r, nil)
138138
if err != nil {
139139
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{

coderd/workspaceagents.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,10 @@ func (api *API) postWorkspaceAgentVersion(rw http.ResponseWriter, r *http.Reques
181181
func (api *API) workspaceAgentPTY(rw http.ResponseWriter, r *http.Request) {
182182
ctx := r.Context()
183183

184-
api.websocketWaitMutex.Lock()
185-
api.websocketWaitGroup.Add(1)
186-
api.websocketWaitMutex.Unlock()
187-
defer api.websocketWaitGroup.Done()
184+
api.WebsocketWaitMutex.Lock()
185+
api.WebsocketWaitGroup.Add(1)
186+
api.WebsocketWaitMutex.Unlock()
187+
defer api.WebsocketWaitGroup.Done()
188188

189189
workspaceAgent := httpmw.WorkspaceAgentParam(r)
190190
workspace := httpmw.WorkspaceParam(r)
@@ -442,10 +442,10 @@ func (api *API) workspaceAgentConnection(rw http.ResponseWriter, r *http.Request
442442
func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request) {
443443
ctx := r.Context()
444444

445-
api.websocketWaitMutex.Lock()
446-
api.websocketWaitGroup.Add(1)
447-
api.websocketWaitMutex.Unlock()
448-
defer api.websocketWaitGroup.Done()
445+
api.WebsocketWaitMutex.Lock()
446+
api.WebsocketWaitGroup.Add(1)
447+
api.WebsocketWaitMutex.Unlock()
448+
defer api.WebsocketWaitGroup.Done()
449449
workspaceAgent := httpmw.WorkspaceAgent(r)
450450
resource, err := api.Database.GetWorkspaceResourceByID(ctx, workspaceAgent.ResourceID)
451451
if err != nil {
@@ -614,10 +614,10 @@ func (api *API) workspaceAgentClientCoordinate(rw http.ResponseWriter, r *http.R
614614
}
615615
}
616616

617-
api.websocketWaitMutex.Lock()
618-
api.websocketWaitGroup.Add(1)
619-
api.websocketWaitMutex.Unlock()
620-
defer api.websocketWaitGroup.Done()
617+
api.WebsocketWaitMutex.Lock()
618+
api.WebsocketWaitGroup.Add(1)
619+
api.WebsocketWaitMutex.Unlock()
620+
defer api.WebsocketWaitGroup.Done()
621621
workspaceAgent := httpmw.WorkspaceAgentParam(r)
622622

623623
conn, err := websocket.Accept(rw, r, nil)
@@ -744,10 +744,10 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
744744
func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Request) {
745745
ctx := r.Context()
746746

747-
api.websocketWaitMutex.Lock()
748-
api.websocketWaitGroup.Add(1)
749-
api.websocketWaitMutex.Unlock()
750-
defer api.websocketWaitGroup.Done()
747+
api.WebsocketWaitMutex.Lock()
748+
api.WebsocketWaitGroup.Add(1)
749+
api.WebsocketWaitMutex.Unlock()
750+
defer api.WebsocketWaitGroup.Done()
751751

752752
workspaceAgent := httpmw.WorkspaceAgent(r)
753753
resource, err := api.Database.GetWorkspaceResourceByID(ctx, workspaceAgent.ResourceID)

enterprise/coderd/provisionerdaemons.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import (
55
"io"
66
"net/http"
77

8-
"cdr.dev/slog"
98
"github.com/google/uuid"
109
"github.com/hashicorp/yamux"
1110
"golang.org/x/xerrors"
1211
"nhooyr.io/websocket"
1312
"storj.io/drpc/drpcmux"
1413
"storj.io/drpc/drpcserver"
1514

15+
"cdr.dev/slog"
16+
1617
"github.com/coder/coder/coderd/database"
1718
"github.com/coder/coder/coderd/httpapi"
1819
"github.com/coder/coder/coderd/httpmw"
20+
"github.com/coder/coder/coderd/provisionerdserver"
1921
"github.com/coder/coder/coderd/rbac"
2022
"github.com/coder/coder/codersdk"
2123
"github.com/coder/coder/provisionerd/proto"
@@ -55,10 +57,10 @@ func (api *API) provisionerDaemonsListen(rw http.ResponseWriter, r *http.Request
5557
daemon := httpmw.ProvisionerDaemon(r)
5658
api.Logger.Warn(r.Context(), "daemon connected", slog.F("daemon", daemon.Name))
5759

58-
api.websocketWaitMutex.Lock()
59-
api.websocketWaitGroup.Add(1)
60-
api.websocketWaitMutex.Unlock()
61-
defer api.websocketWaitGroup.Done()
60+
api.AGPL.WebsocketWaitMutex.Lock()
61+
api.AGPL.WebsocketWaitGroup.Add(1)
62+
api.AGPL.WebsocketWaitMutex.Unlock()
63+
defer api.AGPL.WebsocketWaitGroup.Done()
6264

6365
conn, err := websocket.Accept(rw, r, &websocket.AcceptOptions{
6466
// Need to disable compression to avoid a data-race.
@@ -85,7 +87,7 @@ func (api *API) provisionerDaemonsListen(rw http.ResponseWriter, r *http.Request
8587
return
8688
}
8789
mux := drpcmux.New()
88-
err = proto.DRPCRegisterProvisionerDaemon(mux, &provisionerdServer{
90+
err = proto.DRPCRegisterProvisionerDaemon(mux, &provisionerdserver.Server{
8991
AccessURL: api.AccessURL,
9092
ID: daemon.ID,
9193
Database: api.Database,
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package coderd_test
2+
3+
import "testing"
4+
5+
func TestPostProvisionerDaemon(t *testing.T) {
6+
t.Parallel()
7+
}

0 commit comments

Comments
 (0)