Skip to content

Commit

Permalink
Add tests for dlq_handler.go (cadence-workflow#6071)
Browse files Browse the repository at this point in the history
* Add tests for dlq_handler.go

What changed?
tests for dlq_handler.go. Moved getInterval function to dlqHandleImpl to allow testing

Why?
improve unit test coverage

How did you test it?
unit tests

Potential risks

Release notes

Documentation Changes
  • Loading branch information
fimanishi authored and timl3136 committed Jun 6, 2024
1 parent 1625a3c commit 30e9c3c
Show file tree
Hide file tree
Showing 2 changed files with 375 additions and 16 deletions.
9 changes: 6 additions & 3 deletions service/history/replication/dlq_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (

"github.com/uber/cadence/common"
"github.com/uber/cadence/common/backoff"
"github.com/uber/cadence/common/clock"
"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/log/tag"
"github.com/uber/cadence/common/metrics"
Expand Down Expand Up @@ -82,6 +83,7 @@ type (
metricsClient metrics.Client
done chan struct{}
status int32
timeSource clock.TimeSource

mu sync.Mutex
latestCounts map[string]int64
Expand All @@ -106,6 +108,7 @@ func NewDLQHandler(
logger: shard.GetLogger(),
metricsClient: shard.GetMetricsClient(),
done: make(chan struct{}),
timeSource: clock.NewRealTimeSource(),
}
}

Expand Down Expand Up @@ -176,12 +179,12 @@ func (r *dlqHandlerImpl) emitDLQSizeMetricsLoop() {
)
}

timer := time.NewTimer(getInterval())
timer := r.timeSource.NewTimer(getInterval())
defer timer.Stop()

for {
select {
case <-timer.C:
case <-timer.Chan():
r.fetchAndEmitMessageCount(context.Background())
timer.Reset(getInterval())
case <-r.done:
Expand Down Expand Up @@ -322,7 +325,7 @@ func (r *dlqHandlerImpl) MergeMessages(
}
}

// If hydrated replication task does not exists in remote cluster - continue merging
// If hydrated replication task does not exist in remote cluster - continue merging
// Record lastMessageID with raw task id, so that they can be purged after.
if lastMessageID < raw.TaskID {
lastMessageID = raw.TaskID
Expand Down
Loading

0 comments on commit 30e9c3c

Please sign in to comment.