Skip to content
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

Fix windows system-probe pprof flare tests #26150

Merged
merged 4 commits into from
May 31, 2024
Merged
Changes from all commits
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
37 changes: 17 additions & 20 deletions cmd/agent/subcommands/flare/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ import (
type commandTestSuite struct {
suite.Suite
sysprobeSocketPath string
tcpServer *httptest.Server
unixServer *httptest.Server
}

func (c *commandTestSuite) SetupSuite() {
t := c.T()
c.sysprobeSocketPath = path.Join(t.TempDir(), "sysprobe.sock")
c.tcpServer, c.unixServer = c.getPprofTestServer()
}

func getPprofTestServer(t *testing.T, utsPath string) (tcpServer *httptest.Server, unixServer *httptest.Server) {
func (c *commandTestSuite) TearDownSuite() {
c.tcpServer.Close()
if c.unixServer != nil {
c.unixServer.Close()
}
}

func (c *commandTestSuite) getPprofTestServer() (tcpServer *httptest.Server, unixServer *httptest.Server) {
t := c.T()
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/debug/pprof/heap":
Expand All @@ -61,14 +72,12 @@ func getPprofTestServer(t *testing.T, utsPath string) (tcpServer *httptest.Serve
if runtime.GOOS == "linux" {
unixServer = httptest.NewUnstartedServer(handler)
var err error
unixServer.Listener, err = net.Listen("unix", utsPath)
require.NoError(t, err, "could not create listener for unix socket on %s", utsPath)
unixServer.Listener, err = net.Listen("unix", c.sysprobeSocketPath)
require.NoError(t, err, "could not create listener for unix socket on %s", c.sysprobeSocketPath)
unixServer.Start()

return tcpServer, unixServer
}

return tcpServer, tcpServer
return tcpServer, unixServer
}

func TestCommandTestSuite(t *testing.T) {
Expand All @@ -77,13 +86,7 @@ func TestCommandTestSuite(t *testing.T) {

func (c *commandTestSuite) TestReadProfileData() {
t := c.T()
ts, uts := getPprofTestServer(t, c.sysprobeSocketPath)
t.Cleanup(func() {
ts.Close()
uts.Close()
})

u, err := url.Parse(ts.URL)
u, err := url.Parse(c.tcpServer.URL)
require.NoError(t, err)
port := u.Port()

Expand Down Expand Up @@ -151,13 +154,7 @@ func (c *commandTestSuite) TestReadProfileData() {

func (c *commandTestSuite) TestReadProfileDataNoTraceAgent() {
t := c.T()
ts, uts := getPprofTestServer(t, c.sysprobeSocketPath)
t.Cleanup(func() {
ts.Close()
uts.Close()
})

u, err := url.Parse(ts.URL)
u, err := url.Parse(c.tcpServer.URL)
require.NoError(t, err)
port := u.Port()

Expand Down
Loading