Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix merge map of payload #3412

Merged
merged 1 commit into from
Sep 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions common/payload/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,13 @@ func MergeMapOfPayload(
m1 map[string]*commonpb.Payload,
m2 map[string]*commonpb.Payload,
) map[string]*commonpb.Payload {
if m1 == nil {
return maps.Clone(m2)
if m2 == nil {
return maps.Clone(m1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just return m1 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I think I could. But thought about what if it's changed outside after this function is called. It would change the map reference, and have unexpected side effects maybe. I don't know, just thought it would be safer like this.

}
ret := maps.Clone(m1)
if ret == nil {
ret = make(map[string]*commonpb.Payload)
}
for k, v := range m2 {
if proto.Equal(v, nilPayload) || proto.Equal(v, emptySlicePayload) {
delete(ret, k)
Expand Down
12 changes: 12 additions & 0 deletions common/payload/payload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,22 @@ func TestMergeMapOfPayload(t *testing.T) {
resultMap := MergeMapOfPayload(currentMap, newMap)
assert.Equal(newMap, resultMap)

newMap = make(map[string]*commonpb.Payload)
resultMap = MergeMapOfPayload(currentMap, newMap)
assert.Equal(newMap, resultMap)

newMap = map[string]*commonpb.Payload{"key": EncodeString("val")}
resultMap = MergeMapOfPayload(currentMap, newMap)
assert.Equal(newMap, resultMap)

newMap = map[string]*commonpb.Payload{
"key": EncodeString("val"),
"nil": nilPayload,
"emptyArray": emptySlicePayload,
}
resultMap = MergeMapOfPayload(currentMap, newMap)
assert.Equal(map[string]*commonpb.Payload{"key": EncodeString("val")}, resultMap)

currentMap = map[string]*commonpb.Payload{"number": EncodeString("1")}
resultMap = MergeMapOfPayload(currentMap, newMap)
assert.Equal(
Expand Down
29 changes: 29 additions & 0 deletions host/elasticsearch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1333,6 +1333,35 @@ func (s *elasticsearchIntegrationSuite) TestUpsertWorkflowExecutionSearchAttribu
time.Sleep(waitTimeInMs * time.Millisecond)
}
s.True(verified)

// verify search attributes from DescribeWorkflowExecution
descRequest := &workflowservice.DescribeWorkflowExecutionRequest{
Namespace: s.namespace,
Execution: &commonpb.WorkflowExecution{
WorkflowId: id,
},
}
descResp, err := s.engine.DescribeWorkflowExecution(NewContext(), descRequest)
s.NoError(err)
expectedSearchAttributes, _ := searchattribute.Encode(
map[string]interface{}{
"CustomDoubleField": 22.0878,
searchattribute.BinaryChecksums: []string{"binary-v1", "binary-v2"},
},
nil,
)
s.Equal(
len(expectedSearchAttributes.GetIndexedFields()),
len(descResp.WorkflowExecutionInfo.GetSearchAttributes().GetIndexedFields()),
)
for attrName, expectedPayload := range expectedSearchAttributes.GetIndexedFields() {
respAttr, ok := descResp.WorkflowExecutionInfo.GetSearchAttributes().GetIndexedFields()[attrName]
s.True(ok)
s.Equal(expectedPayload.GetData(), respAttr.GetData())
attrType, typeSet := respAttr.GetMetadata()[searchattribute.MetadataType]
s.True(typeSet)
s.True(len(attrType) > 0)
}
}

func (s *elasticsearchIntegrationSuite) TestModifyWorkflowExecutionProperties() {
Expand Down