Skip to content

Commit

Permalink
add reaper frequency test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tamirms committed Jun 24, 2024
1 parent 31329aa commit 20ae45a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services/horizon/internal/ingest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ func (s *system) runStateMachine(cur stateMachineNode) error {
}

func (s *system) maybeReapHistory(lastIngestedLedger uint32) {
if s.config.ReapConfig.Frequency == 0 || lastIngestedLedger%uint32(s.config.ReapConfig.Frequency) != 0 {
if s.reaper.config.Frequency == 0 || lastIngestedLedger%uint32(s.reaper.config.Frequency) != 0 {
return
}
s.wg.Add(1)
Expand Down
24 changes: 24 additions & 0 deletions services/horizon/internal/ingest/reap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (t *ReaperTestSuite) SetupTest() {
t.reaper = newReaper(ReapConfig{
RetentionCount: 30,
BatchSize: 10,
Frequency: 7,
}, t.historyQ, t.reapLockQ)
t.prevSleep = sleep
sleep = 0
Expand Down Expand Up @@ -126,6 +127,29 @@ func (t *ReaperTestSuite) TestInProgress() {
)
}

func (t *ReaperTestSuite) TestReaperInvokedOnMatchingLedger() {
s := &system{
ctx: t.ctx,
reaper: t.reaper,
}
assertMocksInOrder(
t.reapLockQ.On("Begin", t.ctx).Return(nil).Once(),
t.reapLockQ.On("TryReaperLock", t.ctx).Return(false, nil).Once(),
t.reapLockQ.On("Rollback").Return(nil).Once(),
)
s.maybeReapHistory(49)
s.wg.Wait()
}

func (t *ReaperTestSuite) TestReaperIgnoredOnMismatchingLedger() {
s := &system{
ctx: t.ctx,
reaper: t.reaper,
}
s.maybeReapHistory(48)
s.wg.Wait()
}

func (t *ReaperTestSuite) TestLatestLedgerTooSmall() {
assertMocksInOrder(
t.reapLockQ.On("Begin", t.ctx).Return(nil).Once(),
Expand Down
1 change: 1 addition & 0 deletions services/horizon/internal/ingest/resume_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func (s *ResumeTestTestSuite) SetupTest() {
ledgerBackend: s.ledgerBackend,
stellarCoreClient: s.stellarCoreClient,
runStateVerificationOnLedger: ledgerEligibleForStateVerification(64, 1),
reaper: &Reaper{},
}
s.system.initMetrics()

Expand Down

0 comments on commit 20ae45a

Please sign in to comment.