From 0d5ad364e6920e4a4c6c9ddda895cbfc1aab27d3 Mon Sep 17 00:00:00 2001 From: Vsevolod Kaloshin Date: Fri, 22 Dec 2023 15:30:24 +0100 Subject: [PATCH] add unit tests for WorkflowIDToHistoryShard and DomainIDToHistoryShard (#5533) --- common/util_test.go | 50 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/common/util_test.go b/common/util_test.go index bc8f5dc8cbd..533e0a46fac 100644 --- a/common/util_test.go +++ b/common/util_test.go @@ -707,3 +707,53 @@ func TestConvertGetTaskFailedCauseToErr(t *testing.T) { }) } } + +func TestWorkflowIDToHistoryShard(t *testing.T) { + for _, c := range []struct { + workflowID string + numberOfShards int + + want int + }{ + { + workflowID: "", + numberOfShards: 1000, + want: 242, + }, + { + workflowID: "workflowId", + numberOfShards: 1000, + want: 580, + }, + } { + t.Run(fmt.Sprintf("%s-%v", c.workflowID, c.numberOfShards), func(t *testing.T) { + got := WorkflowIDToHistoryShard(c.workflowID, c.numberOfShards) + require.Equal(t, c.want, got) + }) + } +} + +func TestDomainIDToHistoryShard(t *testing.T) { + for _, c := range []struct { + domainID string + numberOfShards int + + want int + }{ + { + domainID: "", + numberOfShards: 1000, + want: 242, + }, + { + domainID: "domainId", + numberOfShards: 1000, + want: 600, + }, + } { + t.Run(fmt.Sprintf("%s-%v", c.domainID, c.numberOfShards), func(t *testing.T) { + got := DomainIDToHistoryShard(c.domainID, c.numberOfShards) + require.Equal(t, c.want, got) + }) + } +}