Skip to content

Commit 61fd87b

Browse files
Fix domain check in replay (#778)
* Fix domain check in replay * add unit test
1 parent c99ffab commit 61fd87b

File tree

3 files changed

+305
-6
lines changed

3 files changed

+305
-6
lines changed

internal/internal_task_handlers.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ func isDecisionMatchEvent(d *s.Decision, e *s.HistoryEvent, strictMode bool) boo
12221222
}
12231223
eventAttributes := e.RequestCancelExternalWorkflowExecutionInitiatedEventAttributes
12241224
decisionAttributes := d.RequestCancelExternalWorkflowExecutionDecisionAttributes
1225-
if checkIfDecisionDomainMatchEventDomain(eventAttributes.GetDomain(), decisionAttributes.GetDomain()) ||
1225+
if checkDomainsInDecisionAndEvent(eventAttributes.GetDomain(), decisionAttributes.GetDomain()) ||
12261226
eventAttributes.WorkflowExecution.GetWorkflowId() != decisionAttributes.GetWorkflowId() {
12271227
return false
12281228
}
@@ -1235,7 +1235,7 @@ func isDecisionMatchEvent(d *s.Decision, e *s.HistoryEvent, strictMode bool) boo
12351235
}
12361236
eventAttributes := e.SignalExternalWorkflowExecutionInitiatedEventAttributes
12371237
decisionAttributes := d.SignalExternalWorkflowExecutionDecisionAttributes
1238-
if checkIfDecisionDomainMatchEventDomain(eventAttributes.GetDomain(), decisionAttributes.GetDomain()) ||
1238+
if checkDomainsInDecisionAndEvent(eventAttributes.GetDomain(), decisionAttributes.GetDomain()) ||
12391239
eventAttributes.GetSignalName() != decisionAttributes.GetSignalName() ||
12401240
eventAttributes.WorkflowExecution.GetWorkflowId() != decisionAttributes.Execution.GetWorkflowId() {
12411241
return false
@@ -1270,7 +1270,7 @@ func isDecisionMatchEvent(d *s.Decision, e *s.HistoryEvent, strictMode bool) boo
12701270
eventAttributes := e.StartChildWorkflowExecutionInitiatedEventAttributes
12711271
decisionAttributes := d.StartChildWorkflowExecutionDecisionAttributes
12721272
if lastPartOfName(eventAttributes.WorkflowType.GetName()) != lastPartOfName(decisionAttributes.WorkflowType.GetName()) ||
1273-
(strictMode && checkIfDecisionDomainMatchEventDomain(eventAttributes.GetDomain(), decisionAttributes.GetDomain())) ||
1273+
(strictMode && checkDomainsInDecisionAndEvent(eventAttributes.GetDomain(), decisionAttributes.GetDomain())) ||
12741274
(strictMode && eventAttributes.TaskList.GetName() != decisionAttributes.TaskList.GetName()) {
12751275
return false
12761276
}
@@ -1281,11 +1281,15 @@ func isDecisionMatchEvent(d *s.Decision, e *s.HistoryEvent, strictMode bool) boo
12811281
return false
12821282
}
12831283

