-
Notifications
You must be signed in to change notification settings - Fork 905
chore: add additional tailnet topology integration tests #13549
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
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3527862
derp server restart test
ethanndickson 5c1c70e
fix
ethanndickson 3fee5ed
server interface
ethanndickson 5e73d63
WIP
ethanndickson f0da669
WIP
ethanndickson 8eea4eb
coordinator restart
ethanndickson dde80f7
restart derp & coordinator
ethanndickson aa31cc0
impl'd review changes
ethanndickson 286660f
impl'd review
ethanndickson 023e0a7
cleaner query strings
ethanndickson 6872ba1
fix
ethanndickson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,13 +111,64 @@ type SimpleServerOptions struct { | |
|
||
var _ ServerStarter = SimpleServerOptions{} | ||
|
||
type connManager struct { | ||
mu sync.Mutex | ||
conns map[uuid.UUID]net.Conn | ||
} | ||
|
||
func (c *connManager) Add(id uuid.UUID, conn net.Conn) func() { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
c.conns[id] = conn | ||
return func() { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
delete(c.conns, id) | ||
} | ||
} | ||
|
||
func (c *connManager) CloseAll() { | ||
c.mu.Lock() | ||
defer c.mu.Unlock() | ||
for _, conn := range c.conns { | ||
_ = conn.Close() | ||
} | ||
c.conns = make(map[uuid.UUID]net.Conn) | ||
} | ||
|
||
type derpServer struct { | ||
http.Handler | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Following on from your feedback - if we leave the |
||
srv *derp.Server | ||
closeFn func() | ||
} | ||
|
||
func newDerpServer(t *testing.T, logger slog.Logger) *derpServer { | ||
derpSrv := derp.NewServer(key.NewNode(), tailnet.Logger(logger.Named("derp"))) | ||
derpHandler, derpCloseFunc := tailnet.WithWebsocketSupport(derpSrv, derphttp.Handler(derpSrv)) | ||
t.Cleanup(derpCloseFunc) | ||
return &derpServer{ | ||
srv: derpSrv, | ||
Handler: derpHandler, | ||
closeFn: derpCloseFunc, | ||
} | ||
} | ||
|
||
func (s *derpServer) Close() { | ||
s.srv.Close() | ||
s.closeFn() | ||
} | ||
|
||
//nolint:revive | ||
func (o SimpleServerOptions) Router(t *testing.T, logger slog.Logger) *chi.Mux { | ||
coord := tailnet.NewCoordinator(logger) | ||
var coordPtr atomic.Pointer[tailnet.Coordinator] | ||
coordPtr.Store(&coord) | ||
t.Cleanup(func() { _ = coord.Close() }) | ||
|
||
cm := connManager{ | ||
conns: make(map[uuid.UUID]net.Conn), | ||
} | ||
|
||
csvc, err := tailnet.NewClientService(logger, &coordPtr, 10*time.Minute, func() *tailcfg.DERPMap { | ||
return &tailcfg.DERPMap{ | ||
// Clients will set their own based on their custom access URL. | ||
|
@@ -126,9 +177,11 @@ func (o SimpleServerOptions) Router(t *testing.T, logger slog.Logger) *chi.Mux { | |
}) | ||
require.NoError(t, err) | ||
|
||
derpServer := derp.NewServer(key.NewNode(), tailnet.Logger(logger.Named("derp"))) | ||
derpHandler, derpCloseFunc := tailnet.WithWebsocketSupport(derpServer, derphttp.Handler(derpServer)) | ||
t.Cleanup(derpCloseFunc) | ||
derpServer := atomic.Pointer[derpServer]{} | ||
derpServer.Store(newDerpServer(t, logger)) | ||
t.Cleanup(func() { | ||
derpServer.Load().Close() | ||
}) | ||
|
||
r := chi.NewRouter() | ||
r.Use( | ||
|
@@ -166,11 +219,32 @@ func (o SimpleServerOptions) Router(t *testing.T, logger slog.Logger) *chi.Mux { | |
return | ||
} | ||
|
||
derpHandler.ServeHTTP(w, r) | ||
derpServer.Load().ServeHTTP(w, r) | ||
}) | ||
r.Get("/latency-check", func(w http.ResponseWriter, r *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
}) | ||
r.Post("/restart", func(w http.ResponseWriter, r *http.Request) { | ||
ethanndickson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
oldServer := derpServer.Swap(newDerpServer(t, logger)) | ||
oldServer.Close() | ||
w.WriteHeader(http.StatusOK) | ||
}) | ||
}) | ||
|
||
// /restart?derp=[true|false]&coordinator=[true|false] | ||
r.Post("/restart", func(w http.ResponseWriter, r *http.Request) { | ||
if r.URL.Query().Get("derp") == "true" { | ||
logger.Info(r.Context(), "killing DERP server") | ||
oldServer := derpServer.Swap(newDerpServer(t, logger)) | ||
oldServer.Close() | ||
logger.Info(r.Context(), "restarted DERP server") | ||
} | ||
|
||
if r.URL.Query().Get("coordinator") == "true" { | ||
logger.Info(r.Context(), "simulating coordinator restart") | ||
cm.CloseAll() | ||
} | ||
w.WriteHeader(http.StatusOK) | ||
}) | ||
|
||
r.Get("/api/v2/workspaceagents/{id}/coordinate", func(w http.ResponseWriter, r *http.Request) { | ||
|
@@ -199,6 +273,9 @@ func (o SimpleServerOptions) Router(t *testing.T, logger slog.Logger) *chi.Mux { | |
ctx, wsNetConn := codersdk.WebsocketNetConn(ctx, conn, websocket.MessageBinary) | ||
defer wsNetConn.Close() | ||
|
||
cleanFn := cm.Add(id, wsNetConn) | ||
defer cleanFn() | ||
|
||
err = csvc.ServeConnV2(ctx, wsNetConn, tailnet.StreamID{ | ||
Name: "client-" + id.String(), | ||
ID: id, | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.