Skip to content

Commit

Permalink
added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amirylm committed Mar 13, 2024
1 parent 1e6b852 commit e8d2266
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func (ub *upkeepLogBuffer) enqueue(blockThreshold int64, logsToAdd ...logpoller.
ub.q = logs
dropped := ub.clean(blockThreshold)

ub.lggr.Debugf("Enqueued %d logs, dropped %d", added, dropped)
ub.lggr.Debugf("Enqueued %d logs, dropped %d with blockThreshold %d", added, dropped, blockThreshold)
prommetrics.AutomationLogsInLogBuffer.Add(float64(added))

return added, dropped
Expand Down Expand Up @@ -318,6 +318,9 @@ func (ub *upkeepLogBuffer) clean(blockThreshold int64) int {
delete(ub.visited, logid)
}
}

ub.lggr.Debugw("Cleaned logs", "dropped", dropped, "blockThreshold", blockThreshold, "len updated", len(updated), "len ub.q", len(ub.q), "maxLogs", maxLogs)

ub.q = updated

for lid, block := range ub.visited {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,40 @@ func TestLogEventBufferV2_EnqueueDequeue(t *testing.T) {
require.Equal(t, 2, upkeepBuf.size())
})

t.Run("enqueue upkeeps limits", func(t *testing.T) {
buf := NewLogBuffer(logger.TestLogger(t), 3, 2)

added, dropped := buf.Enqueue(big.NewInt(1),
logpoller.Log{BlockNumber: 9, TxHash: common.HexToHash("0x9"), LogIndex: 0},
logpoller.Log{BlockNumber: 9, TxHash: common.HexToHash("0x9"), LogIndex: 1},
logpoller.Log{BlockNumber: 10, TxHash: common.HexToHash("0x10"), LogIndex: 0},
logpoller.Log{BlockNumber: 10, TxHash: common.HexToHash("0x10"), LogIndex: 1},
logpoller.Log{BlockNumber: 11, TxHash: common.HexToHash("0x11"), LogIndex: 1},
logpoller.Log{BlockNumber: 11, TxHash: common.HexToHash("0x11"), LogIndex: 2},
logpoller.Log{BlockNumber: 11, TxHash: common.HexToHash("0x11"), LogIndex: 3},
)
require.Equal(t, 7, added)
require.Equal(t, 1, dropped)
upkeepBuf, ok := buf.(*logBuffer).getUpkeepBuffer(big.NewInt(1))
require.True(t, ok)
require.Equal(t, 6, upkeepBuf.size())
})

t.Run("enqueue out of block range", func(t *testing.T) {
buf := NewLogBuffer(logger.TestLogger(t), 5, 4)

added, dropped := buf.Enqueue(big.NewInt(1),
logpoller.Log{BlockNumber: 1, TxHash: common.HexToHash("0x10"), LogIndex: 0},
logpoller.Log{BlockNumber: 10, TxHash: common.HexToHash("0x10"), LogIndex: 1},
logpoller.Log{BlockNumber: 11, TxHash: common.HexToHash("0x11"), LogIndex: 1},
)
require.Equal(t, 2, added)
require.Equal(t, 0, dropped)
upkeepBuf, ok := buf.(*logBuffer).getUpkeepBuffer(big.NewInt(1))
require.True(t, ok)
require.Equal(t, 2, upkeepBuf.size())
})

t.Run("enqueue dequeue", func(t *testing.T) {
buf := NewLogBuffer(logger.TestLogger(t), 10, 10)

Expand Down

0 comments on commit e8d2266

Please sign in to comment.