Skip to content

Commit

Permalink
Listen on 127.0.0.1 in tests to avoid firewall popups on MacOS (#2882)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-p authored Jan 3, 2024
1 parent cabb3d2 commit 3087725
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ func TestSchedulerForwardsErrorToFrontend(t *testing.T) {
frontendGrpcServer := grpc.NewServer()
frontendpb.RegisterFrontendForQuerierServer(frontendGrpcServer, fm)

l, err := net.Listen("tcp", "")
l, err := net.Listen("tcp", "127.0.0.1:")
require.NoError(t, err)

frontendAddress = l.Addr().String()
Expand Down
13 changes: 10 additions & 3 deletions pkg/test/integration/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func getFreePorts(len int) (ports []int, err error) {
ports = make([]int, len)
for i := 0; i < len; i++ {
var a *net.TCPAddr
if a, err = net.ResolveTCPAddr("tcp", "localhost:0"); err == nil {
if a, err = net.ResolveTCPAddr("tcp", "127.0.0.1:0"); err == nil {
var l *net.TCPListener
if l, err = net.ListenTCP("tcp", a); err != nil {
return nil, err
Expand All @@ -48,6 +48,7 @@ type PyroscopeTest struct {
memberlistPort int
}

const address = "127.0.0.1"
const storeInMemory = "inmemory"

func (p *PyroscopeTest) Start(t *testing.T) {
Expand All @@ -63,10 +64,16 @@ func (p *PyroscopeTest) Start(t *testing.T) {
err = cfg.DynamicUnmarshal(&p.config, []string{"pyroscope"}, flag.NewFlagSet("pyroscope", flag.ContinueOnError))
require.NoError(t, err)

// set free ports
// set addresses and ports
p.config.Server.HTTPListenAddress = address
p.config.Server.HTTPListenPort = p.httpPort
p.config.Server.GRPCListenAddress = address
p.config.Worker.SchedulerAddress = address
p.config.MemberlistKV.AdvertisePort = p.memberlistPort
p.config.MemberlistKV.TCPTransport.BindPort = p.memberlistPort
p.config.Ingester.LifecyclerConfig.Addr = address
p.config.QueryScheduler.ServiceDiscovery.SchedulerRing.InstanceAddr = address
p.config.Frontend.Addr = address

// heartbeat more often
p.config.Distributor.DistributorRing.HeartbeatPeriod = time.Second
Expand Down Expand Up @@ -116,7 +123,7 @@ func (p *PyroscopeTest) ringActive() bool {
return httpBodyContains(p.URL()+"/ring", "ACTIVE")
}
func (p *PyroscopeTest) URL() string {
return fmt.Sprintf("http://localhost:%d", p.httpPort)
return fmt.Sprintf("http://%s:%d", address, p.httpPort)
}

func (p *PyroscopeTest) queryClient() querierv1connect.QuerierServiceClient {
Expand Down

0 comments on commit 3087725

Please sign in to comment.