1284-
func checkIfDecisionDomainMatchEventDomain(eventDomainName, decisionDomainName string) bool {
1284+
// return true if the check fails:
1285+
// domain is not empty in decision
1286+
// and domain is not replayDomain
1287+
// and domains unmatch in decision and events
1288+
func checkDomainsInDecisionAndEvent(eventDomainName, decisionDomainName string) bool {
12851289
if decisionDomainName == "" || IsReplayDomain(decisionDomainName) {
1286-
return true
1290+
return false
12871291
}
1288-
return eventDomainName == decisionDomainName
1292+
return eventDomainName != decisionDomainName
12891293
}
12901294

12911295
func (wth *workflowTaskHandlerImpl) completeWorkflow(

internal/internal_worker_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func init() {
5252
RegisterWorkflow(testReplayWorkflow)
5353
RegisterWorkflow(testReplayWorkflow_LocalActivity)
5454
RegisterWorkflow(testReplayWorkflowFromFile)
55+
RegisterWorkflow(testReplayWorkflowFromFileParent)
5556
RegisterActivityWithOptions(
5657
testActivity,
5758
RegisterActivityOptions{Name: "testActivity"},
@@ -155,6 +156,25 @@ func testReplayWorkflowFromFile(ctx Context) error {
155156
return err
156157
}
157158

159+
func testReplayWorkflowFromFileParent(ctx Context) error {
160+
execution := GetWorkflowInfo(ctx).WorkflowExecution
161+
childID := fmt.Sprintf("child_workflow:%v", execution.RunID)
162+
cwo := ChildWorkflowOptions{
163+
WorkflowID: childID,
164+
ExecutionStartToCloseTimeout: time.Minute,
165+
}
166+
ctx = WithChildWorkflowOptions(ctx, cwo)
167+
var result string
168+
cwf := ExecuteChildWorkflow(ctx, testReplayWorkflowFromFile)
169+
f1 := cwf.SignalChildWorkflow(ctx, "test-signal", "test-data")
170+
err := f1.Get(ctx, nil)
171+
err = cwf.Get(ctx, &result)
172+
if err != nil {
173+
return err
174+
}
175+
return nil
176+
}
177+
158178
func testActivity(ctx context.Context) error {
159179
return nil
160180
}
@@ -288,6 +308,12 @@ func (s *internalWorkerTestSuite) TestReplayWorkflowHistory_LocalActivity_Activi
288308
require.Error(s.T(), err)
289309
}
290310

311+
func (s *internalWorkerTestSuite) TestReplayWorkflowHistoryFromFileParent() {
312+
logger := getLogger()
313+
err := ReplayWorkflowHistoryFromJSONFile(logger, "testdata/parentWF.json")
314+
require.NoError(s.T(), err)
315+
}
316+
291317
func (s *internalWorkerTestSuite) TestReplayWorkflowHistoryFromFile() {
292318
logger := getLogger()
293319
err := ReplayWorkflowHistoryFromJSONFile(logger, "testdata/sampleHistory.json")

internal/testdata/parentWF.json

Lines changed: 269 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,269 @@
1+
[{
2+
"eventId": 1,
3+
"timestamp": 1561506494525296000,
4+
"eventType": "WorkflowExecutionStarted",
5+
"version": -24,
6+
"taskId": 50331648,
7+
"workflowExecutionStartedEventAttributes": {
8+
"workflowType": {
9+
"name": "go.uber.org/cadence/internal.testReplayWorkflowFromFileParent"
10+
},
11+
"taskList": {
12+
"name": "childWorkflowGroup"
13+
},
14+
"executionStartToCloseTimeoutSeconds": 60,
15+
"taskStartToCloseTimeoutSeconds": 60,
16+
"originalExecutionRunId": "0ea65eda-a0db-4a59-bef3-dce48e8484f8",
17+
"identity": "10773@longer-C02V60N3HTDG@",
18+
"attempt": 0,
19+
"cronSchedule": "",
20+
"firstDecisionTaskBackoffSeconds": 0,
21+
"header": {}
22+
}
23+
}, {
24+
"eventId": 2,
25+
"timestamp": 1561506494525315000,
26+
"eventType": "DecisionTaskScheduled",
27+
"version": -24,
28+
"taskId": 50331649,
29+
"decisionTaskScheduledEventAttributes": {
30+
"taskList": {
31+
"name": "childWorkflowGroup"
32+
},
33+
"startToCloseTimeoutSeconds": 60,
34+
"attempt": 0
35+
}
36+
}, {
37+
"eventId": 3,
38+
"timestamp": 1561506524119673000,
39+
"eventType": "DecisionTaskStarted",
40+
"version": -24,
41+
"taskId": 50331654,
42+
"decisionTaskStartedEventAttributes": {
43+
"scheduledEventId": 2,
44+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
45+
"requestId": "0a2af0a8-333d-43f2-8a52-716effaf9a5c"
46+
}
47+
}, {
48+
"eventId": 4,
49+
"timestamp": 1561506524134556000,
50+
"eventType": "DecisionTaskCompleted",
51+
"version": -24,
52+
"taskId": 50331657,
53+
"decisionTaskCompletedEventAttributes": {
54+
"scheduledEventId": 2,
55+
"startedEventId": 3,
56+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
57+
"binaryChecksum": "445b7fb4d6c34a010ca01a41e88cc621"
58+
}
59+
}, {
60+
"eventId": 5,
61+
"timestamp": 1561506524134580000,
62+
"eventType": "StartChildWorkflowExecutionInitiated",
63+
"version": -24,
64+
"taskId": 50331658,
65+
"startChildWorkflowExecutionInitiatedEventAttributes": {
66+
"domain": "samples-domain",
67+
"workflowId": "child_workflow:0ea65eda-a0db-4a59-bef3-dce48e8484f8",
68+
"workflowType": {
69+
"name": "go.uber.org/cadence/internal.testReplayWorkflowFromFile"
70+
},
71+
"taskList": {
72+
"name": "childWorkflowGroup"
73+
},
74+
"input": "MAo1Cg==",
75+
"executionStartToCloseTimeoutSeconds": 60,
76+
"taskStartToCloseTimeoutSeconds": 10,
77+
"childPolicy": "TERMINATE",
78+
"decisionTaskCompletedEventId": 4,
79+
"workflowIdReusePolicy": "AllowDuplicateFailedOnly",
80+
"header": {}
81+
}
82+
}, {
83+
"eventId": 6,
84+
"timestamp": 1561506524150629000,
85+
"eventType": "ChildWorkflowExecutionStarted",
86+
"version": -24,
87+
"taskId": 50331660,
88+
"childWorkflowExecutionStartedEventAttributes": {
89+
"domain": "samples-domain",
90+
"initiatedEventId": 5,
91+
"workflowExecution": {
92+
"workflowId": "child_workflow:0ea65eda-a0db-4a59-bef3-dce48e8484f8",
93+
"runId": "105dcb3a-c813-43ea-9d8e-da8731a9110c"
94+
},
95+
"workflowType": {
96+
"name": "main.SampleChildWorkflow"
97+
},
98+
"header": {}
99+
}
100+
}, {
101+
"eventId": 7,
102+
"timestamp": 1561506524150637000,
103+
"eventType": "DecisionTaskScheduled",
104+
"version": -24,
105+
"taskId": 50331663,
106+
"decisionTaskScheduledEventAttributes": {
107+
"taskList": {
108+
"name": "longer-C02V60N3HTDG:3abcb72a-67e1-4f91-b742-83e7577c157c"
109+
},
110+
"startToCloseTimeoutSeconds": 60,
111+
"attempt": 0
112+
}
113+
}, {
114+
"eventId": 8,
115+
"timestamp": 1561506524166038000,
116+
"eventType": "DecisionTaskStarted",
117+
"version": -24,
118+
"taskId": 50331667,
119+
"decisionTaskStartedEventAttributes": {
120+
"scheduledEventId": 7,
121+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
122+
"requestId": "66b33286-99e6-4ec4-be2c-2aa15b6e3a42"
123+
}
124+
}, {
125+
"eventId": 9,
126+
"timestamp": 1561506524177688000,
127+
"eventType": "DecisionTaskCompleted",
128+
"version": -24,
129+
"taskId": 50331670,
130+
"decisionTaskCompletedEventAttributes": {
131+
"scheduledEventId": 7,
132+
"startedEventId": 8,
133+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
134+
"binaryChecksum": "445b7fb4d6c34a010ca01a41e88cc621"
135+
}
136+
}, {
137+
"eventId": 10,
138+
"timestamp": 1561506524177725000,
139+
"eventType": "SignalExternalWorkflowExecutionInitiated",
140+
"version": -24,
141+
"taskId": 50331671,
142+
"signalExternalWorkflowExecutionInitiatedEventAttributes": {
143+
"decisionTaskCompletedEventId": 9,
144+
"domain": "samples-domain",
145+
"workflowExecution": {
146+
"workflowId": "child_workflow:0ea65eda-a0db-4a59-bef3-dce48e8484f8",
147+
"runId": ""
148+
},
149+
"signalName": "test-signal",
150+
"input": "InRlc3QtZGF0YSIK",
151+
"control": "MA==",
152+
"childWorkflowOnly": true
153+
}
154+
}, {
155+
"eventId": 11,
156+
"timestamp": 1561506524254684000,
157+
"eventType": "ExternalWorkflowExecutionSignaled",
158+
"version": -24,
159+
"taskId": 50331673,
160+
"externalWorkflowExecutionSignaledEventAttributes": {
161+
"initiatedEventId": 10,
162+
"domain": "2896806f-7a10-47d0-b963-ad80dc5df011",
163+
"workflowExecution": {
164+
"workflowId": "child_workflow:0ea65eda-a0db-4a59-bef3-dce48e8484f8",
165+
"runId": ""
166+
},
167+
"control": "MA=="
168+
}
169+
}, {
170+
"eventId": 12,
171+
"timestamp": 1561506524254689000,
172+
"eventType": "DecisionTaskScheduled",
173+
"version": -24,
174+
"taskId": 50331676,
175+
"decisionTaskScheduledEventAttributes": {
176+
"taskList": {
177+
"name": "longer-C02V60N3HTDG:3abcb72a-67e1-4f91-b742-83e7577c157c"
178+
},
179+
"startToCloseTimeoutSeconds": 60,
180+
"attempt": 0
181+
}
182+
}, {
183+
"eventId": 13,
184+
"timestamp": 1561506524259702000,
185+
"eventType": "DecisionTaskStarted",
186+
"version": -24,
187+
"taskId": 50331680,
188+
"decisionTaskStartedEventAttributes": {
189+
"scheduledEventId": 12,
190+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
191+
"requestId": "e8162676-7d86-4cea-ba21-2f5ea97835ef"
192+
}
193+
}, {
194+
"eventId": 14,
195+
"timestamp": 1561506524264877000,
196+
"eventType": "DecisionTaskCompleted",
197+
"version": -24,
198+
"taskId": 50331683,
199+
"decisionTaskCompletedEventAttributes": {
200+
"scheduledEventId": 12,
201+
"startedEventId": 13,
202+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
203+
"binaryChecksum": "445b7fb4d6c34a010ca01a41e88cc621"
204+
}
205+
}, {
206+
"eventId": 15,
207+
"timestamp": 1561506524402360000,
208+
"eventType": "ChildWorkflowExecutionCompleted",
209+
"version": -24,
210+
"taskId": 50331684,
211+
"childWorkflowExecutionCompletedEventAttributes": {
212+
"result": "IkNoaWxkIHdvcmtmbG93IGV4ZWN1dGlvbiBjb21wbGV0ZWQgYWZ0ZXIgNSBydW5zIgo=",
213+
"domain": "samples-domain",
214+
"workflowExecution": {
215+
"workflowId": "child_workflow:0ea65eda-a0db-4a59-bef3-dce48e8484f8",
216+
"runId": "1c4e88cc-37fa-4cd1-82b5-997c4c746678"
217+
},
218+
"workflowType": {
219+
"name": "main.SampleChildWorkflow"
220+
},
221+
"initiatedEventId": 5,
222+
"startedEventId": 6
223+
}
224+
}, {
225+
"eventId": 16,
226+
"timestamp": 1561506524402364000,
227+
"eventType": "DecisionTaskScheduled",
228+
"version": -24,
229+
"taskId": 50331687,
230+
"decisionTaskScheduledEventAttributes": {
231+
"taskList": {
232+
"name": "longer-C02V60N3HTDG:3abcb72a-67e1-4f91-b742-83e7577c157c"
233+
},
234+
"startToCloseTimeoutSeconds": 60,
235+
"attempt": 0
236+
}
237+
}, {
238+
"eventId": 17,
239+
"timestamp": 1561506524410406000,
240+
"eventType": "DecisionTaskStarted",
241+
"version": -24,
242+
"taskId": 50331691,
243+
"decisionTaskStartedEventAttributes": {
244+
"scheduledEventId": 16,
245+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
246+
"requestId": "06c6589a-29e6-405c-a28d-9d6466998b69"
247+
}
248+
}, {
249+
"eventId": 18,
250+
"timestamp": 1561506524417332000,
251+
"eventType": "DecisionTaskCompleted",
252+
"version": -24,
253+
"taskId": 50331694,
254+
"decisionTaskCompletedEventAttributes": {
255+
"scheduledEventId": 16,
256+
"startedEventId": 17,
257+
"identity": "10816@longer-C02V60N3HTDG@childWorkflowGroup",
258+
"binaryChecksum": "445b7fb4d6c34a010ca01a41e88cc621"
259+
}
260+
}, {
261+
"eventId": 19,
262+
"timestamp": 1561506524417344000,
263+
"eventType": "WorkflowExecutionCompleted",
264+
"version": -24,
265+
"taskId": 50331695,
266+
"workflowExecutionCompletedEventAttributes": {
267+
"decisionTaskCompletedEventId": 18
268+
}
269+
}]

0 commit comments

Comments
 (0)