Skip to content

Commit

Permalink
Fix dataObject/search attributes bugs of overriding each others (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
longquanzheng authored Feb 7, 2023
1 parent 9d08d3b commit af20271
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 16 deletions.
7 changes: 7 additions & 0 deletions integ/persistence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ func TestPersistenceWorkflow(t *testing.T) {
dos[testDataObjectKey].Get(&do)
assert.Equal(t, wfId, do.StrValue)

dos, err = client.GetAllWorkflowDataObjects(context.Background(), wfId, "")
assert.Nil(t, err)
assert.Equal(t, 2, len(dos))
var str string
dos[testDataObjectKey2].Get(&str)
assert.Equal(t, "a string", str)

sas, err := client.GetWorkflowSearchAttributes(context.Background(), &persistenceWorkflow{}, wfId, "", []string{
testSearchAttributeKeyword,
testSearchAttributeText,
Expand Down
4 changes: 3 additions & 1 deletion integ/persistence_workflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ type persistenceWorkflow struct {
}

const (
testDataObjectKey = "test-data-object"
testDataObjectKey = "test-data-object"
testDataObjectKey2 = "test-data-object-2"

testSearchAttributeInt = "CustomIntField"
testSearchAttributeDatetime = "CustomDatetimeField"
Expand All @@ -31,6 +32,7 @@ func (b persistenceWorkflow) GetStates() []iwf.StateDef {
func (b persistenceWorkflow) GetPersistenceSchema() []iwf.PersistenceFieldDef {
return []iwf.PersistenceFieldDef{
iwf.DataObjectDef(testDataObjectKey),
iwf.DataObjectDef(testDataObjectKey2),
iwf.SearchAttributeDef(testSearchAttributeInt, iwfidl.INT),
iwf.SearchAttributeDef(testSearchAttributeDatetime, iwfidl.DATETIME),
iwf.SearchAttributeDef(testSearchAttributeBool, iwfidl.BOOL),
Expand Down
7 changes: 7 additions & 0 deletions integ/persistence_workflow_state1.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (b persistenceWorkflowState1) Start(ctx iwf.WorkflowContext, input iwf.Obje
panic("this value should be empty because we haven't set it before")
}
persistence.SetDataObject(testDataObjectKey, do)
persistence.SetDataObject(testDataObjectKey2, "a string")
persistence.SetSearchAttributeInt(testSearchAttributeInt, 1)

return iwf.EmptyCommandRequest(), nil
Expand All @@ -43,6 +44,12 @@ func (b persistenceWorkflowState1) Decide(ctx iwf.WorkflowContext, input iwf.Obj

var do ExampleDataObjectModel
persistence.GetDataObject(testDataObjectKey, &do)
var str string
persistence.GetDataObject(testDataObjectKey2, &str)
if str != "a string" {
panic("testDataObjectKey2 value is incorrect")
}

persistence.SetSearchAttributeDatetime(testSearchAttributeDatetime, do.Datetime)
persistence.SetSearchAttributeBool(testSearchAttributeBool, true)
return iwf.SingleNextState(persistenceWorkflowState2{}, nil), nil
Expand Down
30 changes: 15 additions & 15 deletions iwf/persistence_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,55 +256,55 @@ func (p *persistenceImpl) GetToReturn() (
searchAttributes []iwfidl.SearchAttribute) {
for k, v := range p.dataObjectsToReturn {
dataObjectsToReturn = append(dataObjectsToReturn, iwfidl.KeyValue{
Key: &k,
Value: &v,
Key: ptr.Any(k),
Value: ptr.Any(v),
})
}

for k, v := range p.stateLocalToReturn {
stateLocalToReturn = append(stateLocalToReturn, iwfidl.KeyValue{
Key: &k,
Value: &v,
Key: ptr.Any(k),
Value: ptr.Any(v),
})
}

for k, v := range p.recordedEvents {
recordEvents = append(recordEvents, iwfidl.KeyValue{
Key: &k,
Value: &v,
Key: ptr.Any(k),
Value: ptr.Any(v),
})
}
for k, sa := range p.saIntToReturn {
searchAttributes = append(searchAttributes, iwfidl.SearchAttribute{
Key: &k,
Key: ptr.Any(k),
ValueType: ptr.Any(p.saKeyToType[k]),
IntegerValue: &sa,
IntegerValue: ptr.Any(sa),
})
}
for k, sa := range p.saStringToReturn {
searchAttributes = append(searchAttributes, iwfidl.SearchAttribute{
Key: &k,
Key: ptr.Any(k),
ValueType: ptr.Any(p.saKeyToType[k]),
StringValue: &sa,
StringValue: ptr.Any(sa),
})
}
for k, sa := range p.saDoubleToReturn {
searchAttributes = append(searchAttributes, iwfidl.SearchAttribute{
Key: &k,
Key: ptr.Any(k),
ValueType: ptr.Any(p.saKeyToType[k]),
DoubleValue: &sa,
DoubleValue: ptr.Any(sa),
})
}
for k, sa := range p.saBoolToReturn {
searchAttributes = append(searchAttributes, iwfidl.SearchAttribute{
Key: &k,
Key: ptr.Any(k),
ValueType: ptr.Any(p.saKeyToType[k]),
BoolValue: &sa,
BoolValue: ptr.Any(sa),
})
}
for k, sa := range p.saStrArrToReturn {
searchAttributes = append(searchAttributes, iwfidl.SearchAttribute{
Key: &k,
Key: ptr.Any(k),
ValueType: ptr.Any(p.saKeyToType[k]),
StringArrayValue: sa,
})
Expand Down

0 comments on commit af20271

Please sign in to comment.