Skip to content

Commit

Permalink
fix bug with reusing heartbeater base in all heartbeaters
Browse files Browse the repository at this point in the history
  • Loading branch information
almostinf committed Nov 8, 2024
1 parent b512b58 commit be63bb9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
7 changes: 5 additions & 2 deletions notifier/selfstate/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,10 @@ func createHearbeaters(
database moira.Database,
clock moira.Clock,
) []heartbeat.Heartbeater {
hearbeaterBase := heartbeat.NewHeartbeaterBase(logger, database, clock)

heartbeaters := make([]heartbeat.Heartbeater, 0)

if heartbeatersCfg.DatabaseCfg.Enabled {
hearbeaterBase := heartbeat.NewHeartbeaterBase(logger, database, clock)
databaseHeartbeater, err := heartbeat.NewDatabaseHeartbeater(heartbeatersCfg.DatabaseCfg, hearbeaterBase)
if err != nil {
logger.Error().
Expand All @@ -115,6 +114,7 @@ func createHearbeaters(
}

if heartbeatersCfg.FilterCfg.Enabled {
hearbeaterBase := heartbeat.NewHeartbeaterBase(logger, database, clock)
filterHeartbeater, err := heartbeat.NewFilterHeartbeater(heartbeatersCfg.FilterCfg, hearbeaterBase)
if err != nil {
logger.Error().
Expand All @@ -127,6 +127,7 @@ func createHearbeaters(
}

if heartbeatersCfg.LocalCheckerCfg.Enabled {
hearbeaterBase := heartbeat.NewHeartbeaterBase(logger, database, clock)
localCheckerHeartbeater, err := heartbeat.NewLocalCheckerHeartbeater(heartbeatersCfg.LocalCheckerCfg, hearbeaterBase)
if err != nil {
logger.Error().
Expand All @@ -139,6 +140,7 @@ func createHearbeaters(
}

if heartbeatersCfg.RemoteCheckerCfg.Enabled {
hearbeaterBase := heartbeat.NewHeartbeaterBase(logger, database, clock)
remoteCheckerHeartbeater, err := heartbeat.NewRemoteCheckerHeartbeater(heartbeatersCfg.RemoteCheckerCfg, hearbeaterBase)
if err != nil {
logger.Error().
Expand All @@ -151,6 +153,7 @@ func createHearbeaters(
}

if heartbeatersCfg.NotifierCfg.Enabled {
hearbeaterBase := heartbeat.NewHeartbeaterBase(logger, database, clock)
notifierHeartbeater, err := heartbeat.NewNotifierHeartbeater(heartbeatersCfg.NotifierCfg, hearbeaterBase)
if err != nil {
logger.Error().
Expand Down
12 changes: 6 additions & 6 deletions notifier/selfstate/monitor/monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestCreateHeartbeaters(t *testing.T) {
Convey("Test createHeartbeaters", t, func() {
Convey("Without any heartbeater", func() {
hbCfg := heartbeat.HeartbeatersConfig{}
mockClock.EXPECT().NowUTC().Return(testTime)
mockClock.EXPECT().NowUTC().Return(testTime).AnyTimes()
heartbeaters := createHearbeaters(hbCfg, mockLogger, mockDatabase, mockClock)
So(heartbeaters, ShouldBeEmpty)
})
Expand All @@ -44,7 +44,7 @@ func TestCreateHeartbeaters(t *testing.T) {
RedisDisconnectDelay: time.Minute,
},
}
mockClock.EXPECT().NowUTC().Return(testTime)
mockClock.EXPECT().NowUTC().Return(testTime).AnyTimes()
heartbeaters := createHearbeaters(hbCfg, mockLogger, mockDatabase, mockClock)
So(heartbeaters, ShouldHaveLength, 1)
})
Expand All @@ -64,7 +64,7 @@ func TestCreateHeartbeaters(t *testing.T) {
MetricReceivedDelay: time.Minute,
},
}
mockClock.EXPECT().NowUTC().Return(testTime)
mockClock.EXPECT().NowUTC().Return(testTime).AnyTimes()
heartbeaters := createHearbeaters(hbCfg, mockLogger, mockDatabase, mockClock)
So(heartbeaters, ShouldHaveLength, 2)
})
Expand All @@ -90,7 +90,7 @@ func TestCreateHeartbeaters(t *testing.T) {
LocalCheckDelay: time.Minute,
},
}
mockClock.EXPECT().NowUTC().Return(testTime)
mockClock.EXPECT().NowUTC().Return(testTime).AnyTimes()
heartbeaters := createHearbeaters(hbCfg, mockLogger, mockDatabase, mockClock)
So(heartbeaters, ShouldHaveLength, 3)
})
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestCreateHeartbeaters(t *testing.T) {
RemoteCheckDelay: time.Minute,
},
}
mockClock.EXPECT().NowUTC().Return(testTime)
mockClock.EXPECT().NowUTC().Return(testTime).AnyTimes()
heartbeaters := createHearbeaters(hbCfg, mockLogger, mockDatabase, mockClock)
So(heartbeaters, ShouldHaveLength, 4)
})
Expand Down Expand Up @@ -159,7 +159,7 @@ func TestCreateHeartbeaters(t *testing.T) {
},
},
}
mockClock.EXPECT().NowUTC().Return(testTime)
mockClock.EXPECT().NowUTC().Return(testTime).AnyTimes()
heartbeaters := createHearbeaters(hbCfg, mockLogger, mockDatabase, mockClock)
So(heartbeaters, ShouldHaveLength, 5)
})
Expand Down

0 comments on commit be63bb9

Please sign in to comment.