Skip to content

Commit 872d69c

Browse files
authored
Don't use the default port in runtime manager tests (#5454)
This runs into conflicts with an actual agent running on the system. Use a random port instead.
1 parent 781f529 commit 872d69c

File tree

2 files changed

+25
-20
lines changed

2 files changed

+25
-20
lines changed

pkg/component/runtime/manager_fake_input_test.go

+24-18
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func (suite *FakeInputSuite) TestManager_Features() {
101101
agentInfo,
102102
apmtest.DiscardTracer,
103103
newTestMonitoringMgr(),
104-
configuration.DefaultGRPCConfig(),
104+
testGrpcConfig(),
105105
false)
106106
require.NoError(t, err)
107107

@@ -302,7 +302,7 @@ func (suite *FakeInputSuite) TestManager_APM() {
302302
agentInfo,
303303
apmtest.DiscardTracer,
304304
newTestMonitoringMgr(),
305-
configuration.DefaultGRPCConfig(),
305+
testGrpcConfig(),
306306
false)
307307
require.NoError(t, err)
308308

@@ -537,7 +537,7 @@ func (suite *FakeInputSuite) TestManager_Limits() {
537537
agentInfo,
538538
apmtest.DiscardTracer,
539539
newTestMonitoringMgr(),
540-
configuration.DefaultGRPCConfig(),
540+
testGrpcConfig(),
541541
false,
542542
)
543543
require.NoError(t, err)
@@ -695,7 +695,7 @@ func (suite *FakeInputSuite) TestManager_BadUnitToGood() {
695695
defer cancel()
696696

697697
ai := &info.AgentInfo{}
698-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
698+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
699699
false)
700700
require.NoError(t, err)
701701
errCh := make(chan error)
@@ -865,7 +865,7 @@ func (suite *FakeInputSuite) TestManager_GoodUnitToBad() {
865865
defer cancel()
866866

867867
ai := &info.AgentInfo{}
868-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
868+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
869869
false)
870870
require.NoError(t, err)
871871
runResultChan := make(chan error, 1)
@@ -1048,7 +1048,7 @@ func (suite *FakeInputSuite) TestManager_NoDeadlock() {
10481048

10491049
// Create the runtime manager
10501050
ai := &info.AgentInfo{}
1051-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1051+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
10521052
false)
10531053
require.NoError(t, err)
10541054

@@ -1123,7 +1123,7 @@ func (suite *FakeInputSuite) TestManager_Configure() {
11231123
defer cancel()
11241124

11251125
ai := &info.AgentInfo{}
1126-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1126+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
11271127
false)
11281128
require.NoError(t, err)
11291129
errCh := make(chan error)
@@ -1246,7 +1246,7 @@ func (suite *FakeInputSuite) TestManager_RemoveUnit() {
12461246
defer cancel()
12471247

12481248
ai := &info.AgentInfo{}
1249-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1249+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
12501250
false)
12511251
require.NoError(t, err)
12521252
errCh := make(chan error)
@@ -1402,7 +1402,7 @@ func (suite *FakeInputSuite) TestManager_ActionState() {
14021402
defer cancel()
14031403

14041404
ai := &info.AgentInfo{}
1405-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1405+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
14061406
false)
14071407
require.NoError(t, err)
14081408
errCh := make(chan error)
@@ -1528,7 +1528,7 @@ func (suite *FakeInputSuite) TestManager_Restarts() {
15281528
defer cancel()
15291529

15301530
ai := &info.AgentInfo{}
1531-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1531+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
15321532
false)
15331533
require.NoError(t, err)
15341534
errCh := make(chan error)
@@ -1665,7 +1665,7 @@ func (suite *FakeInputSuite) TestManager_Restarts_ConfigKill() {
16651665
defer cancel()
16661666

16671667
ai := &info.AgentInfo{}
1668-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1668+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
16691669
false)
16701670
require.NoError(t, err)
16711671
errCh := make(chan error)
@@ -1810,7 +1810,7 @@ func (suite *FakeInputSuite) TestManager_KeepsRestarting() {
18101810
defer cancel()
18111811

18121812
ai := &info.AgentInfo{}
1813-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1813+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
18141814
false)
18151815
require.NoError(t, err)
18161816
errCh := make(chan error)
@@ -1955,7 +1955,7 @@ func (suite *FakeInputSuite) TestManager_RestartsOnMissedCheckins() {
19551955
defer cancel()
19561956

19571957
ai := &info.AgentInfo{}
1958-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
1958+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
19591959
false)
19601960
require.NoError(t, err)
19611961
errCh := make(chan error)
@@ -2075,7 +2075,7 @@ func (suite *FakeInputSuite) TestManager_InvalidAction() {
20752075
defer cancel()
20762076

20772077
ai := &info.AgentInfo{}
2078-
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), configuration.DefaultGRPCConfig(),
2078+
m, err := NewManager(newDebugLogger(t), newDebugLogger(t), ai, apmtest.DiscardTracer, newTestMonitoringMgr(), testGrpcConfig(),
20792079
false)
20802080
require.NoError(t, err)
20812081
errCh := make(chan error)
@@ -2200,7 +2200,7 @@ func (suite *FakeInputSuite) TestManager_MultiComponent() {
22002200
agentInfo,
22012201
apmtest.DiscardTracer,
22022202
newTestMonitoringMgr(),
2203-
configuration.DefaultGRPCConfig(),
2203+
testGrpcConfig(),
22042204
false)
22052205
require.NoError(t, err)
22062206

