Skip to content

Commit

Permalink
Added test for HistoryStats and ExecutionStats for history execution (c…
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekj720 authored May 13, 2024
1 parent 6108a44 commit 3c0991d
Showing 1 changed file with 70 additions and 0 deletions.
70 changes: 70 additions & 0 deletions service/history/execution/context_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/uber/cadence/common/dynamicconfig"
"github.com/uber/cadence/common/log"
"github.com/uber/cadence/common/metrics"
"github.com/uber/cadence/common/metrics/mocks"
"github.com/uber/cadence/common/persistence"
"github.com/uber/cadence/service/history/config"
"github.com/uber/cadence/service/history/shard"
Expand Down Expand Up @@ -127,3 +128,72 @@ func TestEmitLargeWorkflowShardIDStats(t *testing.T) {
})
}
}

func TestEmitWorkflowHistoryStats(t *testing.T) {

mockMetricsClient := new(mocks.Client)
mockScope := new(mocks.Scope)

mockMetricsClient.On("Scope", mock.Anything, mock.Anything).Return(mockScope)

mockScope.On("RecordTimer", mock.Anything, mock.Anything).Return()

domainName := "testDomain"
historySize := 2048
historyCount := 150

emitWorkflowHistoryStats(mockMetricsClient, domainName, historySize, historyCount)

mockMetricsClient.AssertExpectations(t)
mockScope.AssertExpectations(t)
}

func TestEmitWorkflowExecutionStats(t *testing.T) {
tests := []struct {
name string
domainName string
stats *persistence.MutableStateStats
historySize int64
expectCalls bool
}{
{
name: "With valid stats",
domainName: "testDomain",
stats: &persistence.MutableStateStats{
MutableStateSize: 1024,
ActivityInfoSize: 256,
TimerInfoSize: 128,
},
historySize: 2048,
expectCalls: true,
},
{
name: "Nil stats",
domainName: "testDomain",
stats: nil,
historySize: 2048,
expectCalls: false,
},
}

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {

mockMetricsClient := new(mocks.Client)
mockScope := new(mocks.Scope)

if tc.expectCalls {
mockMetricsClient.On("Scope", metrics.ExecutionSizeStatsScope, mock.Anything).Return(mockScope)
mockMetricsClient.On("Scope", metrics.ExecutionCountStatsScope, mock.Anything).Return(mockScope)
mockScope.On("RecordTimer", mock.AnythingOfType("int"), mock.AnythingOfType("time.Duration")).Return().Times(14)
} else {
mockScope.AssertNotCalled(t, "RecordTimer")
}

emitWorkflowExecutionStats(mockMetricsClient, tc.domainName, tc.stats, tc.historySize)

mockMetricsClient.AssertExpectations(t)
mockScope.AssertExpectations(t)
})
}
}

0 comments on commit 3c0991d

Please sign in to comment.