Skip to content

Commit dc709a2

Browse files
authored
CHASM: Add more persistence layer tests (#8201)
## What changed? - Add more persistence layer tests for CHASM workloads ## Why? - Persistence requests from CHASM doesn't have event and the version history field in mutable state is also empty. This may break certain persistence implementations. Adding more tests for better coverage. ## How did you test it? - [x] built - [ ] run locally and tested manually - [ ] covered by existing tests - [x] added new unit test(s) - [ ] added new functional test(s)
1 parent 91b6993 commit dc709a2

File tree

2 files changed

+178
-2
lines changed

2 files changed

+178
-2
lines changed

common/persistence/tests/execution_mutable_state.go

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,47 @@ func (s *ExecutionMutableStateSuite) TestCreate_Reuse() {
223223
s.AssertHEEqualWithDB(newBranchToken, newEvents)
224224
}
225225

226+
func (s *ExecutionMutableStateSuite) TestCreate_Reuse_CHASM() {
227+
// CHASM snapshot has no events and empty current version history.
228+
prevLastWriteVersion := rand.Int63()
229+
prevSnapshot := s.CreateCHASMSnapshot(
230+
prevLastWriteVersion,
231+
enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED,
232+
enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
233+
rand.Int63(),
234+
)
235+
236+
newRunID := uuid.New().String()
237+
newSnapshot, newEvents := RandomSnapshot(
238+
s.T(),
239+
s.NamespaceID,
240+
s.WorkflowID,
241+
newRunID,
242+
common.FirstEventID,
243+
rand.Int63(),
244+
enumsspb.WORKFLOW_EXECUTION_STATE_CREATED,
245+
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
246+
rand.Int63(),
247+
nil, // CHASM snapshot has no events
248+
)
249+
s.Empty(newEvents)
250+
251+
_, err := s.ExecutionManager.CreateWorkflowExecution(s.Ctx, &p.CreateWorkflowExecutionRequest{
252+
ShardID: s.ShardID,
253+
RangeID: s.RangeID,
254+
Mode: p.CreateWorkflowModeUpdateCurrent,
255+
256+
PreviousRunID: prevSnapshot.ExecutionState.RunId,
257+
PreviousLastWriteVersion: prevLastWriteVersion,
258+
259+
NewWorkflowSnapshot: *newSnapshot,
260+
NewWorkflowEvents: newEvents,
261+
})
262+
s.NoError(err)
263+
264+
s.AssertMSEqualWithDB(newSnapshot)
265+
}
266+
226267
func (s *ExecutionMutableStateSuite) TestCreate_Reuse_CurrentConflict() {
227268
prevLastWriteVersion := rand.Int63()
228269
branchToken, prevSnapshot, prevEvents := s.CreateWorkflow(
@@ -1403,6 +1444,105 @@ func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew
14031444
s.AssertHEEqualWithDB(branchToken, currentEvents1, currentEvents2)
14041445
}
14051446

1447+
func (s *ExecutionMutableStateSuite) TestConflictResolve_SuppressCurrent_WithNew_CHASM() {
1448+
currentSnapshot := s.CreateCHASMSnapshot(
1449+
rand.Int63(),
1450+
enumsspb.WORKFLOW_EXECUTION_STATE_CREATED,
1451+
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
1452+
rand.Int63(),
1453+
)
1454+
1455+
baseRunID := uuid.New().String()
1456+
baseSnapshot, baseEvents := RandomSnapshot(
1457+
s.T(),
1458+
s.NamespaceID,
1459+
s.WorkflowID,
1460+
baseRunID,
1461+
common.FirstEventID,
1462+
rand.Int63(),
1463+
enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE,
1464+
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
1465+
rand.Int63(),
1466+
nil,
1467+
)
1468+
s.Empty(baseEvents)
1469+
_, err := s.ExecutionManager.CreateWorkflowExecution(s.Ctx, &p.CreateWorkflowExecutionRequest{
1470+
ShardID: s.ShardID,
1471+
RangeID: s.RangeID,
1472+
Mode: p.CreateWorkflowModeBypassCurrent,
1473+
1474+
PreviousRunID: "",
1475+
PreviousLastWriteVersion: 0,
1476+
1477+
NewWorkflowSnapshot: *baseSnapshot,
1478+
NewWorkflowEvents: baseEvents,
1479+
})
1480+
s.NoError(err)
1481+
1482+
resetSnapshot, resetEvents := RandomSnapshot(
1483+
s.T(),
1484+
s.NamespaceID,
1485+
s.WorkflowID,
1486+
baseRunID,
1487+
baseSnapshot.NextEventID,
1488+
rand.Int63(),
1489+
enumsspb.WORKFLOW_EXECUTION_STATE_COMPLETED,
1490+
enumspb.WORKFLOW_EXECUTION_STATUS_COMPLETED,
1491+
baseSnapshot.DBRecordVersion+1,
1492+
nil,
1493+
)
1494+
s.Empty(resetEvents)
1495+
1496+
newRunID := uuid.New().String()
1497+
newSnapshot, newEvents := RandomSnapshot(
1498+
s.T(),
1499+
s.NamespaceID,
1500+
s.WorkflowID,
1501+
newRunID,
1502+
common.FirstEventID,
1503+
rand.Int63(),
1504+
enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING,
1505+
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
1506+
rand.Int63(),
1507+
nil,
1508+
)
1509+
s.Empty(newEvents)
1510+
1511+
currentMutation, currentEvents := RandomMutation(
1512+
s.T(),
1513+
s.NamespaceID,
1514+
s.WorkflowID,
1515+
s.RunID,
1516+
newSnapshot.NextEventID,
1517+
rand.Int63(),
1518+
enumsspb.WORKFLOW_EXECUTION_STATE_ZOMBIE,
1519+
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
1520+
currentSnapshot.DBRecordVersion+1,
1521+
nil,
1522+
)
1523+
s.Empty(currentEvents)
1524+
1525+
_, err = s.ExecutionManager.ConflictResolveWorkflowExecution(s.Ctx, &p.ConflictResolveWorkflowExecutionRequest{
1526+
ShardID: s.ShardID,
1527+
RangeID: s.RangeID,
1528+
Mode: p.ConflictResolveWorkflowModeUpdateCurrent,
1529+
1530+
ResetWorkflowSnapshot: *resetSnapshot,
1531+
ResetWorkflowEvents: resetEvents,
1532+
1533+
NewWorkflowSnapshot: newSnapshot,
1534+
NewWorkflowEvents: newEvents,
1535+
1536+
CurrentWorkflowMutation: currentMutation,
1537+
CurrentWorkflowEvents: currentEvents,
1538+
})
1539+
s.NoError(err)
1540+
1541+
s.AssertMSEqualWithDB(resetSnapshot)
1542+
s.AssertMSEqualWithDB(newSnapshot)
1543+
s.AssertMSEqualWithDB(currentSnapshot, currentMutation)
1544+
}
1545+
14061546
func (s *ExecutionMutableStateSuite) TestConflictResolve_ResetCurrent() {
14071547
branchToken, baseSnapshot, baseEvents := s.CreateWorkflow(
14081548
rand.Int63(),
@@ -1948,6 +2088,37 @@ func (s *ExecutionMutableStateSuite) TestSet() {
19482088
s.AssertHEEqualWithDB(branchToken, events)
19492089
}
19502090

2091+
func (s *ExecutionMutableStateSuite) TestSet_CHASM() {
2092+
snapshot := s.CreateCHASMSnapshot(
2093+
rand.Int63(),
2094+
enumsspb.WORKFLOW_EXECUTION_STATE_CREATED,
2095+
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
2096+
rand.Int63(),
2097+
)
2098+
2099+
setSnapshot, _ := RandomSnapshot(
2100+
s.T(),
2101+
s.NamespaceID,
2102+
s.WorkflowID,
2103+
s.RunID,
2104+
common.FirstEventID,
2105+
rand.Int63(),
2106+
enumsspb.WORKFLOW_EXECUTION_STATE_RUNNING,
2107+
enumspb.WORKFLOW_EXECUTION_STATUS_RUNNING,
2108+
snapshot.DBRecordVersion+1,
2109+
nil, // CHASM snapshot has no events
2110+
)
2111+
_, err := s.ExecutionManager.SetWorkflowExecution(s.Ctx, &p.SetWorkflowExecutionRequest{
2112+
ShardID: s.ShardID,
2113+
RangeID: s.RangeID,
2114+
2115+
SetWorkflowSnapshot: *setSnapshot,
2116+
})
2117+
s.NoError(err)
2118+
2119+
s.AssertMSEqualWithDB(setSnapshot)
2120+
}
2121+
19512122
func (s *ExecutionMutableStateSuite) TestDeleteCurrent_IsCurrent() {
19522123
branchToken, newSnapshot, newEvents := s.CreateWorkflow(
19532124
rand.Int63(),

common/persistence/tests/util.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func RandomSnapshot(
4848
) (*p.WorkflowSnapshot, []*p.WorkflowEvents) {
4949
snapshot := &p.WorkflowSnapshot{
5050
ExecutionInfo: RandomExecutionInfo(namespaceID, workflowID, eventID, lastWriteVersion, branchToken),
51-
ExecutionState: RandomExecutionState(runID, state, status),
51+
ExecutionState: RandomExecutionState(runID, state, status, lastWriteVersion),
5252

5353
NextEventID: eventID + 1, // NOTE: RandomSnapshot generates a single history event, hence NextEventID is plus 1
5454

@@ -98,7 +98,7 @@ func RandomMutation(
9898
) (*p.WorkflowMutation, []*p.WorkflowEvents) {
9999
mutation := &p.WorkflowMutation{
100100
ExecutionInfo: RandomExecutionInfo(namespaceID, workflowID, eventID, lastWriteVersion, branchToken),
101-
ExecutionState: RandomExecutionState(runID, state, status),
101+
ExecutionState: RandomExecutionState(runID, state, status, lastWriteVersion),
102102

103103
NextEventID: eventID + 1, // NOTE: RandomMutation generates a single history event, hence NextEventID is plus 1
104104

@@ -210,13 +210,18 @@ func RandomExecutionState(
210210
runID string,
211211
state enumsspb.WorkflowExecutionState,
212212
status enumspb.WorkflowExecutionStatus,
213+
lastWriteVersion int64,
213214
) *persistencespb.WorkflowExecutionState {
214215
createRequestID := uuid.NewString()
215216
return &persistencespb.WorkflowExecutionState{
216217
CreateRequestId: createRequestID,
217218
RunId: runID,
218219
State: state,
219220
Status: status,
221+
LastUpdateVersionedTransition: &persistencespb.VersionedTransition{
222+
NamespaceFailoverVersion: lastWriteVersion,
223+
TransitionCount: rand.Int63(),
224+
},
220225
RequestIds: map[string]*persistencespb.RequestIDInfo{
221226
createRequestID: {
222227
EventType: enumspb.EVENT_TYPE_WORKFLOW_EXECUTION_STARTED,

0 commit comments

Comments
 (0)