@@ -2414,7 +2414,7 @@ func (suite *FakeInputSuite) TestManager_LogLevel() {
24142414
ai,
24152415
apmtest.DiscardTracer,
24162416
newTestMonitoringMgr(),
2417-
configuration.DefaultGRPCConfig(),
2417+
testGrpcConfig(),
24182418
false)
24192419
require.NoError(t, err)
24202420

@@ -2556,7 +2556,7 @@ func (suite *FakeInputSuite) TestManager_StartStopComponent() {
25562556
ai,
25572557
apmtest.DiscardTracer,
25582558
newTestMonitoringMgr(),
2559-
configuration.DefaultGRPCConfig(),
2559+
testGrpcConfig(),
25602560
false)
25612561
require.NoError(t, err, "could not crete new manager")
25622562

@@ -2737,7 +2737,7 @@ func (suite *FakeInputSuite) TestManager_Chunk() {
27372737
defer cancel()
27382738

27392739
const grpcDefaultSize = 1024 * 1024 * 4
2740-
grpcConfig := configuration.DefaultGRPCConfig()
2740+
grpcConfig := testGrpcConfig()
27412741
grpcConfig.MaxMsgSize = grpcDefaultSize * 2 // set to double the default size
27422742

27432743
ai := &info.AgentInfo{}
@@ -2937,6 +2937,12 @@ func testBinary(t *testing.T, name string) string {
29372937
return binaryPath
29382938
}
29392939

2940+
func testGrpcConfig() *configuration.GRPCConfig {
2941+
grpcConfig := configuration.DefaultGRPCConfig()
2942+
grpcConfig.Port = 0 // this means that we choose a random available port
2943+
return grpcConfig
2944+
}
2945+
29402946
func fakeBinaryPath(name string) string {
29412947
binaryPath := filepath.Join("..", "fake", name, name)
29422948

pkg/component/runtime/manager_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/elastic/elastic-agent-client/v7/pkg/client"
1919
"github.com/elastic/elastic-agent-libs/logp"
2020
"github.com/elastic/elastic-agent/internal/pkg/agent/application/info"
21-
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
2221
"github.com/elastic/elastic-agent/pkg/component"
2322
"github.com/elastic/elastic-agent/pkg/core/logger"
2423
)
@@ -34,7 +33,7 @@ func TestManager_SimpleComponentErr(t *testing.T) {
3433
ai,
3534
apmtest.DiscardTracer,
3635
newTestMonitoringMgr(),
37-
configuration.DefaultGRPCConfig(),
36+
testGrpcConfig(),
3837
false,
3938
)
4039
require.NoError(t, err)

0 commit comments

Comments
 (0)