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

Only listen on localhost for unit tests #261

Merged
merged 1 commit into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions cmd/replication/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ func main() {
chainRegistry,
db,
blockchainPublisher,
fmt.Sprintf("0.0.0.0:%d", options.API.Port),
)
if err != nil {
log.Fatal("initializing server", zap.Error(err))
Expand Down
5 changes: 2 additions & 3 deletions pkg/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"context"
"fmt"
"net"
"strings"
"sync"
Expand Down Expand Up @@ -33,11 +32,11 @@ type ApiServer struct {
func NewAPIServer(
ctx context.Context,
log *zap.Logger,
port int,
listenAddress string,
enableReflection bool,
registrationFunc RegistrationFunc,
) (*ApiServer, error) {
grpcListener, err := net.Listen("tcp", fmt.Sprintf("0.0.0.0:%d", port))
grpcListener, err := net.Listen("tcp", listenAddress)

if err != nil {
return nil, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func NewReplicationServer(
nodeRegistry registry.NodeRegistry,
writerDB *sql.DB,
blockchainPublisher blockchain.IBlockchainPublisher,
listenAddress string,
) (*ReplicationServer, error) {
var err error

Expand Down Expand Up @@ -147,7 +148,7 @@ func NewReplicationServer(
s.apiServer, err = api.NewAPIServer(
s.ctx,
log,
options.API.Port,
listenAddress,
options.Reflection.Enable,
serviceRegistrationFunc,
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewTestServer(
API: config.ApiOptions{
Port: port,
},
}, registry, db, messagePublisher)
}, registry, db, messagePublisher, fmt.Sprintf("localhost:%d", port))
require.NoError(t, err)

return server
Expand Down
4 changes: 2 additions & 2 deletions pkg/testutils/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ func NewTestAPIServer(t *testing.T) (*api.ApiServer, *sql.DB, func()) {
svr, err := api.NewAPIServer(
ctx,
log,
0, /*port*/
true, /*enableReflection*/
"localhost:0", /*listenAddress*/
true, /*enableReflection*/
serviceRegistrationFunc,
)
require.NoError(t, err)
Expand Down
Loading