Skip to content
Prev Previous commit
Next Next commit
add flush to wsproxy tests
  • Loading branch information
johnstcn committed Jan 16, 2024
commit 601136cd23b45d0d60c917de1a584c07a7db123e
6 changes: 6 additions & 0 deletions enterprise/coderd/coderdenttest/proxytest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type ProxyOptions struct {

// ProxyURL is optional
ProxyURL *url.URL

// Flush is optional
Flush chan chan<- struct{}
Copy link
Member

Choose a reason for hiding this comment

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

Naming could match workspace apps here, i.e. FlushStats.

}

// NewWorkspaceProxy will configure a wsproxy.Server with the given options.
Expand Down Expand Up @@ -113,6 +116,9 @@ func NewWorkspaceProxy(t *testing.T, coderdAPI *coderd.API, owner *codersdk.Clie
// Inherit collector options from coderd, but keep the wsproxy reporter.
statsCollectorOptions := coderdAPI.Options.WorkspaceAppsStatsCollectorOptions
statsCollectorOptions.Reporter = nil
if options.Flush != nil {
statsCollectorOptions.Flush = options.Flush
}

wssrv, err := wsproxy.New(ctx, &wsproxy.Options{
Logger: slogtest.Make(t, nil).Leveled(slog.LevelDebug),
Expand Down
9 changes: 9 additions & 0 deletions enterprise/wsproxy/wsproxy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@ func TestWorkspaceProxyWorkspaceApps(t *testing.T) {
"*",
}

proxyFlushCh := make(chan chan<- struct{}, 1)
flushStats := func() {
proxyFlushDone := make(chan struct{}, 1)
proxyFlushCh <- proxyFlushDone
<-proxyFlushDone
}

client, closer, api, user := coderdenttest.NewWithAPI(t, &coderdenttest.Options{
Options: &coderdtest.Options{
DeploymentValues: deploymentValues,
Expand Down Expand Up @@ -476,13 +483,15 @@ func TestWorkspaceProxyWorkspaceApps(t *testing.T) {
Name: "best-proxy",
AppHostname: opts.AppHost,
DisablePathApps: opts.DisablePathApps,
Flush: proxyFlushCh,
})

return &apptest.Deployment{
Options: opts,
SDKClient: client,
FirstUser: user,
PathAppBaseURL: proxyAPI.Options.AccessURL,
FlushStats: flushStats,
}
})
}