• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

uber / cadence / 018ecf37-6c70-46a8-8890-f48c24c91b7e

11 Apr 2024 10:11PM UTC coverage: 67.347% (-0.01%) from 67.357%
018ecf37-6c70-46a8-8890-f48c24c91b7e

push

buildkite

web-flow
Persist workflow request ids into Cassandra (#5826)

285 of 484 new or added lines in 7 files covered. (58.88%)

33 existing lines in 13 files now uncovered.

98455 of 146191 relevant lines covered (67.35%)

2396.87 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/common/persistence/persistence-tests/executionManagerTest.go
1
// Copyright (c) 2017-2020 Uber Technologies, Inc.
2
// Portions of the Software are attributed to Copyright (c) 2020 Temporal Technologies Inc.
3
//
4
// Permission is hereby granted, free of charge, to any person obtaining a copy
5
// of this software and associated documentation files (the "Software"), to deal
6
// in the Software without restriction, including without limitation the rights
7
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
// copies of the Software, and to permit persons to whom the Software is
9
// furnished to do so, subject to the following conditions:
10
//
11
// The above copyright notice and this permission notice shall be included in
12
// all copies or substantial portions of the Software.
13
//
14
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
// THE SOFTWARE.
21

22
package persistencetests
23

24
import (
25
        "context"
26
        "encoding/json"
27
        "fmt"
28
        "log"
29
        "math"
30
        "math/rand"
31
        "os"
32
        "sync"
33
        "sync/atomic"
34
        "testing"
35
        "time"
36

37
        "github.com/pborman/uuid"
38
        "github.com/stretchr/testify/require"
39

40
        "github.com/uber/cadence/common"
41
        "github.com/uber/cadence/common/checksum"
42
        p "github.com/uber/cadence/common/persistence"
43
        "github.com/uber/cadence/common/types"
44
)
45

46
type (
47
        // ExecutionManagerSuite contains matching persistence tests
48
        ExecutionManagerSuite struct {
49
                *TestBase
50
                // override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test,
51
                // not merely log an error
52
                *require.Assertions
53
        }
54
)
55

56
var (
57
        testContextTimeout      = 5 * time.Second
58
        largeTestContextTimeout = 10 * time.Second
59

60
        testWorkflowChecksum = checksum.Checksum{
61
                Version: 22,
62
                Flavor:  checksum.FlavorIEEECRC32OverThriftBinary,
63
                Value:   []byte("test-checksum"),
64
        }
65
)
66

67
// SetupSuite implementation
68
func (s *ExecutionManagerSuite) SetupSuite() {
×
69
        if testing.Verbose() {
×
70
                log.SetOutput(os.Stdout)
×
71
        }
×
72
}
73

74
// TearDownSuite implementation
75
func (s *ExecutionManagerSuite) TearDownSuite() {
×
76
        s.TearDownWorkflowStore()
×
77
}
×
78

79
// SetupTest implementation
80
func (s *ExecutionManagerSuite) SetupTest() {
×
81
        // Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil
×
82
        s.Assertions = require.New(s.T())
×
83
        s.ClearTasks()
×
84
}
×
85

86
func (s *ExecutionManagerSuite) newRandomChecksum() checksum.Checksum {
×
87
        return checksum.Checksum{
×
88
                Flavor:  checksum.FlavorIEEECRC32OverThriftBinary,
×
89
                Version: 22,
×
90
                Value:   uuid.NewRandom(),
×
91
        }
×
92
}
×
93

94
func (s *ExecutionManagerSuite) assertChecksumsEqual(expected checksum.Checksum, actual checksum.Checksum) {
×
95
        s.EqualValues(expected, actual)
×
96
}
×
97

98
// TestCreateWorkflowExecutionDeDup test
99
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionDeDup() {
×
100
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
101
        defer cancel()
×
102

×
103
        domainID := uuid.New()
×
104
        domainName := uuid.New()
×
105
        workflowID := "create-workflow-test-dedup"
×
106
        runID := "3969fae6-6b75-4c2a-b74b-4054edd296a6"
×
107
        workflowExecution := types.WorkflowExecution{
×
108
                WorkflowID: workflowID,
×
109
                RunID:      runID,
×
110
        }
×
111
        tasklist := "some random tasklist"
×
112
        workflowType := "some random workflow type"
×
113
        workflowTimeout := int32(10)
×
114
        decisionTimeout := int32(14)
×
115
        lastProcessedEventID := int64(0)
×
116
        nextEventID := int64(3)
×
117
        csum := s.newRandomChecksum()
×
118
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
119
                {
×
120
                        EventID: nextEventID,
×
121
                        Version: common.EmptyVersion,
×
122
                },
×
123
        })
×
124
        versionHistories := p.NewVersionHistories(versionHistory)
×
125

×
126
        req := &p.CreateWorkflowExecutionRequest{
×
127
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
128
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
129
                                CreateRequestID:             uuid.New(),
×
130
                                DomainID:                    domainID,
×
131
                                WorkflowID:                  workflowID,
×
132
                                RunID:                       runID,
×
133
                                FirstExecutionRunID:         runID,
×
134
                                TaskList:                    tasklist,
×
135
                                WorkflowTypeName:            workflowType,
×
136
                                WorkflowTimeout:             workflowTimeout,
×
137
                                DecisionStartToCloseTimeout: decisionTimeout,
×
138
                                LastFirstEventID:            common.FirstEventID,
×
139
                                NextEventID:                 nextEventID,
×
140
                                LastProcessedEvent:          lastProcessedEventID,
×
141
                                State:                       p.WorkflowStateCreated,
×
142
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
143
                        },
×
144
                        ExecutionStats:   &p.ExecutionStats{},
×
145
                        Checksum:         csum,
×
146
                        VersionHistories: versionHistories,
×
147
                },
×
148
                RangeID:    s.ShardInfo.RangeID,
×
149
                Mode:       p.CreateWorkflowModeBrandNew,
×
150
                DomainName: domainName,
×
151
        }
×
152

×
153
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
154
        s.Nil(err)
×
155
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
156
        s.Nil(err)
×
157
        s.assertChecksumsEqual(csum, info.Checksum)
×
158
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
159
        updatedStats := copyExecutionStats(info.ExecutionStats)
×
160
        updatedInfo.State = p.WorkflowStateCompleted
×
161
        updatedInfo.CloseStatus = p.WorkflowCloseStatusCompleted
×
162
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
163
                UpdateWorkflowMutation: p.WorkflowMutation{
×
164
                        ExecutionInfo:    updatedInfo,
×
165
                        ExecutionStats:   updatedStats,
×
166
                        Condition:        nextEventID,
×
167
                        VersionHistories: versionHistories,
×
168
                },
×
169
                RangeID: s.ShardInfo.RangeID,
×
170
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
171
        })
×
172
        s.NoError(err)
×
173

×
174
        req.Mode = p.CreateWorkflowModeWorkflowIDReuse
×
175
        req.PreviousRunID = runID
×
176
        req.PreviousLastWriteVersion = common.EmptyVersion
×
177
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
178
        s.Error(err)
×
179
        s.IsType(&p.WorkflowExecutionAlreadyStartedError{}, err)
×
180
}
×
181

NEW
182
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionWithWorkflowRequestsDedup() {
×
NEW
183
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
NEW
184
        defer cancel()
×
NEW
185

×
NEW
186
        domainID := uuid.New()
×
NEW
187
        domainName := uuid.New()
×
NEW
188
        workflowID := "create-workflow-test-dedup"
×
NEW
189
        runID := uuid.New()
×
NEW
190
        requestID := uuid.New()
×
NEW
191
        tasklist := "some random tasklist"
×
NEW
192
        workflowType := "some random workflow type"
×
NEW
193
        workflowTimeout := int32(10)
×
NEW
194
        decisionTimeout := int32(14)
×
NEW
195
        lastProcessedEventID := int64(0)
×
NEW
196
        nextEventID := int64(3)
×
NEW
197
        csum := s.newRandomChecksum()
×
NEW
198
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
NEW
199
                {
×
NEW
200
                        EventID: nextEventID,
×
NEW
201
                        Version: common.EmptyVersion,
×
NEW
202
                },
×
NEW
203
        })
×
NEW
204
        versionHistories := p.NewVersionHistories(versionHistory)
×
NEW
205

×
NEW
206
        req := &p.CreateWorkflowExecutionRequest{
×
NEW
207
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
NEW
208
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
NEW
209
                                CreateRequestID:             requestID,
×
NEW
210
                                DomainID:                    domainID,
×
NEW
211
                                WorkflowID:                  workflowID,
×
NEW
212
                                RunID:                       runID,
×
NEW
213
                                FirstExecutionRunID:         runID,
×
NEW
214
                                TaskList:                    tasklist,
×
NEW
215
                                WorkflowTypeName:            workflowType,
×
NEW
216
                                WorkflowTimeout:             workflowTimeout,
×
NEW
217
                                DecisionStartToCloseTimeout: decisionTimeout,
×
NEW
218
                                LastFirstEventID:            common.FirstEventID,
×
NEW
219
                                NextEventID:                 nextEventID,
×
NEW
220
                                LastProcessedEvent:          lastProcessedEventID,
×
NEW
221
                                State:                       p.WorkflowStateCreated,
×
NEW
222
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
NEW
223
                        },
×
NEW
224
                        ExecutionStats:   &p.ExecutionStats{},
×
NEW
225
                        Checksum:         csum,
×
NEW
226
                        VersionHistories: versionHistories,
×
NEW
227
                        WorkflowRequests: []*p.WorkflowRequest{
×
NEW
228
                                {
×
NEW
229
                                        RequestID:   requestID,
×
NEW
230
                                        Version:     1,
×
NEW
231
                                        RequestType: p.WorkflowRequestTypeStart,
×
NEW
232
                                },
×
NEW
233
                        },
×
NEW
234
                },
×
NEW
235
                RangeID:             s.ShardInfo.RangeID,
×
NEW
236
                Mode:                p.CreateWorkflowModeBrandNew,
×
NEW
237
                WorkflowRequestMode: p.CreateWorkflowRequestModeReplicated,
×
NEW
238
                DomainName:          domainName,
×
NEW
239
        }
×
NEW
240
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
NEW
241
        s.Nil(err)
×
NEW
242
        req.WorkflowRequestMode = p.CreateWorkflowRequestModeNew
×
NEW
243
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
NEW
244
        s.Error(err)
×
NEW
245
        s.IsType(&p.DuplicateRequestError{}, err)
×
NEW
246
        req.WorkflowRequestMode = p.CreateWorkflowRequestModeReplicated
×
NEW
247
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
NEW
248
        s.Error(err)
×
NEW
249
        s.IsType(&p.WorkflowExecutionAlreadyStartedError{}, err)
×
NEW
250
}
×
251

252
// TestCreateWorkflowExecutionStateCloseStatus test
253
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionStateCloseStatus() {
×
254
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
255
        defer cancel()
×
256

×
257
        domainID := uuid.New()
×
258
        invalidCloseStatuses := []int{
×
259
                p.WorkflowCloseStatusCompleted,
×
260
                p.WorkflowCloseStatusFailed,
×
261
                p.WorkflowCloseStatusCanceled,
×
262
                p.WorkflowCloseStatusTerminated,
×
263
                p.WorkflowCloseStatusContinuedAsNew,
×
264
                p.WorkflowCloseStatusTimedOut,
×
265
        }
×
266
        tasklist := "some random tasklist"
×
267
        workflowType := "some random workflow type"
×
268
        workflowTimeout := int32(10)
×
269
        decisionTimeout := int32(14)
×
270
        lastProcessedEventID := int64(0)
×
271
        nextEventID := int64(3)
×
272
        csum := s.newRandomChecksum()
×
273
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
274
                {
×
275
                        EventID: nextEventID,
×
276
                        Version: common.EmptyVersion,
×
277
                },
×
278
        })
×
279
        versionHistories := p.NewVersionHistories(versionHistory)
×
280

×
281
        req := &p.CreateWorkflowExecutionRequest{
×
282
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
283
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
284
                                CreateRequestID:             uuid.New(),
×
285
                                DomainID:                    domainID,
×
286
                                TaskList:                    tasklist,
×
287
                                WorkflowTypeName:            workflowType,
×
288
                                WorkflowTimeout:             workflowTimeout,
×
289
                                DecisionStartToCloseTimeout: decisionTimeout,
×
290
                                LastFirstEventID:            common.FirstEventID,
×
291
                                NextEventID:                 nextEventID,
×
292
                                LastProcessedEvent:          lastProcessedEventID,
×
293
                        },
×
294
                        ExecutionStats:   &p.ExecutionStats{},
×
295
                        Checksum:         csum,
×
296
                        VersionHistories: versionHistories,
×
297
                },
×
298
                RangeID: s.ShardInfo.RangeID,
×
299
                Mode:    p.CreateWorkflowModeBrandNew,
×
300
        }
×
301

×
302
        workflowExecutionStatusCreated := types.WorkflowExecution{
×
303
                WorkflowID: "create-workflow-test-state-created",
×
304
                RunID:      uuid.New(),
×
305
        }
×
306
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusCreated.GetWorkflowID()
×
307
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusCreated.GetRunID()
×
308
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusCreated.GetRunID()
×
309
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateCreated
×
310
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
311
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
312
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
313
                s.IsType(&types.InternalServiceError{}, err)
×
314
        }
×
315
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
316
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
317
        s.Nil(err)
×
318
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionStatusCreated)
×
319
        s.Nil(err)
×
320
        s.Equal(p.WorkflowStateCreated, info.ExecutionInfo.State)
×
321
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
322
        s.assertChecksumsEqual(csum, info.Checksum)
×
323

×
324
        workflowExecutionStatusRunning := types.WorkflowExecution{
×
325
                WorkflowID: "create-workflow-test-state-running",
×
326
                RunID:      uuid.New(),
×
327
        }
×
328
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusRunning.GetWorkflowID()
×
329
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusRunning.GetRunID()
×
330
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusRunning.GetRunID()
×
331
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
332
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
333
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
334
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
335
                s.IsType(&types.InternalServiceError{}, err)
×
336
        }
×
337
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
338
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
339
        s.Nil(err)
×
340
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionStatusRunning)
×
341
        s.Nil(err)
×
342
        s.Equal(p.WorkflowStateRunning, info.ExecutionInfo.State)
×
343
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
344
        s.assertChecksumsEqual(csum, info.Checksum)
×
345

×
346
        workflowExecutionStatusCompleted := types.WorkflowExecution{
×
347
                WorkflowID: "create-workflow-test-state-completed",
×
348
                RunID:      uuid.New(),
×
349
        }
×
350
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusCompleted.GetWorkflowID()
×
351
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusCompleted.GetRunID()
×
352
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusCompleted.GetRunID()
×
353
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateCompleted
×
354
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
355
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
356
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
357
                s.IsType(&types.InternalServiceError{}, err)
×
358
        }
×
359
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
360
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
361
        s.IsType(&types.InternalServiceError{}, err)
×
362

×
363
        // for zombie workflow creation, we must use existing workflow ID which got created
×
364
        // since we do not allow creation of zombie workflow without current record
×
365
        workflowExecutionStatusZombie := types.WorkflowExecution{
×
366
                WorkflowID: workflowExecutionStatusRunning.WorkflowID,
×
367
                RunID:      uuid.New(),
×
368
        }
×
369
        req.Mode = p.CreateWorkflowModeZombie
×
370
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusZombie.GetWorkflowID()
×
371
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusZombie.GetRunID()
×
372
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusZombie.GetRunID()
×
373
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateZombie
×
374
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
375
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
376
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
377
                s.IsType(&types.InternalServiceError{}, err)
×
378
        }
×
379
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
380
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
381
        s.Nil(err)
×
382
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionStatusZombie)
×
383
        s.Nil(err)
×
384
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
385
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
386
        s.assertChecksumsEqual(csum, info.Checksum)
×
387
}
388

389
// TestCreateWorkflowExecutionWithZombieState test
390
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionWithZombieState() {
×
391
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
392
        defer cancel()
×
393

×
394
        domainID := uuid.New()
×
395
        workflowID := "create-workflow-test-with-zombie-state"
×
396
        workflowExecutionZombie1 := types.WorkflowExecution{
×
397
                WorkflowID: workflowID,
×
398
                RunID:      uuid.New(),
×
399
        }
×
400
        tasklist := "some random tasklist"
×
401
        workflowType := "some random workflow type"
×
402
        workflowTimeout := int32(10)
×
403
        decisionTimeout := int32(14)
×
404
        lastProcessedEventID := int64(0)
×
405
        nextEventID := int64(3)
×
406
        csum := s.newRandomChecksum()
×
407
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
408
                {
×
409
                        EventID: nextEventID,
×
410
                        Version: common.EmptyVersion,
×
411
                },
×
412
        })
×
413
        versionHistories := p.NewVersionHistories(versionHistory)
×
414

×
415
        req := &p.CreateWorkflowExecutionRequest{
×
416
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
417
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
418
                                CreateRequestID:             uuid.New(),
×
419
                                DomainID:                    domainID,
×
420
                                WorkflowID:                  workflowID,
×
421
                                RunID:                       workflowExecutionZombie1.GetRunID(),
×
422
                                FirstExecutionRunID:         workflowExecutionZombie1.GetRunID(),
×
423
                                TaskList:                    tasklist,
×
424
                                WorkflowTypeName:            workflowType,
×
425
                                WorkflowTimeout:             workflowTimeout,
×
426
                                DecisionStartToCloseTimeout: decisionTimeout,
×
427
                                NextEventID:                 nextEventID,
×
428
                                LastProcessedEvent:          lastProcessedEventID,
×
429
                                State:                       p.WorkflowStateZombie,
×
430
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
431
                        },
×
432
                        ExecutionStats:   &p.ExecutionStats{},
×
433
                        Checksum:         csum,
×
434
                        VersionHistories: versionHistories,
×
435
                },
×
436
                RangeID: s.ShardInfo.RangeID,
×
437
                Mode:    p.CreateWorkflowModeZombie,
×
438
        }
×
439
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
440
        s.Nil(err) // allow creating a zombie workflow if no current running workflow
×
441
        _, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
442
        s.IsType(&types.EntityNotExistsError{}, err) // no current workflow
×
443

×
444
        workflowExecutionRunning := types.WorkflowExecution{
×
445
                WorkflowID: workflowID,
×
446
                RunID:      uuid.New(),
×
447
        }
×
448
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionRunning.GetRunID()
×
449
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionRunning.GetRunID()
×
450
        req.Mode = p.CreateWorkflowModeBrandNew
×
451
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
452
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
453
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
454
        s.Nil(err)
×
455
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
456
        s.Nil(err)
×
457
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
458

×
459
        workflowExecutionZombie := types.WorkflowExecution{
×
460
                WorkflowID: workflowID,
×
461
                RunID:      uuid.New(),
×
462
        }
×
463
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionZombie.GetRunID()
×
464
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionZombie.GetRunID()
×
465
        req.Mode = p.CreateWorkflowModeZombie
×
466
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateZombie
×
467
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
468
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
469
        s.Nil(err)
×
470
        // current run ID is still the prev running run ID
×
471
        currentRunID, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecutionRunning.GetWorkflowID())
×
472
        s.Nil(err)
×
473
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
474
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionZombie)
×
475
        s.Nil(err)
×
476
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
477
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
478
        s.assertChecksumsEqual(csum, info.Checksum)
×
479
}
×
480

NEW
481
func (s *ExecutionManagerSuite) TestUpdateWorkflowExecutionWithWorkflowRequestsDedup() {
×
NEW
482
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
NEW
483
        defer cancel()
×
NEW
484

×
NEW
485
        domainID := uuid.New()
×
NEW
486
        domainName := uuid.New()
×
NEW
487
        workflowID := "create-workflow-test-dedup"
×
NEW
488
        runID := uuid.New()
×
NEW
489
        requestID := uuid.New()
×
NEW
490
        tasklist := "some random tasklist"
×
NEW
491
        workflowType := "some random workflow type"
×
NEW
492
        workflowTimeout := int32(10)
×
NEW
493
        decisionTimeout := int32(14)
×
NEW
494
        lastProcessedEventID := int64(0)
×
NEW
495
        nextEventID := int64(3)
×
NEW
496
        csum := s.newRandomChecksum()
×
NEW
497
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
NEW
498
                {
×
NEW
499
                        EventID: nextEventID,
×
NEW
500
                        Version: common.EmptyVersion,
×
NEW
501
                },
×
NEW
502
        })
×
NEW
503
        versionHistories := p.NewVersionHistories(versionHistory)
×
NEW
504

×
NEW
505
        req := &p.CreateWorkflowExecutionRequest{
×
NEW
506
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
NEW
507
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
NEW
508
                                CreateRequestID:             requestID,
×
NEW
509
                                DomainID:                    domainID,
×
NEW
510
                                WorkflowID:                  workflowID,
×
NEW
511
                                RunID:                       runID,
×
NEW
512
                                FirstExecutionRunID:         runID,
×
NEW
513
                                TaskList:                    tasklist,
×
NEW
514
                                WorkflowTypeName:            workflowType,
×
NEW
515
                                WorkflowTimeout:             workflowTimeout,
×
NEW
516
                                DecisionStartToCloseTimeout: decisionTimeout,
×
NEW
517
                                LastFirstEventID:            common.FirstEventID,
×
NEW
518
                                NextEventID:                 nextEventID,
×
NEW
519
                                LastProcessedEvent:          lastProcessedEventID,
×
NEW
520
                                State:                       p.WorkflowStateCreated,
×
NEW
521
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
NEW
522
                        },
×
NEW
523
                        ExecutionStats:   &p.ExecutionStats{},
×
NEW
524
                        Checksum:         csum,
×
NEW
525
                        VersionHistories: versionHistories,
×
NEW
526
                        WorkflowRequests: []*p.WorkflowRequest{
×
NEW
527
                                {
×
NEW
528
                                        RequestID:   requestID,
×
NEW
529
                                        Version:     1,
×
NEW
530
                                        RequestType: p.WorkflowRequestTypeStart,
×
NEW
531
                                },
×
NEW
532
                                {
×
NEW
533
                                        RequestID:   requestID,
×
NEW
534
                                        Version:     1,
×
NEW
535
                                        RequestType: p.WorkflowRequestTypeSignal,
×
NEW
536
                                },
×
NEW
537
                        },
×
NEW
538
                },
×
NEW
539
                RangeID:             s.ShardInfo.RangeID,
×
NEW
540
                Mode:                p.CreateWorkflowModeBrandNew,
×
NEW
541
                WorkflowRequestMode: p.CreateWorkflowRequestModeNew,
×
NEW
542
                DomainName:          domainName,
×
NEW
543
        }
×
NEW
544
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
NEW
545
        s.Nil(err)
×
NEW
546
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, types.WorkflowExecution{WorkflowID: workflowID, RunID: runID})
×
NEW
547
        s.Nil(err)
×
NEW
548
        csum = s.newRandomChecksum() // update the checksum to new value
×
NEW
549
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
NEW
550
        updatedStats := copyExecutionStats(info.ExecutionStats)
×
NEW
551
        updatedInfo.State = p.WorkflowStateRunning
×
NEW
552
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
NEW
553
        updateReq := &p.UpdateWorkflowExecutionRequest{
×
NEW
554
                UpdateWorkflowMutation: p.WorkflowMutation{
×
NEW
555
                        ExecutionInfo:    updatedInfo,
×
NEW
556
                        ExecutionStats:   updatedStats,
×
NEW
557
                        Condition:        nextEventID,
×
NEW
558
                        Checksum:         csum,
×
NEW
559
                        VersionHistories: versionHistories,
×
NEW
560
                        WorkflowRequests: []*p.WorkflowRequest{
×
NEW
561
                                {
×
NEW
562
                                        RequestID:   requestID,
×
NEW
563
                                        Version:     1,
×
NEW
564
                                        RequestType: p.WorkflowRequestTypeSignal,
×
NEW
565
                                },
×
NEW
566
                        },
×
NEW
567
                },
×
NEW
568
                RangeID:             s.ShardInfo.RangeID,
×
NEW
569
                Mode:                p.UpdateWorkflowModeUpdateCurrent,
×
NEW
570
                WorkflowRequestMode: p.CreateWorkflowRequestModeNew,
×
NEW
571
        }
×
NEW
572
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, updateReq)
×
NEW
573
        s.Error(err)
×
NEW
574
        s.IsType(&p.DuplicateRequestError{}, err)
×
NEW
575
        updateReq.WorkflowRequestMode = p.CreateWorkflowRequestModeReplicated
×
NEW
576
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, updateReq)
×
NEW
577
        s.Nil(err)
×
NEW
578
        updateReq.UpdateWorkflowMutation.WorkflowRequests[0].RequestID = uuid.New()
×
NEW
579
        updateReq.WorkflowRequestMode = p.CreateWorkflowRequestModeNew
×
NEW
580
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, updateReq)
×
NEW
581
        s.Nil(err)
×
NEW
582
}
×
583

584
// TestUpdateWorkflowExecutionStateCloseStatus test
585
func (s *ExecutionManagerSuite) TestUpdateWorkflowExecutionStateCloseStatus() {
×
586
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
587
        defer cancel()
×
588

×
589
        domainID := uuid.New()
×
590
        workflowExecution := types.WorkflowExecution{
×
591
                WorkflowID: "update-workflow-test-state",
×
592
                RunID:      uuid.New(),
×
593
        }
×
594
        closeStatuses := []int{
×
595
                p.WorkflowCloseStatusCompleted,
×
596
                p.WorkflowCloseStatusFailed,
×
597
                p.WorkflowCloseStatusCanceled,
×
598
                p.WorkflowCloseStatusTerminated,
×
599
                p.WorkflowCloseStatusContinuedAsNew,
×
600
                p.WorkflowCloseStatusTimedOut,
×
601
        }
×
602
        tasklist := "some random tasklist"
×
603
        workflowType := "some random workflow type"
×
604
        workflowTimeout := int32(10)
×
605
        decisionTimeout := int32(14)
×
606
        lastProcessedEventID := int64(0)
×
607
        nextEventID := int64(3)
×
608
        csum := s.newRandomChecksum()
×
609
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
610
                {
×
611
                        EventID: nextEventID,
×
612
                        Version: common.EmptyVersion,
×
613
                },
×
614
        })
×
615
        versionHistories := p.NewVersionHistories(versionHistory)
×
616

×
617
        req := &p.CreateWorkflowExecutionRequest{
×
618
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
619
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
620
                                CreateRequestID:             uuid.New(),
×
621
                                DomainID:                    domainID,
×
622
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
623
                                RunID:                       workflowExecution.GetRunID(),
×
624
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
625
                                TaskList:                    tasklist,
×
626
                                WorkflowTypeName:            workflowType,
×
627
                                WorkflowTimeout:             workflowTimeout,
×
628
                                DecisionStartToCloseTimeout: decisionTimeout,
×
629
                                LastFirstEventID:            common.FirstEventID,
×
630
                                NextEventID:                 nextEventID,
×
631
                                LastProcessedEvent:          lastProcessedEventID,
×
632
                        },
×
633
                        ExecutionStats:   &p.ExecutionStats{},
×
634
                        Checksum:         csum,
×
635
                        VersionHistories: versionHistories,
×
636
                },
×
637
                RangeID: s.ShardInfo.RangeID,
×
638
                Mode:    p.CreateWorkflowModeBrandNew,
×
639
        }
×
640

×
641
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateCreated
×
642
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
643
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
644
        s.Nil(err)
×
645
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
646
        s.Nil(err)
×
647
        s.Equal(p.WorkflowStateCreated, info.ExecutionInfo.State)
×
648
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
649
        s.assertChecksumsEqual(csum, info.Checksum)
×
650

×
651
        csum = s.newRandomChecksum() // update the checksum to new value
×
652
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
653
        updatedStats := copyExecutionStats(info.ExecutionStats)
×
654
        updatedInfo.State = p.WorkflowStateRunning
×
655
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
656
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
657
                UpdateWorkflowMutation: p.WorkflowMutation{
×
658
                        ExecutionInfo:    updatedInfo,
×
659
                        ExecutionStats:   updatedStats,
×
660
                        Condition:        nextEventID,
×
661
                        Checksum:         csum,
×
662
                        VersionHistories: versionHistories,
×
663
                },
×
664
                RangeID: s.ShardInfo.RangeID,
×
665
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
666
        })
×
667
        s.NoError(err)
×
668
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
669
        s.Nil(err)
×
670
        s.Equal(p.WorkflowStateRunning, info.ExecutionInfo.State)
×
671
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
672
        s.assertChecksumsEqual(csum, info.Checksum)
×
673

×
674
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
675
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
676
        updatedInfo.State = p.WorkflowStateRunning
×
677
        for _, closeStatus := range closeStatuses {
×
678
                updatedInfo.CloseStatus = closeStatus
×
679
                _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
680
                        UpdateWorkflowMutation: p.WorkflowMutation{
×
681
                                ExecutionInfo:  updatedInfo,
×
682
                                ExecutionStats: updatedStats,
×
683
                                Condition:      nextEventID,
×
684
                        },
×
685
                        RangeID: s.ShardInfo.RangeID,
×
686
                        Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
687
                })
×
688
                s.IsType(&types.InternalServiceError{}, err)
×
689
        }
×
690

691
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
692
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
693
        updatedInfo.State = p.WorkflowStateCompleted
×
694
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
695
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
696
                UpdateWorkflowMutation: p.WorkflowMutation{
×
697
                        ExecutionInfo:  updatedInfo,
×
698
                        ExecutionStats: updatedStats,
×
699
                        Condition:      nextEventID,
×
700
                },
×
701
                RangeID: s.ShardInfo.RangeID,
×
702
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
703
        })
×
704
        s.IsType(&types.InternalServiceError{}, err)
×
705

×
706
        for _, closeStatus := range closeStatuses {
×
707
                updatedInfo.CloseStatus = closeStatus
×
708
                _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
709
                        UpdateWorkflowMutation: p.WorkflowMutation{
×
710
                                ExecutionInfo:    updatedInfo,
×
711
                                ExecutionStats:   updatedStats,
×
712
                                Condition:        nextEventID,
×
713
                                VersionHistories: versionHistories,
×
714
                        },
×
715
                        RangeID: s.ShardInfo.RangeID,
×
716
                        Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
717
                })
×
718
                s.Nil(err)
×
719
                info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
720
                s.Nil(err)
×
721
                s.Equal(p.WorkflowStateCompleted, info.ExecutionInfo.State)
×
722
                s.Equal(closeStatus, info.ExecutionInfo.CloseStatus)
×
723
        }
×
724

725
        // create a new workflow with same domain ID & workflow ID
726
        // to enable update workflow with zombie status
727
        workflowExecutionRunning := types.WorkflowExecution{
×
728
                WorkflowID: workflowExecution.WorkflowID,
×
729
                RunID:      uuid.New(),
×
730
        }
×
731
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionRunning.GetWorkflowID()
×
732
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionRunning.GetRunID()
×
733
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionRunning.GetRunID()
×
734
        req.Mode = p.CreateWorkflowModeWorkflowIDReuse
×
735
        req.PreviousRunID = workflowExecution.GetRunID()
×
736
        req.PreviousLastWriteVersion = common.EmptyVersion
×
737
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
738
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
739
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
740
        s.Nil(err)
×
741

×
742
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
743
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
744
        updatedInfo.State = p.WorkflowStateZombie
×
745
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
746
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
747
                UpdateWorkflowMutation: p.WorkflowMutation{
×
748
                        ExecutionInfo:    updatedInfo,
×
749
                        ExecutionStats:   updatedStats,
×
750
                        Condition:        nextEventID,
×
751
                        VersionHistories: versionHistories,
×
752
                },
×
753
                RangeID: s.ShardInfo.RangeID,
×
754
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
755
        })
×
756
        s.NoError(err)
×
757
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
758
        s.Nil(err)
×
759
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
760
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
761

×
762
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
763
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
764
        updatedInfo.State = p.WorkflowStateZombie
×
765
        for _, closeStatus := range closeStatuses {
×
766
                updatedInfo.CloseStatus = closeStatus
×
767
                _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
768
                        UpdateWorkflowMutation: p.WorkflowMutation{
×
769
                                ExecutionInfo:  updatedInfo,
×
770
                                ExecutionStats: updatedStats,
×
771
                                Condition:      nextEventID,
×
772
                        },
×
773
                        RangeID: s.ShardInfo.RangeID,
×
774
                        Mode:    p.UpdateWorkflowModeBypassCurrent,
×
775
                })
×
776
                s.IsType(&types.InternalServiceError{}, err)
×
777
        }
×
778
}
779

780
// TestUpdateWorkflowExecutionWithZombieState test
781
func (s *ExecutionManagerSuite) TestUpdateWorkflowExecutionWithZombieState() {
×
782
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
783
        defer cancel()
×
784

×
785
        domainID := uuid.New()
×
786
        workflowID := "create-workflow-test-with-zombie-state"
×
787
        workflowExecution := types.WorkflowExecution{
×
788
                WorkflowID: workflowID,
×
789
                RunID:      uuid.New(),
×
790
        }
×
791
        tasklist := "some random tasklist"
×
792
        workflowType := "some random workflow type"
×
793
        workflowTimeout := int32(10)
×
794
        decisionTimeout := int32(14)
×
795
        lastProcessedEventID := int64(0)
×
796
        nextEventID := int64(3)
×
797
        csum := s.newRandomChecksum()
×
798
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
799
                {
×
800
                        EventID: nextEventID,
×
801
                        Version: common.EmptyVersion,
×
802
                },
×
803
        })
×
804
        versionHistories := p.NewVersionHistories(versionHistory)
×
805

×
806
        // create and update a workflow to make it completed
×
807
        req := &p.CreateWorkflowExecutionRequest{
×
808
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
809
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
810
                                CreateRequestID:             uuid.New(),
×
811
                                DomainID:                    domainID,
×
812
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
813
                                RunID:                       workflowExecution.GetRunID(),
×
814
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
815
                                TaskList:                    tasklist,
×
816
                                WorkflowTypeName:            workflowType,
×
817
                                WorkflowTimeout:             workflowTimeout,
×
818
                                DecisionStartToCloseTimeout: decisionTimeout,
×
819
                                NextEventID:                 nextEventID,
×
820
                                LastProcessedEvent:          lastProcessedEventID,
×
821
                                State:                       p.WorkflowStateRunning,
×
822
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
823
                        },
×
824
                        ExecutionStats:   &p.ExecutionStats{},
×
825
                        Checksum:         csum,
×
826
                        VersionHistories: versionHistories,
×
827
                },
×
828
                RangeID: s.ShardInfo.RangeID,
×
829
                Mode:    p.CreateWorkflowModeBrandNew,
×
830
        }
×
831
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
832
        s.Nil(err)
×
833
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
834
        s.Nil(err)
×
835
        s.Equal(workflowExecution.GetRunID(), currentRunID)
×
836

×
837
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
838
        s.Nil(err)
×
839
        s.assertChecksumsEqual(csum, info.Checksum)
×
840

×
841
        // try to turn current workflow into zombie state, this should end with an error
×
842
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
843
        updateStats := copyExecutionStats(info.ExecutionStats)
×
844
        updatedInfo.State = p.WorkflowStateZombie
×
845
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
846
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
847
                UpdateWorkflowMutation: p.WorkflowMutation{
×
848
                        ExecutionInfo:  updatedInfo,
×
849
                        ExecutionStats: updateStats,
×
850
                        Condition:      nextEventID,
×
851
                        Checksum:       csum,
×
852
                },
×
853
                RangeID: s.ShardInfo.RangeID,
×
854
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
855
        })
×
856
        s.NotNil(err)
×
857

×
858
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
859
        updateStats = copyExecutionStats(info.ExecutionStats)
×
860
        updatedInfo.State = p.WorkflowStateCompleted
×
861
        updatedInfo.CloseStatus = p.WorkflowCloseStatusCompleted
×
862
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
863
                UpdateWorkflowMutation: p.WorkflowMutation{
×
864
                        ExecutionInfo:    updatedInfo,
×
865
                        ExecutionStats:   updateStats,
×
866
                        Condition:        nextEventID,
×
867
                        VersionHistories: versionHistories,
×
868
                },
×
869
                RangeID: s.ShardInfo.RangeID,
×
870
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
871
        })
×
872
        s.NoError(err)
×
873

×
874
        // create a new workflow with same domain ID & workflow ID
×
875
        workflowExecutionRunning := types.WorkflowExecution{
×
876
                WorkflowID: workflowID,
×
877
                RunID:      uuid.New(),
×
878
        }
×
879
        csum = checksum.Checksum{} // set checksum to nil
×
880
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionRunning.GetWorkflowID()
×
881
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionRunning.GetRunID()
×
882
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionRunning.GetRunID()
×
883
        req.Mode = p.CreateWorkflowModeWorkflowIDReuse
×
884
        req.PreviousRunID = workflowExecution.GetRunID()
×
885
        req.PreviousLastWriteVersion = common.EmptyVersion
×
886
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
887
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
888
        req.NewWorkflowSnapshot.Checksum = csum
×
889
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
890
        s.Nil(err)
×
891
        currentRunID, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
892
        s.Nil(err)
×
893
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
894

×
895
        // get the workflow to be turned into a zombie
×
896
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
897
        s.Nil(err)
×
898
        s.assertChecksumsEqual(csum, info.Checksum)
×
899
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
900
        updateStats = copyExecutionStats(info.ExecutionStats)
×
901
        updatedInfo.State = p.WorkflowStateZombie
×
902
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
903
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
904
                UpdateWorkflowMutation: p.WorkflowMutation{
×
905
                        ExecutionInfo:    updatedInfo,
×
906
                        ExecutionStats:   updateStats,
×
907
                        Condition:        nextEventID,
×
908
                        Checksum:         csum,
×
909
                        VersionHistories: versionHistories,
×
910
                },
×
911
                RangeID: s.ShardInfo.RangeID,
×
912
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
913
        })
×
914
        s.NoError(err)
×
915
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
916
        s.Nil(err)
×
917
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
918
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
919
        s.assertChecksumsEqual(csum, info.Checksum)
×
920
        // check current run ID is un touched
×
921
        currentRunID, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
922
        s.Nil(err)
×
923
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
924
}
×
925

926
// TestUpdateWorkflowExecutionTasks test
927
func (s *ExecutionManagerSuite) TestUpdateWorkflowExecutionTasks() {
×
928
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
929
        defer cancel()
×
930

×
931
        domainID := "b0a8571c-0257-40ea-afcd-3a14eae181c0"
×
932
        workflowExecution := types.WorkflowExecution{
×
933
                WorkflowID: "update-workflow-tasks-test",
×
934
                RunID:      "5ba5e531-e46b-48d9-b4b3-859919839553",
×
935
        }
×
936
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
937
        s.NoError(err0)
×
938
        s.NotNil(task0, "Expected non empty task identifier.")
×
939

×
940
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
941
        s.NoError(err)
×
942
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
943
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
944
        s.NoError(err)
×
945

×
946
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
947
        s.NoError(err)
×
948
        info1 := state1.ExecutionInfo
×
949
        s.NotNil(info1, "Valid Workflow info expected.")
×
950
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
951
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
952

×
953
        now := time.Now()
×
954
        remoteClusterName := "remote-cluster"
×
955
        transferTasks := []p.Task{
×
956
                &p.ActivityTask{
×
957
                        TaskData: p.TaskData{
×
958
                                VisibilityTimestamp: now,
×
959
                                TaskID:              s.GetNextSequenceNumber(),
×
960
                                Version:             common.EmptyVersion,
×
961
                        },
×
962
                        DomainID:   domainID,
×
963
                        TaskList:   "some randome tasklist name",
×
964
                        ScheduleID: 123,
×
965
                },
×
966
        }
×
967
        timerTasks := []p.Task{
×
968
                &p.UserTimerTask{
×
969
                        TaskData: p.TaskData{
×
970
                                VisibilityTimestamp: now.Add(time.Minute),
×
971
                                TaskID:              s.GetNextSequenceNumber(),
×
972
                                Version:             common.EmptyVersion,
×
973
                        },
×
974
                        EventID: 124,
×
975
                },
×
976
        }
×
977
        crossClusterTasks := []p.Task{
×
978
                &p.CrossClusterApplyParentClosePolicyTask{
×
979
                        ApplyParentClosePolicyTask: p.ApplyParentClosePolicyTask{
×
980
                                TaskData: p.TaskData{
×
981
                                        VisibilityTimestamp: now,
×
982
                                        TaskID:              s.GetNextSequenceNumber(),
×
983
                                        Version:             common.EmptyVersion,
×
984
                                },
×
985
                        },
×
986
                        TargetCluster: remoteClusterName,
×
987
                },
×
988
        }
×
989

×
990
        err = s.UpdateWorkflowExecutionTasks(
×
991
                ctx,
×
992
                updatedInfo1,
×
993
                updatedStats1,
×
994
                int64(3),
×
995
                transferTasks,
×
996
                timerTasks,
×
997
                crossClusterTasks,
×
998
        )
×
999
        s.NoError(err)
×
1000

×
1001
        loadedTransferTasks, err := s.GetTransferTasks(ctx, 10, true)
×
1002
        s.NoError(err)
×
1003
        s.Len(loadedTransferTasks, len(transferTasks))
×
1004

×
1005
        loadedTimerTasks, err := s.GetTimerIndexTasks(ctx, 10, true)
×
1006
        s.NoError(err)
×
1007
        s.Len(loadedTimerTasks, len(timerTasks))
×
1008

×
1009
        loadedCrossClusterTasks, err := s.GetCrossClusterTasks(ctx, remoteClusterName, 0, 10, true)
×
1010
        s.NoError(err)
×
1011
        s.Len(loadedCrossClusterTasks, len(crossClusterTasks))
×
1012
}
×
1013

1014
// TestCreateWorkflowExecutionBrandNew test
1015
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionBrandNew() {
×
1016
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1017
        defer cancel()
×
1018

×
1019
        domainID := uuid.New()
×
1020
        workflowExecution := types.WorkflowExecution{
×
1021
                WorkflowID: "create-workflow-test-brand-new",
×
1022
                RunID:      uuid.New(),
×
1023
        }
×
1024
        tasklist := "some random tasklist"
×
1025
        workflowType := "some random workflow type"
×
1026
        workflowTimeout := int32(10)
×
1027
        decisionTimeout := int32(14)
×
1028
        lastProcessedEventID := int64(0)
×
1029
        nextEventID := int64(3)
×
1030
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1031
                {
×
1032
                        EventID: nextEventID,
×
1033
                        Version: common.EmptyVersion,
×
1034
                },
×
1035
        })
×
1036
        versionHistories := p.NewVersionHistories(versionHistory)
×
1037

×
1038
        req := &p.CreateWorkflowExecutionRequest{
×
1039
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1040
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1041
                                CreateRequestID:             uuid.New(),
×
1042
                                DomainID:                    domainID,
×
1043
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
1044
                                RunID:                       workflowExecution.GetRunID(),
×
1045
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
1046
                                TaskList:                    tasklist,
×
1047
                                WorkflowTypeName:            workflowType,
×
1048
                                WorkflowTimeout:             workflowTimeout,
×
1049
                                DecisionStartToCloseTimeout: decisionTimeout,
×
1050
                                State:                       p.WorkflowStateRunning,
×
1051
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1052
                                LastFirstEventID:            common.FirstEventID,
×
1053
                                NextEventID:                 nextEventID,
×
1054
                                LastProcessedEvent:          lastProcessedEventID,
×
1055
                        },
×
1056
                        ExecutionStats:   &p.ExecutionStats{},
×
1057
                        VersionHistories: versionHistories,
×
1058
                },
×
1059
                RangeID: s.ShardInfo.RangeID,
×
1060
                Mode:    p.CreateWorkflowModeBrandNew,
×
1061
        }
×
1062

×
1063
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
1064
        s.Nil(err)
×
1065
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
1066
        s.NotNil(err)
×
1067
        alreadyStartedErr, ok := err.(*p.WorkflowExecutionAlreadyStartedError)
×
1068
        s.True(ok, "err is not WorkflowExecutionAlreadyStartedError")
×
1069
        s.Equal(req.NewWorkflowSnapshot.ExecutionInfo.CreateRequestID, alreadyStartedErr.StartRequestID)
×
1070
        s.Equal(workflowExecution.GetRunID(), alreadyStartedErr.RunID)
×
1071
        s.Equal(0, alreadyStartedErr.CloseStatus)
×
1072
        s.Equal(p.WorkflowStateRunning, alreadyStartedErr.State)
×
1073
}
×
1074

1075
// TestUpsertWorkflowActivity test
1076
func (s *ExecutionManagerSuite) TestUpsertWorkflowActivity() {
×
1077
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1078
        defer cancel()
×
1079

×
1080
        domainID := uuid.New()
×
1081
        workflowID := "create-workflow-test-with-upsert-activity"
×
1082
        workflowExecution := types.WorkflowExecution{
×
1083
                WorkflowID: workflowID,
×
1084
                RunID:      uuid.New(),
×
1085
        }
×
1086
        tasklist := "some random tasklist"
×
1087
        workflowType := "some random workflow type"
×
1088
        workflowTimeout := int32(10)
×
1089
        decisionTimeout := int32(14)
×
1090
        lastProcessedEventID := int64(0)
×
1091
        nextEventID := int64(3)
×
1092
        csum := s.newRandomChecksum()
×
1093
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1094
                {
×
1095
                        EventID: nextEventID,
×
1096
                        Version: common.EmptyVersion,
×
1097
                },
×
1098
        })
×
1099
        versionHistories := p.NewVersionHistories(versionHistory)
×
1100

×
1101
        // create and update a workflow to make it completed
×
1102
        req := &p.CreateWorkflowExecutionRequest{
×
1103
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1104
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1105
                                CreateRequestID:             uuid.New(),
×
1106
                                DomainID:                    domainID,
×
1107
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
1108
                                RunID:                       workflowExecution.GetRunID(),
×
1109
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
1110
                                TaskList:                    tasklist,
×
1111
                                WorkflowTypeName:            workflowType,
×
1112
                                WorkflowTimeout:             workflowTimeout,
×
1113
                                DecisionStartToCloseTimeout: decisionTimeout,
×
1114
                                NextEventID:                 nextEventID,
×
1115
                                LastProcessedEvent:          lastProcessedEventID,
×
1116
                                State:                       p.WorkflowStateRunning,
×
1117
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1118
                        },
×
1119
                        ExecutionStats:   &p.ExecutionStats{},
×
1120
                        Checksum:         csum,
×
1121
                        VersionHistories: versionHistories,
×
1122
                },
×
1123
                RangeID: s.ShardInfo.RangeID,
×
1124
                Mode:    p.CreateWorkflowModeBrandNew,
×
1125
        }
×
1126
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
1127
        s.Nil(err)
×
1128
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
1129
        s.Nil(err)
×
1130
        s.Equal(workflowExecution.GetRunID(), currentRunID)
×
1131

×
1132
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1133
        s.Nil(err)
×
1134
        s.assertChecksumsEqual(csum, info.Checksum)
×
1135
        s.Equal(0, len(info.ActivityInfos))
×
1136

×
1137
        // insert a new activity
×
1138
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
1139
        updateStats := copyExecutionStats(info.ExecutionStats)
×
1140
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
1141
                UpdateWorkflowMutation: p.WorkflowMutation{
×
1142
                        ExecutionInfo:  updatedInfo,
×
1143
                        ExecutionStats: updateStats,
×
1144
                        Condition:      nextEventID,
×
1145
                        Checksum:       csum,
×
1146
                        UpsertActivityInfos: []*p.ActivityInfo{
×
1147
                                {
×
1148
                                        Version:    0,
×
1149
                                        ScheduleID: 100,
×
1150
                                        TaskList:   "test-activity-tasklist-1",
×
1151
                                },
×
1152
                        },
×
1153
                        VersionHistories: versionHistories,
×
1154
                },
×
1155
                RangeID: s.ShardInfo.RangeID,
×
1156
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
1157
        })
×
1158
        s.Nil(err)
×
1159

×
1160
        info2, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1161
        s.Nil(err)
×
1162
        s.Equal(1, len(info2.ActivityInfos))
×
1163
        s.Equal("test-activity-tasklist-1", info2.ActivityInfos[100].TaskList)
×
1164

×
1165
        // upsert the previous activity
×
1166
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
1167
                UpdateWorkflowMutation: p.WorkflowMutation{
×
1168
                        ExecutionInfo:  updatedInfo,
×
1169
                        ExecutionStats: updateStats,
×
1170
                        Condition:      nextEventID,
×
1171
                        Checksum:       csum,
×
1172
                        UpsertActivityInfos: []*p.ActivityInfo{
×
1173
                                {
×
1174
                                        Version:    0,
×
1175
                                        ScheduleID: 100,
×
1176
                                        TaskList:   "test-activity-tasklist-2",
×
1177
                                },
×
1178
                        },
×
1179
                        VersionHistories: versionHistories,
×
1180
                },
×
1181
                RangeID: s.ShardInfo.RangeID,
×
1182
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
1183
        })
×
1184
        s.NoError(err)
×
1185
        info3, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1186
        s.Nil(err)
×
1187
        s.Equal(1, len(info3.ActivityInfos))
×
1188
        s.Equal("test-activity-tasklist-2", info3.ActivityInfos[100].TaskList)
×
1189
}
×
1190

1191
// TestCreateWorkflowExecutionRunIDReuseWithoutReplication test
1192
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionRunIDReuseWithoutReplication() {
×
1193
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1194
        defer cancel()
×
1195

×
1196
        domainID := uuid.New()
×
1197
        workflowExecution := types.WorkflowExecution{
×
1198
                WorkflowID: "create-workflow-test-run-id-reuse-without-replication",
×
1199
                RunID:      uuid.New(),
×
1200
        }
×
1201
        tasklist := "some random tasklist"
×
1202
        workflowType := "some random workflow type"
×
1203
        workflowTimeout := int32(10)
×
1204
        decisionTimeout := int32(14)
×
1205
        lastProcessedEventID := int64(0)
×
1206
        nextEventID := int64(3)
×
1207
        decisionScheduleID := int64(2)
×
1208
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1209
                {
×
1210
                        EventID: decisionScheduleID,
×
1211
                        Version: common.EmptyVersion,
×
1212
                },
×
1213
        })
×
1214
        versionHistories := p.NewVersionHistories(versionHistory)
×
1215

×
1216
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist,
×
1217
                workflowType, workflowTimeout, decisionTimeout, nil, nextEventID,
×
1218
                lastProcessedEventID, decisionScheduleID, nil, nil)
×
1219
        s.NoError(err0)
×
1220
        s.NotNil(task0, "Expected non empty task identifier.")
×
1221

×
1222
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1223
        s.NoError(err1)
×
1224
        s.assertChecksumsEqual(testWorkflowChecksum, state0.Checksum)
×
1225
        info0 := state0.ExecutionInfo
×
1226
        closeInfo := copyWorkflowExecutionInfo(info0)
×
1227
        closeInfo.State = p.WorkflowStateCompleted
×
1228
        closeInfo.CloseStatus = p.WorkflowCloseStatusCompleted
×
1229
        closeInfo.NextEventID = int64(5)
×
1230
        closeInfo.LastProcessedEvent = int64(2)
×
1231

×
1232
        err2 := s.UpdateWorkflowExecution(ctx, closeInfo, state0.ExecutionStats, versionHistories, nil, nil, nextEventID,
×
1233
                nil, nil, nil, nil, nil)
×
1234
        s.NoError(err2)
×
1235

×
1236
        newExecution := types.WorkflowExecution{
×
1237
                WorkflowID: workflowExecution.GetWorkflowID(),
×
1238
                RunID:      uuid.New(),
×
1239
        }
×
1240
        // this create should work since we are relying the business logic in history engine
×
1241
        // to check whether the existing running workflow has finished
×
1242
        _, err3 := s.ExecutionManager.CreateWorkflowExecution(ctx, &p.CreateWorkflowExecutionRequest{
×
1243
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1244
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1245
                                CreateRequestID:             uuid.New(),
×
1246
                                DomainID:                    domainID,
×
1247
                                WorkflowID:                  newExecution.GetWorkflowID(),
×
1248
                                RunID:                       newExecution.GetRunID(),
×
1249
                                FirstExecutionRunID:         newExecution.GetRunID(),
×
1250
                                TaskList:                    tasklist,
×
1251
                                WorkflowTypeName:            workflowType,
×
1252
                                WorkflowTimeout:             workflowTimeout,
×
1253
                                DecisionStartToCloseTimeout: decisionTimeout,
×
1254
                                State:                       p.WorkflowStateRunning,
×
1255
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1256
                                LastFirstEventID:            common.FirstEventID,
×
1257
                                NextEventID:                 nextEventID,
×
1258
                                LastProcessedEvent:          lastProcessedEventID,
×
1259
                        },
×
1260
                        ExecutionStats:   &p.ExecutionStats{},
×
1261
                        VersionHistories: versionHistories,
×
1262
                },
×
1263
                RangeID:                  s.ShardInfo.RangeID,
×
1264
                Mode:                     p.CreateWorkflowModeWorkflowIDReuse,
×
1265
                PreviousRunID:            workflowExecution.GetRunID(),
×
1266
                PreviousLastWriteVersion: common.EmptyVersion,
×
1267
        })
×
1268
        s.NoError(err3)
×
1269
}
×
1270

1271
// TestCreateWorkflowExecutionConcurrentCreate test
1272
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionConcurrentCreate() {
×
1273
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1274
        defer cancel()
×
1275

×
1276
        domainID := uuid.New()
×
1277
        workflowExecution := types.WorkflowExecution{
×
1278
                WorkflowID: "create-workflow-test-concurrent-create",
×
1279
                RunID:      uuid.New(),
×
1280
        }
×
1281
        tasklist := "some random tasklist"
×
1282
        workflowType := "some random workflow type"
×
1283
        workflowTimeout := int32(10)
×
1284
        decisionTimeout := int32(14)
×
1285
        lastProcessedEventID := int64(0)
×
1286
        nextEventID := int64(3)
×
1287
        decisionScheduleID := int64(2)
×
1288

×
1289
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist,
×
1290
                workflowType, workflowTimeout, decisionTimeout, nil, nextEventID,
×
1291
                lastProcessedEventID, decisionScheduleID, nil, nil)
×
1292
        s.Nil(err0, "No error expected.")
×
1293
        s.NotNil(task0, "Expected non empty task identifier.")
×
1294

×
1295
        times := 2
×
1296
        var wg sync.WaitGroup
×
1297
        wg.Add(times)
×
1298
        var numOfErr int32
×
1299
        var lastError error
×
1300
        for i := 0; i < times; i++ {
×
1301
                go func() {
×
1302
                        newExecution := types.WorkflowExecution{
×
1303
                                WorkflowID: workflowExecution.GetWorkflowID(),
×
1304
                                RunID:      uuid.New(),
×
1305
                        }
×
1306

×
1307
                        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1308
                        s.NoError(err1)
×
1309
                        info0 := state0.ExecutionInfo
×
1310
                        continueAsNewInfo := copyWorkflowExecutionInfo(info0)
×
1311
                        continueAsNewInfo.State = p.WorkflowStateRunning
×
1312
                        continueAsNewInfo.NextEventID = int64(5)
×
1313
                        continueAsNewInfo.LastProcessedEvent = int64(2)
×
1314

×
1315
                        err2 := s.ContinueAsNewExecution(ctx, continueAsNewInfo, state0.ExecutionStats, info0.NextEventID, newExecution, int64(3), int64(2), nil)
×
1316
                        if err2 != nil {
×
1317
                                errCount := atomic.AddInt32(&numOfErr, 1)
×
1318
                                if errCount > 1 {
×
1319
                                        lastError = err2
×
1320
                                }
×
1321
                        }
1322
                        wg.Done()
×
1323
                }()
1324
        }
1325
        wg.Wait()
×
1326
        if lastError != nil {
×
1327
                s.Fail("More than one error: %v", lastError.Error())
×
1328
        }
×
1329
        s.Equal(int32(1), atomic.LoadInt32(&numOfErr))
×
1330
}
1331

1332
// TestPersistenceStartWorkflow test
1333
func (s *ExecutionManagerSuite) TestPersistenceStartWorkflow() {
×
1334
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1335
        defer cancel()
×
1336

×
1337
        domainID := "2d7994bf-9de8-459d-9c81-e723daedb246"
×
1338
        workflowExecution := types.WorkflowExecution{
×
1339
                WorkflowID: "start-workflow-test",
×
1340
                RunID:      "7f9fe8a0-9237-11e6-ae22-56b6b6499611",
×
1341
        }
×
1342
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1343
        s.NoError(err0)
×
1344
        s.NotNil(task0, "Expected non empty task identifier.")
×
1345

×
1346
        task1, err1 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType1", 20, 14, nil, 3, 0, 2, nil, nil)
×
1347
        s.Error(err1, "Expected workflow creation to fail.")
×
1348
        s.T().Logf("Unable to start workflow execution: %v\n", err1)
×
1349
        startedErr, ok := err1.(*p.WorkflowExecutionAlreadyStartedError)
×
1350
        s.True(ok, fmt.Sprintf("Expected WorkflowExecutionAlreadyStartedError, but actual is %v", err1))
×
1351
        s.Equal(workflowExecution.GetRunID(), startedErr.RunID, startedErr.Msg)
×
1352

×
1353
        s.Equal(p.WorkflowStateRunning, startedErr.State, startedErr.Msg)
×
1354
        s.Equal(p.WorkflowCloseStatusNone, startedErr.CloseStatus, startedErr.Msg)
×
1355
        s.Equal(common.EmptyVersion, startedErr.LastWriteVersion, startedErr.Msg)
×
1356
        s.Empty(task1, "Expected empty task identifier.")
×
1357
        decisionScheduleID := int64(2)
×
1358
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1359
                {
×
1360
                        EventID: decisionScheduleID,
×
1361
                        Version: common.EmptyVersion,
×
1362
                },
×
1363
        })
×
1364
        versionHistories := p.NewVersionHistories(versionHistory)
×
1365

×
1366
        response, err2 := s.ExecutionManager.CreateWorkflowExecution(ctx, &p.CreateWorkflowExecutionRequest{
×
1367
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1368
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1369
                                CreateRequestID:             uuid.New(),
×
1370
                                DomainID:                    domainID,
×
1371
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
1372
                                RunID:                       workflowExecution.GetRunID(),
×
1373
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
1374
                                TaskList:                    "queue1",
×
1375
                                WorkflowTypeName:            "workflow_type_test",
×
1376
                                WorkflowTimeout:             20,
×
1377
                                DecisionStartToCloseTimeout: 13,
×
1378
                                ExecutionContext:            nil,
×
1379
                                State:                       p.WorkflowStateRunning,
×
1380
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1381
                                LastFirstEventID:            common.FirstEventID,
×
1382
                                NextEventID:                 int64(3),
×
1383
                                LastProcessedEvent:          0,
×
1384
                                DecisionScheduleID:          decisionScheduleID,
×
1385
                                DecisionStartedID:           common.EmptyEventID,
×
1386
                                DecisionTimeout:             1,
×
1387
                        },
×
1388
                        ExecutionStats: &p.ExecutionStats{},
×
1389
                        TransferTasks: []p.Task{
×
1390
                                &p.DecisionTask{
×
1391
                                        TaskData: p.TaskData{
×
1392
                                                TaskID: s.GetNextSequenceNumber(),
×
1393
                                        },
×
1394
                                        DomainID:   domainID,
×
1395
                                        TaskList:   "queue1",
×
1396
                                        ScheduleID: int64(2),
×
1397
                                },
×
1398
                        },
×
1399
                        TimerTasks:       nil,
×
1400
                        VersionHistories: versionHistories,
×
1401
                },
×
1402
                RangeID: s.ShardInfo.RangeID - 1,
×
1403
        })
×
1404

×
1405
        s.Error(err2, "Expected workflow creation to fail.")
×
1406
        s.Nil(response)
×
1407
        s.T().Logf("Unable to start workflow execution: %v\n", err2)
×
1408
        s.IsType(&p.ShardOwnershipLostError{}, err2)
×
1409
}
×
1410

1411
// TestGetWorkflow test
1412
func (s *ExecutionManagerSuite) TestGetWorkflow() {
×
1413
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1414
        defer cancel()
×
1415

×
1416
        now := time.Now()
×
1417
        testResetPoints := types.ResetPoints{
×
1418
                Points: []*types.ResetPointInfo{
×
1419
                        {
×
1420
                                BinaryChecksum:           "test-binary-checksum",
×
1421
                                RunID:                    "test-runID",
×
1422
                                FirstDecisionCompletedID: 123,
×
1423
                                CreatedTimeNano:          common.Int64Ptr(456),
×
1424
                                Resettable:               true,
×
1425
                                ExpiringTimeNano:         common.Int64Ptr(789),
×
1426
                        },
×
1427
                },
×
1428
        }
×
1429
        testSearchAttrKey := "env"
×
1430
        testSearchAttrVal, _ := json.Marshal("test")
×
1431
        testSearchAttr := map[string][]byte{
×
1432
                testSearchAttrKey: testSearchAttrVal,
×
1433
        }
×
1434

×
1435
        testMemoKey := "memoKey"
×
1436
        testMemoVal, _ := json.Marshal("memoVal")
×
1437
        testMemo := map[string][]byte{
×
1438
                testMemoKey: testMemoVal,
×
1439
        }
×
1440

×
1441
        testPartitionConfig := map[string]string{
×
1442
                "zone": "dca1",
×
1443
        }
×
1444

×
1445
        csum := s.newRandomChecksum()
×
1446
        decisionScheduleID := int64(rand.Int31())
×
1447
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1448
                {
×
1449
                        EventID: decisionScheduleID,
×
1450
                        Version: common.EmptyVersion,
×
1451
                },
×
1452
        })
×
1453
        versionHistories := p.NewVersionHistories(versionHistory)
×
1454
        createReq := &p.CreateWorkflowExecutionRequest{
×
1455
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1456
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1457
                                CreateRequestID:             uuid.New(),
×
1458
                                DomainID:                    uuid.New(),
×
1459
                                WorkflowID:                  "get-workflow-test",
×
1460
                                RunID:                       uuid.New(),
×
1461
                                ParentDomainID:              uuid.New(),
×
1462
                                ParentWorkflowID:            "get-workflow-test-parent",
×
1463
                                ParentRunID:                 uuid.New(),
×
1464
                                InitiatedID:                 rand.Int63(),
×
1465
                                TaskList:                    "get-wf-test-tasklist",
×
1466
                                WorkflowTypeName:            "code.uber.internal/test/workflow",
×
1467
                                WorkflowTimeout:             rand.Int31(),
×
1468
                                DecisionStartToCloseTimeout: rand.Int31(),
×
1469
                                ExecutionContext:            []byte("test-execution-context"),
×
1470
                                State:                       p.WorkflowStateRunning,
×
1471
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1472
                                LastFirstEventID:            common.FirstEventID,
×
1473
                                NextEventID:                 rand.Int63(),
×
1474
                                LastProcessedEvent:          int64(rand.Int31()),
×
1475
                                LastUpdatedTimestamp:        now,
×
1476
                                StartTimestamp:              now,
×
1477
                                SignalCount:                 rand.Int31(),
×
1478
                                DecisionVersion:             int64(rand.Int31()),
×
1479
                                DecisionScheduleID:          decisionScheduleID,
×
1480
                                DecisionStartedID:           int64(rand.Int31()),
×
1481
                                DecisionTimeout:             rand.Int31(),
×
1482
                                Attempt:                     rand.Int31(),
×
1483
                                HasRetryPolicy:              true,
×
1484
                                InitialInterval:             rand.Int31(),
×
1485
                                BackoffCoefficient:          7.78,
×
1486
                                MaximumInterval:             rand.Int31(),
×
1487
                                ExpirationTime:              time.Now(),
×
1488
                                MaximumAttempts:             rand.Int31(),
×
1489
                                NonRetriableErrors:          []string{"badRequestError", "accessDeniedError"},
×
1490
                                CronSchedule:                "* * * * *",
×
1491
                                ExpirationSeconds:           rand.Int31(),
×
1492
                                AutoResetPoints:             &testResetPoints,
×
1493
                                SearchAttributes:            testSearchAttr,
×
1494
                                Memo:                        testMemo,
×
1495
                                PartitionConfig:             testPartitionConfig,
×
1496
                        },
×
1497
                        ExecutionStats: &p.ExecutionStats{
×
1498
                                HistorySize: int64(rand.Int31()),
×
1499
                        },
×
1500
                        Checksum:         csum,
×
1501
                        VersionHistories: versionHistories,
×
1502
                },
×
1503
                Mode: p.CreateWorkflowModeBrandNew,
×
1504
        }
×
1505
        createReq.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = createReq.NewWorkflowSnapshot.ExecutionInfo.RunID
×
1506

×
1507
        createResp, err := s.ExecutionManager.CreateWorkflowExecution(ctx, createReq)
×
1508
        s.NoError(err)
×
1509
        s.NotNil(createResp, "Expected non empty task identifier.")
×
1510

×
1511
        state, err := s.GetWorkflowExecutionInfo(ctx, createReq.NewWorkflowSnapshot.ExecutionInfo.DomainID,
×
1512
                types.WorkflowExecution{
×
1513
                        WorkflowID: createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowID,
×
1514
                        RunID:      createReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
1515
                })
×
1516
        s.NoError(err)
×
1517
        info := state.ExecutionInfo
×
1518
        s.NotNil(info, "Valid Workflow response expected.")
×
1519
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.CreateRequestID, info.CreateRequestID)
×
1520
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DomainID, info.DomainID)
×
1521
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowID, info.WorkflowID)
×
1522
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.RunID, info.RunID)
×
1523
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID, info.FirstExecutionRunID)
×
1524
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ParentDomainID, info.ParentDomainID)
×
1525
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ParentWorkflowID, info.ParentWorkflowID)
×
1526
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ParentRunID, info.ParentRunID)
×
1527
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.InitiatedID, info.InitiatedID)
×
1528
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.TaskList, info.TaskList)
×
1529
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowTypeName, info.WorkflowTypeName)
×
1530
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowTimeout, info.WorkflowTimeout)
×
1531
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionStartToCloseTimeout, info.DecisionStartToCloseTimeout)
×
1532
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ExecutionContext, info.ExecutionContext)
×
1533
        s.Equal(p.WorkflowStateRunning, info.State)
×
1534
        s.Equal(p.WorkflowCloseStatusNone, info.CloseStatus)
×
1535
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.NextEventID, info.NextEventID)
×
1536
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.LastProcessedEvent, info.LastProcessedEvent)
×
1537
        s.Equal(true, s.validateTimeRange(info.LastUpdatedTimestamp, time.Hour))
×
1538
        s.Equal(true, s.validateTimeRange(info.StartTimestamp, time.Hour))
×
1539
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionVersion, info.DecisionVersion)
×
1540
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionScheduleID, info.DecisionScheduleID)
×
1541
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionStartedID, info.DecisionStartedID)
×
1542
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionTimeout, info.DecisionTimeout)
×
1543
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.SignalCount, info.SignalCount)
×
1544
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.Attempt, info.Attempt)
×
1545
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.HasRetryPolicy, info.HasRetryPolicy)
×
1546
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.InitialInterval, info.InitialInterval)
×
1547
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.BackoffCoefficient, info.BackoffCoefficient)
×
1548
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.MaximumAttempts, info.MaximumAttempts)
×
1549
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.MaximumInterval, info.MaximumInterval)
×
1550
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationSeconds, info.ExpirationSeconds)
×
1551
        s.EqualTimes(createReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime, info.ExpirationTime)
×
1552
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.CronSchedule, info.CronSchedule)
×
1553
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.NonRetriableErrors, info.NonRetriableErrors)
×
1554
        s.Equal(testResetPoints, *info.AutoResetPoints)
×
1555
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionStats.HistorySize, state.ExecutionStats.HistorySize)
×
1556
        val, ok := info.SearchAttributes[testSearchAttrKey]
×
1557
        s.True(ok)
×
1558
        s.Equal(testSearchAttrVal, val)
×
1559
        val, ok = info.Memo[testMemoKey]
×
1560
        s.True(ok)
×
1561
        s.Equal(testMemoVal, val)
×
1562
        s.Equal(testPartitionConfig, info.PartitionConfig)
×
1563

×
1564
        s.assertChecksumsEqual(csum, state.Checksum)
×
1565
}
×
1566

1567
// TestUpdateWorkflow test
1568
func (s *ExecutionManagerSuite) TestUpdateWorkflow() {
×
1569
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1570
        defer cancel()
×
1571

×
1572
        domainID := "b0a8571c-0257-40ea-afcd-3a14eae181c0"
×
1573
        workflowExecution := types.WorkflowExecution{
×
1574
                WorkflowID: "update-workflow-test",
×
1575
                RunID:      "5ba5e531-e46b-48d9-b4b3-859919839553",
×
1576
        }
×
1577
        partitionConfig0 := map[string]string{
×
1578
                "userID": uuid.New(),
×
1579
        }
×
1580
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, partitionConfig0)
×
1581
        s.NoError(err0)
×
1582
        s.NotNil(task0, "Expected non empty task identifier.")
×
1583

×
1584
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1585
        s.NoError(err1)
×
1586
        info0 := state0.ExecutionInfo
×
1587
        s.NotNil(info0, "Valid Workflow info expected.")
×
1588
        s.Equal(domainID, info0.DomainID)
×
1589
        s.Equal("update-workflow-test", info0.WorkflowID)
×
1590
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info0.RunID)
×
1591
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info0.FirstExecutionRunID)
×
1592
        s.Equal("queue1", info0.TaskList)
×
1593
        s.Equal("wType", info0.WorkflowTypeName)
×
1594
        s.Equal(int32(20), info0.WorkflowTimeout)
×
1595
        s.Equal(int32(13), info0.DecisionStartToCloseTimeout)
×
1596
        s.Equal([]byte(nil), info0.ExecutionContext)
×
1597
        s.Equal(p.WorkflowStateRunning, info0.State)
×
1598
        s.Equal(p.WorkflowCloseStatusNone, info0.CloseStatus)
×
1599
        s.Equal(int64(1), info0.LastFirstEventID)
×
1600
        s.Equal(int64(3), info0.NextEventID)
×
1601
        s.Equal(int64(0), info0.LastProcessedEvent)
×
1602
        s.Equal(true, s.validateTimeRange(info0.LastUpdatedTimestamp, time.Minute))
×
1603
        s.Equal(true, s.validateTimeRange(info0.StartTimestamp, time.Minute))
×
1604
        s.Equal(int64(0), info0.DecisionVersion)
×
1605
        s.Equal(int64(2), info0.DecisionScheduleID)
×
1606
        s.Equal(common.EmptyEventID, info0.DecisionStartedID)
×
1607
        s.Equal(int32(1), info0.DecisionTimeout)
×
1608
        s.Equal(int64(0), info0.DecisionAttempt)
×
1609
        s.Equal(int64(0), info0.DecisionStartedTimestamp)
×
1610
        s.Equal(int64(0), info0.DecisionScheduledTimestamp)
×
1611
        s.Equal(int64(0), info0.DecisionOriginalScheduledTimestamp)
×
1612
        s.Empty(info0.StickyTaskList)
×
1613
        s.Equal(int32(0), info0.StickyScheduleToStartTimeout)
×
1614
        s.Empty(info0.ClientLibraryVersion)
×
1615
        s.Empty(info0.ClientFeatureVersion)
×
1616
        s.Empty(info0.ClientImpl)
×
1617
        s.Equal(int32(0), info0.SignalCount)
×
1618
        s.Equal(info0.AutoResetPoints, &types.ResetPoints{})
×
1619
        s.True(len(info0.SearchAttributes) == 0)
×
1620
        s.True(len(info0.Memo) == 0)
×
1621
        s.Equal(partitionConfig0, info0.PartitionConfig)
×
1622
        s.assertChecksumsEqual(testWorkflowChecksum, state0.Checksum)
×
1623

×
1624
        s.T().Logf("Workflow execution last updated: %v\n", info0.LastUpdatedTimestamp)
×
1625

×
1626
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
1627
        updatedStats := state0.ExecutionStats
×
1628
        updatedInfo.LastFirstEventID = int64(3)
×
1629
        updatedInfo.NextEventID = int64(5)
×
1630
        updatedInfo.LastProcessedEvent = int64(2)
×
1631
        updatedInfo.DecisionVersion = int64(666)
×
1632
        updatedInfo.DecisionAttempt = int64(123)
×
1633
        updatedInfo.DecisionStartedTimestamp = int64(321)
×
1634
        updatedInfo.DecisionScheduledTimestamp = int64(654)
×
1635
        updatedInfo.DecisionOriginalScheduledTimestamp = int64(655)
×
1636
        updatedInfo.StickyTaskList = "random sticky tasklist"
×
1637
        updatedInfo.StickyScheduleToStartTimeout = 876
×
1638
        updatedInfo.ClientLibraryVersion = "random client library version"
×
1639
        updatedInfo.ClientFeatureVersion = "random client feature version"
×
1640
        updatedInfo.ClientImpl = "random client impl"
×
1641
        updatedInfo.SignalCount = 9
×
1642
        updatedInfo.InitialInterval = math.MaxInt32
×
1643
        updatedInfo.BackoffCoefficient = 4.45
×
1644
        updatedInfo.MaximumInterval = math.MaxInt32
×
1645
        updatedInfo.MaximumAttempts = math.MaxInt32
×
1646
        updatedInfo.ExpirationSeconds = math.MaxInt32
×
1647
        updatedInfo.ExpirationTime = time.Now()
×
1648
        updatedInfo.NonRetriableErrors = []string{"accessDenied", "badRequest"}
×
1649
        searchAttrKey := "env"
×
1650
        searchAttrVal := []byte("test")
×
1651
        updatedInfo.SearchAttributes = map[string][]byte{searchAttrKey: searchAttrVal}
×
1652
        memoKey := "memoKey"
×
1653
        memoVal := []byte("memoVal")
×
1654
        updatedInfo.Memo = map[string][]byte{memoKey: memoVal}
×
1655
        partitionConfig := map[string]string{"zone": "dca2"}
×
1656
        updatedInfo.PartitionConfig = partitionConfig
×
1657
        updatedStats.HistorySize = math.MaxInt64
×
1658
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1659
                {
×
1660
                        EventID: updatedInfo.NextEventID,
×
1661
                        Version: common.EmptyVersion,
×
1662
                },
×
1663
        })
×
1664
        versionHistories := p.NewVersionHistories(versionHistory)
×
1665

×
1666
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, nil, nil, nil, nil)
×
1667
        s.NoError(err2)
×
1668

×
1669
        state1, err3 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1670
        s.NoError(err3)
×
1671
        info1 := state1.ExecutionInfo
×
1672
        s.NotNil(info1, "Valid Workflow info expected.")
×
1673
        s.Equal(domainID, info1.DomainID)
×
1674
        s.Equal("update-workflow-test", info1.WorkflowID)
×
1675
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info1.RunID)
×
1676
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info1.FirstExecutionRunID)
×
1677
        s.Equal("queue1", info1.TaskList)
×
1678
        s.Equal("wType", info1.WorkflowTypeName)
×
1679
        s.Equal(int32(20), info1.WorkflowTimeout)
×
1680
        s.Equal(int32(13), info1.DecisionStartToCloseTimeout)
×
1681
        s.Equal([]byte(nil), info1.ExecutionContext)
×
1682
        s.Equal(p.WorkflowStateRunning, info1.State)
×
1683
        s.Equal(p.WorkflowCloseStatusNone, info1.CloseStatus)
×
1684
        s.Equal(int64(3), info1.LastFirstEventID)
×
1685
        s.Equal(int64(5), info1.NextEventID)
×
1686
        s.Equal(int64(2), info1.LastProcessedEvent)
×
1687
        s.Equal(true, s.validateTimeRange(info1.LastUpdatedTimestamp, time.Hour))
×
1688
        s.Equal(info0.StartTimestamp.UnixNano(), info1.StartTimestamp.UnixNano())
×
1689
        s.Equal(int64(666), info1.DecisionVersion)
×
1690
        s.Equal(int64(2), info1.DecisionScheduleID)
×
1691
        s.Equal(common.EmptyEventID, info1.DecisionStartedID)
×
1692
        s.Equal(int32(1), info1.DecisionTimeout)
×
1693
        s.Equal(int64(123), info1.DecisionAttempt)
×
1694
        s.Equal(int64(321), info1.DecisionStartedTimestamp)
×
1695
        s.Equal(int64(654), info1.DecisionScheduledTimestamp)
×
1696
        s.Equal(int64(655), info1.DecisionOriginalScheduledTimestamp)
×
1697
        s.Equal(updatedInfo.StickyTaskList, info1.StickyTaskList)
×
1698
        s.Equal(updatedInfo.StickyScheduleToStartTimeout, info1.StickyScheduleToStartTimeout)
×
1699
        s.Equal(updatedInfo.ClientLibraryVersion, info1.ClientLibraryVersion)
×
1700
        s.Equal(updatedInfo.ClientFeatureVersion, info1.ClientFeatureVersion)
×
1701
        s.Equal(updatedInfo.ClientImpl, info1.ClientImpl)
×
1702
        s.Equal(updatedInfo.SignalCount, info1.SignalCount)
×
1703
        s.EqualValues(updatedStats.HistorySize, state1.ExecutionStats.HistorySize)
×
1704
        s.Equal(updatedInfo.InitialInterval, info1.InitialInterval)
×
1705
        s.Equal(updatedInfo.BackoffCoefficient, info1.BackoffCoefficient)
×
1706
        s.Equal(updatedInfo.MaximumInterval, info1.MaximumInterval)
×
1707
        s.Equal(updatedInfo.MaximumAttempts, info1.MaximumAttempts)
×
1708
        s.Equal(updatedInfo.ExpirationSeconds, info1.ExpirationSeconds)
×
1709
        s.EqualTimes(updatedInfo.ExpirationTime, info1.ExpirationTime)
×
1710
        s.Equal(updatedInfo.NonRetriableErrors, info1.NonRetriableErrors)
×
1711
        searchAttrVal1, ok := info1.SearchAttributes[searchAttrKey]
×
1712
        s.True(ok)
×
1713
        s.Equal(searchAttrVal, searchAttrVal1)
×
1714
        memoVal1, ok := info1.Memo[memoKey]
×
1715
        s.True(ok)
×
1716
        s.Equal(memoVal, memoVal1)
×
1717
        s.Equal(partitionConfig, info1.PartitionConfig)
×
1718
        s.assertChecksumsEqual(testWorkflowChecksum, state1.Checksum)
×
1719

×
1720
        s.T().Logf("Workflow execution last updated: %v\n", info1.LastUpdatedTimestamp)
×
1721

×
1722
        failedUpdateInfo := copyWorkflowExecutionInfo(updatedInfo)
×
1723
        failedUpdateStats := copyExecutionStats(updatedStats)
×
1724
        err4 := s.UpdateWorkflowExecution(ctx, failedUpdateInfo, failedUpdateStats, versionHistories, []int64{int64(5)}, nil, int64(3), nil, nil, nil, nil, nil)
×
1725
        s.Error(err4, "expected non nil error.")
×
1726
        s.IsType(&p.ConditionFailedError{}, err4)
×
1727

×
1728
        state2, err4 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1729
        s.NoError(err4)
×
1730
        info2 := state2.ExecutionInfo
×
1731
        s.NotNil(info2, "Valid Workflow info expected.")
×
1732
        s.Equal(domainID, info2.DomainID)
×
1733
        s.Equal("update-workflow-test", info2.WorkflowID)
×
1734
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info2.RunID)
×
1735
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info2.FirstExecutionRunID)
×
1736
        s.Equal("queue1", info2.TaskList)
×
1737
        s.Equal("wType", info2.WorkflowTypeName)
×
1738
        s.Equal(int32(20), info2.WorkflowTimeout)
×
1739
        s.Equal(int32(13), info2.DecisionStartToCloseTimeout)
×
1740
        s.Equal([]byte(nil), info2.ExecutionContext)
×
1741
        s.Equal(p.WorkflowStateRunning, info2.State)
×
1742
        s.Equal(p.WorkflowCloseStatusNone, info2.CloseStatus)
×
1743
        s.Equal(int64(5), info2.NextEventID)
×
1744
        s.Equal(int64(2), info2.LastProcessedEvent)
×
1745
        s.Equal(true, s.validateTimeRange(info2.LastUpdatedTimestamp, time.Hour))
×
1746
        s.Equal(int64(666), info2.DecisionVersion)
×
1747
        s.Equal(int64(2), info2.DecisionScheduleID)
×
1748
        s.Equal(common.EmptyEventID, info2.DecisionStartedID)
×
1749
        s.Equal(int32(1), info2.DecisionTimeout)
×
1750
        s.Equal(int64(123), info2.DecisionAttempt)
×
1751
        s.Equal(int64(321), info2.DecisionStartedTimestamp)
×
1752
        s.Equal(int64(654), info2.DecisionScheduledTimestamp)
×
1753
        s.Equal(int64(655), info2.DecisionOriginalScheduledTimestamp)
×
1754
        s.Equal(updatedInfo.SignalCount, info2.SignalCount)
×
1755
        s.EqualValues(updatedStats.HistorySize, state2.ExecutionStats.HistorySize)
×
1756
        s.Equal(updatedInfo.InitialInterval, info2.InitialInterval)
×
1757
        s.Equal(updatedInfo.BackoffCoefficient, info2.BackoffCoefficient)
×
1758
        s.Equal(updatedInfo.MaximumInterval, info2.MaximumInterval)
×
1759
        s.Equal(updatedInfo.MaximumAttempts, info2.MaximumAttempts)
×
1760
        s.Equal(updatedInfo.ExpirationSeconds, info2.ExpirationSeconds)
×
1761
        s.EqualTimes(updatedInfo.ExpirationTime, info2.ExpirationTime)
×
1762
        s.Equal(updatedInfo.NonRetriableErrors, info2.NonRetriableErrors)
×
1763
        searchAttrVal2, ok := info2.SearchAttributes[searchAttrKey]
×
1764
        s.True(ok)
×
1765
        s.Equal(searchAttrVal, searchAttrVal2)
×
1766
        memoVal2, ok := info1.Memo[memoKey]
×
1767
        s.True(ok)
×
1768
        s.Equal(memoVal, memoVal2)
×
1769
        s.Equal(partitionConfig, info2.PartitionConfig)
×
1770
        s.assertChecksumsEqual(testWorkflowChecksum, state2.Checksum)
×
1771
        s.T().Logf("Workflow execution last updated: %v", info2.LastUpdatedTimestamp)
×
1772

×
1773
        err5 := s.UpdateWorkflowExecutionWithRangeID(ctx, failedUpdateInfo, failedUpdateStats, versionHistories, []int64{int64(5)}, nil, int64(12345), int64(5), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
×
1774
        s.Error(err5, "expected non nil error.")
×
1775
        s.IsType(&p.ShardOwnershipLostError{}, err5)
×
1776

×
1777
        state3, err6 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1778
        s.NoError(err6)
×
1779
        info3 := state3.ExecutionInfo
×
1780
        s.NotNil(info3, "Valid Workflow info expected.")
×
1781
        s.Equal(domainID, info3.DomainID)
×
1782
        s.Equal("update-workflow-test", info3.WorkflowID)
×
1783
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info3.RunID)
×
1784
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info3.FirstExecutionRunID)
×
1785
        s.Equal("queue1", info3.TaskList)
×
1786
        s.Equal("wType", info3.WorkflowTypeName)
×
1787
        s.Equal(int32(20), info3.WorkflowTimeout)
×
1788
        s.Equal(int32(13), info3.DecisionStartToCloseTimeout)
×
1789
        s.Equal([]byte(nil), info3.ExecutionContext)
×
1790
        s.Equal(p.WorkflowStateRunning, info3.State)
×
1791
        s.Equal(p.WorkflowCloseStatusNone, info3.CloseStatus)
×
1792
        s.Equal(int64(5), info3.NextEventID)
×
1793
        s.Equal(int64(2), info3.LastProcessedEvent)
×
1794
        s.Equal(true, s.validateTimeRange(info3.LastUpdatedTimestamp, time.Hour))
×
1795
        s.Equal(int64(666), info3.DecisionVersion)
×
1796
        s.Equal(int64(2), info3.DecisionScheduleID)
×
1797
        s.Equal(common.EmptyEventID, info3.DecisionStartedID)
×
1798
        s.Equal(int32(1), info3.DecisionTimeout)
×
1799
        s.Equal(int64(123), info3.DecisionAttempt)
×
1800
        s.Equal(int64(321), info3.DecisionStartedTimestamp)
×
1801
        s.Equal(int64(654), info3.DecisionScheduledTimestamp)
×
1802
        s.Equal(int64(655), info3.DecisionOriginalScheduledTimestamp)
×
1803
        s.Equal(updatedInfo.SignalCount, info3.SignalCount)
×
1804
        s.EqualValues(updatedStats.HistorySize, state3.ExecutionStats.HistorySize)
×
1805
        s.Equal(updatedInfo.InitialInterval, info3.InitialInterval)
×
1806
        s.Equal(updatedInfo.BackoffCoefficient, info3.BackoffCoefficient)
×
1807
        s.Equal(updatedInfo.MaximumInterval, info3.MaximumInterval)
×
1808
        s.Equal(updatedInfo.MaximumAttempts, info3.MaximumAttempts)
×
1809
        s.Equal(updatedInfo.ExpirationSeconds, info3.ExpirationSeconds)
×
1810
        s.EqualTimes(updatedInfo.ExpirationTime, info3.ExpirationTime)
×
1811
        s.Equal(updatedInfo.NonRetriableErrors, info3.NonRetriableErrors)
×
1812
        searchAttrVal3, ok := info3.SearchAttributes[searchAttrKey]
×
1813
        s.True(ok)
×
1814
        s.Equal(searchAttrVal, searchAttrVal3)
×
1815
        memoVal3, ok := info1.Memo[memoKey]
×
1816
        s.True(ok)
×
1817
        s.Equal(memoVal, memoVal3)
×
1818
        s.Equal(partitionConfig, info3.PartitionConfig)
×
1819
        s.assertChecksumsEqual(testWorkflowChecksum, state3.Checksum)
×
1820

×
1821
        s.T().Logf("Workflow execution last updated: %v\n", info3.LastUpdatedTimestamp)
×
1822

×
1823
        // update with incorrect rangeID and condition(next_event_id)
×
1824
        err7 := s.UpdateWorkflowExecutionWithRangeID(ctx, failedUpdateInfo, failedUpdateStats, versionHistories, []int64{int64(5)}, nil, int64(12345), int64(3), nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil, nil)
×
1825
        s.Error(err7, "expected non nil error.")
×
1826
        s.IsType(&p.ShardOwnershipLostError{}, err7)
×
1827

×
1828
        state4, err8 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1829
        s.NoError(err8)
×
1830
        info4 := state4.ExecutionInfo
×
1831
        s.NotNil(info4, "Valid Workflow info expected.")
×
1832
        s.Equal(domainID, info4.DomainID)
×
1833
        s.Equal("update-workflow-test", info4.WorkflowID)
×
1834
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info4.RunID)
×
1835
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info4.FirstExecutionRunID)
×
1836
        s.Equal("queue1", info4.TaskList)
×
1837
        s.Equal("wType", info4.WorkflowTypeName)
×
1838
        s.Equal(int32(20), info4.WorkflowTimeout)
×
1839
        s.Equal(int32(13), info4.DecisionStartToCloseTimeout)
×
1840
        s.Equal([]byte(nil), info4.ExecutionContext)
×
1841
        s.Equal(p.WorkflowStateRunning, info4.State)
×
1842
        s.Equal(p.WorkflowCloseStatusNone, info4.CloseStatus)
×
1843
        s.Equal(int64(5), info4.NextEventID)
×
1844
        s.Equal(int64(2), info4.LastProcessedEvent)
×
1845
        s.Equal(true, s.validateTimeRange(info4.LastUpdatedTimestamp, time.Hour))
×
1846
        s.Equal(int64(666), info4.DecisionVersion)
×
1847
        s.Equal(int64(2), info4.DecisionScheduleID)
×
1848
        s.Equal(common.EmptyEventID, info4.DecisionStartedID)
×
1849
        s.Equal(int32(1), info4.DecisionTimeout)
×
1850
        s.Equal(int64(123), info4.DecisionAttempt)
×
1851
        s.Equal(int64(321), info4.DecisionStartedTimestamp)
×
1852
        s.Equal(updatedInfo.SignalCount, info4.SignalCount)
×
1853
        s.EqualValues(updatedStats.HistorySize, state4.ExecutionStats.HistorySize)
×
1854
        s.Equal(updatedInfo.InitialInterval, info4.InitialInterval)
×
1855
        s.Equal(updatedInfo.BackoffCoefficient, info4.BackoffCoefficient)
×
1856
        s.Equal(updatedInfo.MaximumInterval, info4.MaximumInterval)
×
1857
        s.Equal(updatedInfo.MaximumAttempts, info4.MaximumAttempts)
×
1858
        s.Equal(updatedInfo.ExpirationSeconds, info4.ExpirationSeconds)
×
1859
        s.EqualTimes(updatedInfo.ExpirationTime, info4.ExpirationTime)
×
1860
        s.Equal(updatedInfo.NonRetriableErrors, info4.NonRetriableErrors)
×
1861
        searchAttrVal4, ok := info4.SearchAttributes[searchAttrKey]
×
1862
        s.True(ok)
×
1863
        s.Equal(searchAttrVal, searchAttrVal4)
×
1864
        memoVal4, ok := info1.Memo[memoKey]
×
1865
        s.True(ok)
×
1866
        s.Equal(memoVal, memoVal4)
×
1867
        s.Equal(partitionConfig, info4.PartitionConfig)
×
1868
        s.assertChecksumsEqual(testWorkflowChecksum, state4.Checksum)
×
1869

×
1870
        s.T().Logf("Workflow execution last updated: %v\n", info4.LastUpdatedTimestamp)
×
1871
}
×
1872

1873
// TestDeleteWorkflow test
1874
func (s *ExecutionManagerSuite) TestDeleteWorkflow() {
×
1875
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1876
        defer cancel()
×
1877

×
1878
        domainID := "1d4abb23-b87b-457b-96ef-43aba0b9c44f"
×
1879
        workflowExecution := types.WorkflowExecution{
×
1880
                WorkflowID: "delete-workflow-test",
×
1881
                RunID:      "4e0917f2-9361-4a14-b16f-1fafe09b287a",
×
1882
        }
×
1883
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1884
        s.NoError(err0)
×
1885
        s.NotNil(task0, "Expected non empty task identifier.")
×
1886

×
1887
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1888
        s.NoError(err1)
×
1889
        info0 := state0.ExecutionInfo
×
1890
        s.NotNil(info0, "Valid Workflow info expected.")
×
1891
        s.Equal(domainID, info0.DomainID)
×
1892
        s.Equal("delete-workflow-test", info0.WorkflowID)
×
1893
        s.Equal("4e0917f2-9361-4a14-b16f-1fafe09b287a", info0.RunID)
×
1894
        s.Equal("4e0917f2-9361-4a14-b16f-1fafe09b287a", info0.FirstExecutionRunID)
×
1895
        s.Equal("queue1", info0.TaskList)
×
1896
        s.Equal("wType", info0.WorkflowTypeName)
×
1897
        s.Equal(int32(20), info0.WorkflowTimeout)
×
1898
        s.Equal(int32(13), info0.DecisionStartToCloseTimeout)
×
1899
        s.Equal([]byte(nil), info0.ExecutionContext)
×
1900
        s.Equal(p.WorkflowStateRunning, info0.State)
×
1901
        s.Equal(p.WorkflowCloseStatusNone, info0.CloseStatus)
×
1902
        s.Equal(int64(3), info0.NextEventID)
×
1903
        s.Equal(int64(0), info0.LastProcessedEvent)
×
1904
        s.Equal(true, s.validateTimeRange(info0.LastUpdatedTimestamp, time.Hour))
×
1905
        s.Equal(int64(2), info0.DecisionScheduleID)
×
1906
        s.Equal(common.EmptyEventID, info0.DecisionStartedID)
×
1907
        s.Equal(int32(1), info0.DecisionTimeout)
×
1908

×
1909
        s.T().Logf("Workflow execution last updated: %v\n", info0.LastUpdatedTimestamp)
×
1910

×
1911
        err4 := s.DeleteWorkflowExecution(ctx, info0)
×
1912
        s.NoError(err4)
×
1913

×
1914
        _, err3 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1915
        s.Error(err3, "expected non nil error.")
×
1916
        s.IsType(&types.EntityNotExistsError{}, err3)
×
1917

×
1918
        err5 := s.DeleteWorkflowExecution(ctx, info0)
×
1919
        s.NoError(err5)
×
1920
}
×
1921

1922
// TestDeleteCurrentWorkflow test
1923
func (s *ExecutionManagerSuite) TestDeleteCurrentWorkflow() {
×
1924
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1925
        defer cancel()
×
1926

×
1927
        if s.ExecutionManager.GetName() != "cassandra" {
×
1928
                // "this test is only applicable for cassandra (uses TTL based deletes)"
×
1929
                return
×
1930
        }
×
1931
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
1932
        workflowExecution := types.WorkflowExecution{
×
1933
                WorkflowID: "delete-current-workflow-test",
×
1934
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
1935
        }
×
1936

×
1937
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1938
        s.NoError(err0)
×
1939
        s.NotNil(task0, "Expected non empty task identifier.")
×
1940

×
1941
        runID0, err1 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1942
        s.NoError(err1)
×
1943
        s.Equal(workflowExecution.GetRunID(), runID0)
×
1944

×
1945
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1946
        s.NoError(err2)
×
1947

×
1948
        updatedInfo1 := copyWorkflowExecutionInfo(info0.ExecutionInfo)
×
1949
        updatedStats1 := copyExecutionStats(info0.ExecutionStats)
×
1950
        updatedInfo1.NextEventID = int64(6)
×
1951
        updatedInfo1.LastProcessedEvent = int64(2)
×
1952
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1953
                {
×
1954
                        EventID: updatedInfo1.LastProcessedEvent,
×
1955
                        Version: common.EmptyVersion,
×
1956
                },
×
1957
        })
×
1958
        versionHistories := p.NewVersionHistories(versionHistory)
×
1959
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(3), versionHistories)
×
1960
        s.NoError(err3)
×
1961

×
1962
        runID4, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1963
        s.NoError(err4)
×
1964
        s.Equal(workflowExecution.GetRunID(), runID4)
×
1965

×
1966
        fakeInfo := &p.WorkflowExecutionInfo{
×
1967
                DomainID:   info0.ExecutionInfo.DomainID,
×
1968
                WorkflowID: info0.ExecutionInfo.WorkflowID,
×
1969
                RunID:      uuid.New(),
×
1970
        }
×
1971

×
1972
        // test wrong run id with conditional delete
×
1973
        s.NoError(s.DeleteCurrentWorkflowExecution(ctx, fakeInfo))
×
1974

×
1975
        runID5, err5 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1976
        s.NoError(err5)
×
1977
        s.Equal(workflowExecution.GetRunID(), runID5)
×
1978

×
1979
        // simulate a timer_task deleting execution after retention
×
1980
        s.NoError(s.DeleteCurrentWorkflowExecution(ctx, info0.ExecutionInfo))
×
1981

×
1982
        runID0, err1 = s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1983
        s.Error(err1)
×
1984
        s.Empty(runID0)
×
1985
        _, ok := err1.(*types.EntityNotExistsError)
×
1986
        s.True(ok)
×
1987

×
1988
        // execution record should still be there
×
1989
        _, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1990
        s.NoError(err2)
×
1991
}
1992

1993
// TestUpdateDeleteWorkflow mocks the timer behavior to clean up workflow.
1994
func (s *ExecutionManagerSuite) TestUpdateDeleteWorkflow() {
×
1995
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1996
        defer cancel()
×
1997

×
1998
        finishedCurrentExecutionRetentionTTL := int32(2)
×
1999
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
2000
        workflowExecution := types.WorkflowExecution{
×
2001
                WorkflowID: "update-delete-workflow-test",
×
2002
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
2003
        }
×
2004

×
2005
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2006
        s.NoError(err0)
×
2007
        s.NotNil(task0, "Expected non empty task identifier.")
×
2008

×
2009
        runID0, err1 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
2010
        s.NoError(err1)
×
2011
        s.Equal(workflowExecution.GetRunID(), runID0)
×
2012

×
2013
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2014
        s.NoError(err2)
×
2015

×
2016
        updatedInfo1 := copyWorkflowExecutionInfo(info0.ExecutionInfo)
×
2017
        updatedStats1 := copyExecutionStats(info0.ExecutionStats)
×
2018
        updatedInfo1.NextEventID = int64(6)
×
2019
        updatedInfo1.LastProcessedEvent = int64(2)
×
2020
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2021
                {
×
2022
                        EventID: updatedInfo1.LastProcessedEvent,
×
2023
                        Version: common.EmptyVersion,
×
2024
                },
×
2025
        })
×
2026
        versionHistories := p.NewVersionHistories(versionHistory)
×
2027
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(3), versionHistories)
×
2028
        s.NoError(err3)
×
2029

×
2030
        runID4, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
2031
        s.NoError(err4)
×
2032
        s.Equal(workflowExecution.GetRunID(), runID4)
×
2033

×
2034
        // simulate a timer_task deleting execution after retention
×
2035
        err5 := s.DeleteCurrentWorkflowExecution(ctx, info0.ExecutionInfo)
×
2036
        s.NoError(err5)
×
2037
        err6 := s.DeleteWorkflowExecution(ctx, info0.ExecutionInfo)
×
2038
        s.NoError(err6)
×
2039

×
2040
        time.Sleep(time.Duration(finishedCurrentExecutionRetentionTTL*2) * time.Second)
×
2041

×
2042
        runID0, err1 = s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
2043
        s.Error(err1)
×
2044
        s.Empty(runID0)
×
2045
        _, ok := err1.(*types.EntityNotExistsError)
×
2046
        s.True(ok)
×
2047

×
2048
        // execution record should still be there
×
2049
        _, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2050
        s.Error(err2)
×
2051
        _, ok = err2.(*types.EntityNotExistsError)
×
2052
        s.True(ok)
×
2053
}
×
2054

2055
// TestCleanupCorruptedWorkflow test
2056
func (s *ExecutionManagerSuite) TestCleanupCorruptedWorkflow() {
×
2057
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2058
        defer cancel()
×
2059

×
2060
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
2061
        workflowExecution := types.WorkflowExecution{
×
2062
                WorkflowID: "cleanup-corrupted-workflow-test",
×
2063
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
2064
        }
×
2065

×
2066
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2067
        s.NoError(err0)
×
2068
        s.NotNil(task0, "Expected non empty task identifier.")
×
2069

×
2070
        runID0, err1 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
2071
        s.NoError(err1)
×
2072
        s.Equal(workflowExecution.GetRunID(), runID0)
×
2073

×
2074
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2075
        s.NoError(err2)
×
2076

×
2077
        // deleting current record and verify
×
2078
        err3 := s.DeleteCurrentWorkflowExecution(ctx, info0.ExecutionInfo)
×
2079
        s.NoError(err3)
×
2080
        runID0, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
2081
        s.Error(err4)
×
2082
        s.Empty(runID0)
×
2083
        _, ok := err4.(*types.EntityNotExistsError)
×
2084
        s.True(ok)
×
2085

×
2086
        // we should still be able to load with runID
×
2087
        info1, err5 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2088
        s.NoError(err5)
×
2089
        s.Equal(info0, info1)
×
2090

×
2091
        // mark it as corrupted
×
2092
        info0.ExecutionInfo.State = p.WorkflowStateCorrupted
×
2093
        _, err6 := s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
2094
                UpdateWorkflowMutation: p.WorkflowMutation{
×
2095
                        ExecutionInfo:    info0.ExecutionInfo,
×
2096
                        ExecutionStats:   info0.ExecutionStats,
×
2097
                        Condition:        info0.ExecutionInfo.NextEventID,
×
2098
                        Checksum:         testWorkflowChecksum,
×
2099
                        VersionHistories: info0.VersionHistories,
×
2100
                },
×
2101
                RangeID: s.ShardInfo.RangeID,
×
2102
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
2103
        })
×
2104
        s.NoError(err6)
×
2105

×
2106
        // we should still be able to load with runID
×
2107
        info2, err7 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2108
        s.NoError(err7)
×
2109
        s.Equal(p.WorkflowStateCorrupted, info2.ExecutionInfo.State)
×
2110
        info2.ExecutionInfo.State = info1.ExecutionInfo.State
×
2111
        info2.ExecutionInfo.LastUpdatedTimestamp = info1.ExecutionInfo.LastUpdatedTimestamp
×
2112
        s.Equal(info2, info1)
×
2113

×
2114
        // delete the run
×
2115
        err8 := s.DeleteWorkflowExecution(ctx, info0.ExecutionInfo)
×
2116
        s.NoError(err8)
×
2117

×
2118
        // execution record should be gone
×
2119
        _, err9 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2120
        s.Error(err9)
×
2121
        _, ok = err9.(*types.EntityNotExistsError)
×
2122
        s.True(ok)
×
2123
}
×
2124

2125
// TestGetCurrentWorkflow test
2126
func (s *ExecutionManagerSuite) TestGetCurrentWorkflow() {
×
2127
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2128
        defer cancel()
×
2129

×
2130
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
2131
        workflowExecution := types.WorkflowExecution{
×
2132
                WorkflowID: "get-current-workflow-test",
×
2133
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
2134
        }
×
2135

×
2136
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2137
        s.NoError(err0)
×
2138
        s.NotNil(task0, "Expected non empty task identifier.")
×
2139

×
2140
        response, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
2141
                DomainID:   domainID,
×
2142
                WorkflowID: workflowExecution.GetWorkflowID(),
×
2143
        })
×
2144
        s.NoError(err)
×
2145
        s.Equal(workflowExecution.GetRunID(), response.RunID)
×
2146
        s.Equal(common.EmptyVersion, response.LastWriteVersion)
×
2147

×
2148
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2149
        s.NoError(err2)
×
2150

×
2151
        updatedInfo1 := copyWorkflowExecutionInfo(info0.ExecutionInfo)
×
2152
        updatedStats1 := copyExecutionStats(info0.ExecutionStats)
×
2153
        updatedInfo1.NextEventID = int64(6)
×
2154
        updatedInfo1.LastProcessedEvent = int64(2)
×
2155
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2156
                {
×
2157
                        EventID: updatedInfo1.LastProcessedEvent,
×
2158
                        Version: common.EmptyVersion,
×
2159
                },
×
2160
        })
×
2161
        versionHistories := p.NewVersionHistories(versionHistory)
×
2162
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(3), versionHistories)
×
2163
        s.NoError(err3)
×
2164

×
2165
        runID4, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
2166
        s.NoError(err4)
×
2167
        s.Equal(workflowExecution.GetRunID(), runID4)
×
2168

×
2169
        workflowExecution2 := types.WorkflowExecution{
×
2170
                WorkflowID: "get-current-workflow-test",
×
2171
                RunID:      "c3ff4bc6-de18-4643-83b2-037a33f45322",
×
2172
        }
×
2173

×
2174
        task1, err5 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution2, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2175
        s.Error(err5, "Error expected.")
×
2176
        s.Empty(task1, "Expected empty task identifier.")
×
2177
}
×
2178

2179
// TestTransferTasksThroughUpdate test
2180
func (s *ExecutionManagerSuite) TestTransferTasksThroughUpdate() {
×
2181
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2182
        defer cancel()
×
2183

×
2184
        domainID := "b785a8ba-bd7d-4760-bb05-41b115f3e10a"
×
2185
        workflowExecution := types.WorkflowExecution{
×
2186
                WorkflowID: "get-transfer-tasks-through-update-test",
×
2187
                RunID:      "30a9fa1f-0db1-4d7a-8c34-aa82c5dad3aa",
×
2188
        }
×
2189

×
2190
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2191
        s.NoError(err0)
×
2192
        s.NotNil(task0, "Expected non empty task identifier.")
×
2193

×
2194
        tasks1, err1 := s.GetTransferTasks(ctx, 1, false)
×
2195
        s.NoError(err1)
×
2196
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2197
        s.Equal(1, len(tasks1), "Expected 1 decision task.")
×
2198
        task1 := tasks1[0]
×
2199
        s.Equal(domainID, task1.DomainID)
×
2200
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2201
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2202
        s.Equal("queue1", task1.TaskList)
×
2203
        s.Equal(p.TransferTaskTypeDecisionTask, task1.TaskType)
×
2204
        s.Equal(int64(2), task1.ScheduleID)
×
2205
        s.Equal("", task1.TargetRunID)
×
2206

×
2207
        err3 := s.CompleteTransferTask(ctx, task1.TaskID)
×
2208
        s.NoError(err3)
×
2209

×
2210
        state0, err11 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2211
        s.NoError(err11)
×
2212
        info0 := state0.ExecutionInfo
×
2213
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2214
        updatedStats0 := copyExecutionStats(state0.ExecutionStats)
×
2215
        updatedInfo.NextEventID = int64(5)
×
2216
        updatedInfo.LastProcessedEvent = int64(2)
×
2217
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2218
                {
×
2219
                        EventID: updatedInfo.LastProcessedEvent,
×
2220
                        Version: common.EmptyVersion,
×
2221
                },
×
2222
        })
×
2223
        versionHistories := p.NewVersionHistories(versionHistory)
×
2224
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats0, versionHistories, nil, []int64{int64(4)}, int64(3), nil, nil, nil, nil, nil)
×
2225
        s.NoError(err2)
×
2226

×
2227
        tasks2, err1 := s.GetTransferTasks(ctx, 1, false)
×
2228
        s.NoError(err1)
×
2229
        s.NotNil(tasks2, "expected valid list of tasks.")
×
2230
        s.Equal(1, len(tasks2), "Expected 1 decision task.")
×
2231
        task2 := tasks2[0]
×
2232
        s.Equal(domainID, task2.DomainID)
×
2233
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
2234
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
2235
        s.Equal("queue1", task2.TaskList)
×
2236
        s.Equal(p.TransferTaskTypeActivityTask, task2.TaskType)
×
2237
        s.Equal(int64(4), task2.ScheduleID)
×
2238
        s.Equal("", task2.TargetRunID)
×
2239

×
2240
        err4 := s.CompleteTransferTask(ctx, task2.TaskID)
×
2241
        s.NoError(err4)
×
2242

×
2243
        state1, _ := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2244
        info1 := state1.ExecutionInfo
×
2245
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2246
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2247
        updatedInfo1.NextEventID = int64(6)
×
2248
        updatedInfo1.LastProcessedEvent = int64(2)
×
2249
        err5 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(5), versionHistories)
×
2250
        s.NoError(err5)
×
2251

×
2252
        newExecution := types.WorkflowExecution{
×
2253
                WorkflowID: workflowExecution.GetWorkflowID(),
×
2254
                RunID:      "2a038c8f-b575-4151-8d2c-d443e999ab5a",
×
2255
        }
×
2256
        runID6, err6 := s.GetCurrentWorkflowRunID(ctx, domainID, newExecution.GetWorkflowID())
×
2257
        s.NoError(err6)
×
2258
        s.Equal(workflowExecution.GetRunID(), runID6)
×
2259

×
2260
        tasks3, err7 := s.GetTransferTasks(ctx, 1, false)
×
2261
        s.NoError(err7)
×
2262
        s.NotNil(tasks3, "expected valid list of tasks.")
×
2263
        s.Equal(1, len(tasks3), "Expected 1 decision task.")
×
2264
        task3 := tasks3[0]
×
2265
        s.Equal(domainID, task3.DomainID)
×
2266
        s.Equal(workflowExecution.GetWorkflowID(), task3.WorkflowID)
×
2267
        s.Equal(workflowExecution.GetRunID(), task3.RunID)
×
2268
        s.Equal(p.TransferTaskTypeCloseExecution, task3.TaskType)
×
2269
        s.Equal("", task3.TargetRunID)
×
2270

×
2271
        err8 := s.CompleteTransferTask(ctx, task3.TaskID)
×
2272
        s.NoError(err8)
×
2273

×
2274
        _, err9 := s.CreateWorkflowExecution(ctx, domainID, newExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2275
        s.Error(err9, "createWFExecution (brand_new) must fail when there is a previous instance of workflow state already in DB")
×
2276

×
2277
        err10 := s.DeleteWorkflowExecution(ctx, info1)
×
2278
        s.NoError(err10)
×
2279
}
×
2280

2281
// TestCancelTransferTaskTasks test
2282
func (s *ExecutionManagerSuite) TestCancelTransferTaskTasks() {
×
2283
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2284
        defer cancel()
×
2285

×
2286
        domainID := "aeac8287-527b-4b35-80a9-667cb47e7c6d"
×
2287
        workflowExecution := types.WorkflowExecution{
×
2288
                WorkflowID: "cancel-workflow-test",
×
2289
                RunID:      "db20f7e2-1a1e-40d9-9278-d8b886738e05",
×
2290
        }
×
2291

×
2292
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2293
        s.NoError(err)
×
2294
        s.NotNil(task0, "Expected non empty task identifier.")
×
2295

×
2296
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
2297
        s.NoError(err)
×
2298
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
2299
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
2300
        s.NoError(err)
×
2301

×
2302
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2303
        s.NoError(err)
×
2304
        info1 := state1.ExecutionInfo
×
2305
        s.NotNil(info1, "Valid Workflow info expected.")
×
2306
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2307
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2308

×
2309
        targetDomainID := "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2310
        targetWorkflowID := "target-workflow-cancellation-id-1"
×
2311
        targetRunID := "0d00698f-08e1-4d36-a3e2-3bf109f5d2d6"
×
2312
        targetChildWorkflowOnly := false
×
2313
        transferTasks := []p.Task{&p.CancelExecutionTask{
×
2314
                TaskData: p.TaskData{
×
2315
                        TaskID: s.GetNextSequenceNumber(),
×
2316
                },
×
2317
                TargetDomainID:          targetDomainID,
×
2318
                TargetWorkflowID:        targetWorkflowID,
×
2319
                TargetRunID:             targetRunID,
×
2320
                TargetChildWorkflowOnly: targetChildWorkflowOnly,
×
2321
                InitiatedID:             1,
×
2322
        }}
×
2323
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2324
                {
×
2325
                        EventID: 1,
×
2326
                        Version: common.EmptyVersion,
×
2327
                },
×
2328
        })
×
2329
        versionHistories := p.NewVersionHistories(versionHistory)
×
2330
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo1, updatedStats1, int64(3), transferTasks, nil, versionHistories)
×
2331
        s.NoError(err)
×
2332

×
2333
        tasks1, err := s.GetTransferTasks(ctx, 1, false)
×
2334
        s.NoError(err)
×
2335
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2336
        s.Equal(1, len(tasks1), "Expected 1 cancel task.")
×
2337
        task1 := tasks1[0]
×
2338
        s.Equal(p.TransferTaskTypeCancelExecution, task1.TaskType)
×
2339
        s.Equal(domainID, task1.DomainID)
×
2340
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2341
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2342
        s.Equal(targetDomainID, task1.TargetDomainID)
×
2343
        s.Equal(targetWorkflowID, task1.TargetWorkflowID)
×
2344
        s.Equal(targetRunID, task1.TargetRunID)
×
2345
        s.Equal(false, task1.TargetChildWorkflowOnly)
×
2346

×
2347
        err = s.CompleteTransferTask(ctx, task1.TaskID)
×
2348
        s.NoError(err)
×
2349

×
2350
        targetDomainID = "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2351
        targetWorkflowID = "target-workflow-cancellation-id-2"
×
2352
        targetRunID = ""
×
2353
        targetChildWorkflowOnly = true
×
2354
        transferTasks = []p.Task{&p.CancelExecutionTask{
×
2355
                TaskData: p.TaskData{
×
2356
                        TaskID: s.GetNextSequenceNumber(),
×
2357
                },
×
2358
                TargetDomainID:          targetDomainID,
×
2359
                TargetWorkflowID:        targetWorkflowID,
×
2360
                TargetRunID:             targetRunID,
×
2361
                TargetChildWorkflowOnly: targetChildWorkflowOnly,
×
2362
                InitiatedID:             3,
×
2363
        }}
×
2364

×
2365
        state2, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2366
        s.NoError(err)
×
2367
        info2 := state2.ExecutionInfo
×
2368
        s.NotNil(info2, "Valid Workflow info expected.")
×
2369
        updatedInfo2 := copyWorkflowExecutionInfo(info2)
×
2370
        updatedStats2 := copyExecutionStats(state2.ExecutionStats)
×
2371

×
2372
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo2, updatedStats2, int64(3), transferTasks, nil, versionHistories)
×
2373
        s.NoError(err)
×
2374

×
2375
        tasks2, err := s.GetTransferTasks(ctx, 1, false)
×
2376
        s.NoError(err)
×
2377
        s.NotNil(tasks2, "expected valid list of tasks.")
×
2378
        s.Equal(1, len(tasks2), "Expected 1 cancel task.")
×
2379
        task2 := tasks2[0]
×
2380
        s.Equal(p.TransferTaskTypeCancelExecution, task2.TaskType)
×
2381
        s.Equal(domainID, task2.DomainID)
×
2382
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
2383
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
2384
        s.Equal(targetDomainID, task2.TargetDomainID)
×
2385
        s.Equal(targetWorkflowID, task2.TargetWorkflowID)
×
2386
        s.Equal(targetRunID, task2.TargetRunID)
×
2387
        s.Equal(targetChildWorkflowOnly, task2.TargetChildWorkflowOnly)
×
2388

×
2389
        err = s.CompleteTransferTask(ctx, task2.TaskID)
×
2390
        s.NoError(err)
×
2391
}
×
2392

2393
// TestSignalTransferTaskTasks test
2394
func (s *ExecutionManagerSuite) TestSignalTransferTaskTasks() {
×
2395
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2396
        defer cancel()
×
2397

×
2398
        domainID := "aeac8287-527b-4b35-80a9-667cb47e7c6d"
×
2399
        workflowExecution := types.WorkflowExecution{
×
2400
                WorkflowID: "signal-workflow-test",
×
2401
                RunID:      "db20f7e2-1a1e-40d9-9278-d8b886738e05",
×
2402
        }
×
2403

×
2404
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2405
        s.NoError(err)
×
2406
        s.NotNil(task0, "Expected non empty task identifier.")
×
2407

×
2408
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
2409
        s.NoError(err)
×
2410
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
2411
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
2412
        s.NoError(err)
×
2413

×
2414
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2415
        s.NoError(err)
×
2416
        info1 := state1.ExecutionInfo
×
2417
        s.NotNil(info1, "Valid Workflow info expected.")
×
2418
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2419
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2420

×
2421
        targetDomainID := "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2422
        targetWorkflowID := "target-workflow-signal-id-1"
×
2423
        targetRunID := "0d00698f-08e1-4d36-a3e2-3bf109f5d2d6"
×
2424
        targetChildWorkflowOnly := false
×
2425
        transferTasks := []p.Task{&p.SignalExecutionTask{
×
2426
                TaskData: p.TaskData{
×
2427
                        TaskID: s.GetNextSequenceNumber(),
×
2428
                },
×
2429
                TargetDomainID:          targetDomainID,
×
2430
                TargetWorkflowID:        targetWorkflowID,
×
2431
                TargetRunID:             targetRunID,
×
2432
                TargetChildWorkflowOnly: false,
×
2433
                InitiatedID:             1,
×
2434
        }}
×
2435
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2436
                {
×
2437
                        EventID: 1,
×
2438
                        Version: common.EmptyVersion,
×
2439
                },
×
2440
        })
×
2441
        versionHistories := p.NewVersionHistories(versionHistory)
×
2442
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo1, updatedStats1, int64(3), transferTasks, nil, versionHistories)
×
2443
        s.NoError(err)
×
2444

×
2445
        tasks1, err := s.GetTransferTasks(ctx, 1, false)
×
2446
        s.NoError(err)
×
2447
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2448
        s.Equal(1, len(tasks1), "Expected 1 cancel task.")
×
2449
        task1 := tasks1[0]
×
2450
        s.Equal(p.TransferTaskTypeSignalExecution, task1.TaskType)
×
2451
        s.Equal(domainID, task1.DomainID)
×
2452
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2453
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2454
        s.Equal(targetDomainID, task1.TargetDomainID)
×
2455
        s.Equal(targetWorkflowID, task1.TargetWorkflowID)
×
2456
        s.Equal(targetRunID, task1.TargetRunID)
×
2457
        s.Equal(false, task1.TargetChildWorkflowOnly)
×
2458

×
2459
        err = s.CompleteTransferTask(ctx, task1.TaskID)
×
2460
        s.NoError(err)
×
2461

×
2462
        targetDomainID = "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2463
        targetWorkflowID = "target-workflow-signal-id-2"
×
2464
        targetRunID = ""
×
2465
        targetChildWorkflowOnly = true
×
2466
        transferTasks = []p.Task{&p.SignalExecutionTask{
×
2467
                TaskData: p.TaskData{
×
2468
                        TaskID: s.GetNextSequenceNumber(),
×
2469
                },
×
2470
                TargetDomainID:          targetDomainID,
×
2471
                TargetWorkflowID:        targetWorkflowID,
×
2472
                TargetRunID:             targetRunID,
×
2473
                TargetChildWorkflowOnly: targetChildWorkflowOnly,
×
2474
                InitiatedID:             3,
×
2475
        }}
×
2476

×
2477
        state2, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2478
        s.NoError(err)
×
2479
        info2 := state2.ExecutionInfo
×
2480
        s.NotNil(info2, "Valid Workflow info expected.")
×
2481
        updatedInfo2 := copyWorkflowExecutionInfo(info2)
×
2482
        updatedStats2 := copyExecutionStats(state2.ExecutionStats)
×
2483

×
2484
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo2, updatedStats2, int64(3), transferTasks, nil, versionHistories)
×
2485
        s.NoError(err)
×
2486

×
2487
        tasks2, err := s.GetTransferTasks(ctx, 1, false)
×
2488
        s.NoError(err)
×
2489
        s.NotNil(tasks2, "expected valid list of tasks.")
×
2490
        s.Equal(1, len(tasks2), "Expected 1 cancel task.")
×
2491
        task2 := tasks2[0]
×
2492
        s.Equal(p.TransferTaskTypeSignalExecution, task2.TaskType)
×
2493
        s.Equal(domainID, task2.DomainID)
×
2494
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
2495
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
2496
        s.Equal(targetDomainID, task2.TargetDomainID)
×
2497
        s.Equal(targetWorkflowID, task2.TargetWorkflowID)
×
2498
        s.Equal(targetRunID, task2.TargetRunID)
×
2499
        s.Equal(targetChildWorkflowOnly, task2.TargetChildWorkflowOnly)
×
2500

×
2501
        err = s.CompleteTransferTask(ctx, task2.TaskID)
×
2502
        s.NoError(err)
×
2503
}
×
2504

2505
// TestReplicationTasks test
2506
func (s *ExecutionManagerSuite) TestReplicationTasks() {
×
2507
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2508
        defer cancel()
×
2509

×
2510
        domainID := "2466d7de-6602-4ad8-b939-fb8f8c36c711"
×
2511
        workflowExecution := types.WorkflowExecution{
×
2512
                WorkflowID: "get-replication-tasks-test",
×
2513
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2514
        }
×
2515

×
2516
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2517
        s.NoError(err)
×
2518
        s.NotNil(task0, "Expected non empty task identifier.")
×
2519
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
2520
        s.NoError(err)
×
2521
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
2522
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
2523
        s.NoError(err)
×
2524

×
2525
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2526
        s.NoError(err)
×
2527
        info1 := state1.ExecutionInfo
×
2528
        s.NotNil(info1, "Valid Workflow info expected.")
×
2529
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2530
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2531

×
2532
        replicationTasks := []p.Task{
×
2533
                &p.HistoryReplicationTask{
×
2534
                        TaskData: p.TaskData{
×
2535
                                TaskID:  s.GetNextSequenceNumber(),
×
2536
                                Version: 123,
×
2537
                        },
×
2538
                        FirstEventID: int64(1),
×
2539
                        NextEventID:  int64(3),
×
2540
                },
×
2541
                &p.HistoryReplicationTask{
×
2542
                        TaskData: p.TaskData{
×
2543
                                TaskID:  s.GetNextSequenceNumber(),
×
2544
                                Version: 456,
×
2545
                        },
×
2546
                        FirstEventID: int64(1),
×
2547
                        NextEventID:  int64(3),
×
2548
                },
×
2549
                &p.SyncActivityTask{
×
2550
                        TaskData: p.TaskData{
×
2551
                                TaskID:  s.GetNextSequenceNumber(),
×
2552
                                Version: 789,
×
2553
                        },
×
2554
                        ScheduledID: 99,
×
2555
                },
×
2556
        }
×
2557
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2558
                {
×
2559
                        EventID: 3,
×
2560
                        Version: common.EmptyVersion,
×
2561
                },
×
2562
        })
×
2563
        versionHistories := p.NewVersionHistories(versionHistory)
×
2564
        err = s.UpdateWorklowStateAndReplication(ctx, updatedInfo1, updatedStats1, versionHistories, int64(3), replicationTasks)
×
2565
        s.NoError(err)
×
2566

×
2567
        respTasks, err := s.GetReplicationTasks(ctx, 1, true)
×
2568
        s.NoError(err)
×
2569
        s.Equal(len(replicationTasks), len(respTasks))
×
2570

×
2571
        for index := range replicationTasks {
×
2572
                s.Equal(replicationTasks[index].GetTaskID(), respTasks[index].GetTaskID())
×
2573
                s.Equal(replicationTasks[index].GetType(), respTasks[index].GetTaskType())
×
2574
                s.Equal(replicationTasks[index].GetVersion(), respTasks[index].GetVersion())
×
2575
                switch replicationTasks[index].GetType() {
×
2576
                case p.ReplicationTaskTypeHistory:
×
2577
                        expected := replicationTasks[index].(*p.HistoryReplicationTask)
×
2578
                        s.Equal(expected.FirstEventID, respTasks[index].FirstEventID)
×
2579
                        s.Equal(expected.NextEventID, respTasks[index].NextEventID)
×
2580
                        s.Equal(expected.BranchToken, respTasks[index].BranchToken)
×
2581
                        s.Equal(expected.NewRunBranchToken, respTasks[index].NewRunBranchToken)
×
2582
                case p.ReplicationTaskTypeSyncActivity:
×
2583
                        expected := replicationTasks[index].(*p.SyncActivityTask)
×
2584
                        s.Equal(expected.ScheduledID, respTasks[index].ScheduledID)
×
2585
                }
2586
                err = s.CompleteReplicationTask(ctx, respTasks[index].GetTaskID())
×
2587
                s.NoError(err)
×
2588
        }
2589
}
2590

2591
// TestCrossClusterTasks test
2592
func (s *ExecutionManagerSuite) TestCrossClusterTasks() {
×
2593
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2594
        defer cancel()
×
2595

×
2596
        domainID := "5ab207b4-7422-4bc0-a6e4-e677b1b7d5d2"
×
2597
        workflowExecution := types.WorkflowExecution{
×
2598
                WorkflowID: "cross-cluster-tasks-test",
×
2599
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2600
        }
×
2601

×
2602
        resp, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2603
        s.NoError(err)
×
2604
        s.NotNil(resp, "Expected non empty task identifier.")
×
2605

×
2606
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2607
        s.NoError(err)
×
2608
        info1 := state1.ExecutionInfo
×
2609
        s.NotNil(info1, "Valid Workflow info expected.")
×
2610
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2611
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2612

×
2613
        remoteClusterName1 := "remote-cluster-1"
×
2614
        remoteClusterName2 := "remote-cluster-2"
×
2615
        now := time.Now()
×
2616
        crossClusterTasks1 := []p.Task{
×
2617
                &p.CrossClusterStartChildExecutionTask{
×
2618
                        TargetCluster: remoteClusterName1,
×
2619
                        StartChildExecutionTask: p.StartChildExecutionTask{
×
2620
                                TaskData: p.TaskData{
×
2621
                                        VisibilityTimestamp: now,
×
2622
                                        TaskID:              s.GetNextSequenceNumber(),
×
2623
                                        Version:             123,
×
2624
                                },
×
2625
                                TargetDomainID:   uuid.New(),
×
2626
                                TargetWorkflowID: "target workflow 1",
×
2627
                                InitiatedID:      5,
×
2628
                        },
×
2629
                },
×
2630
                &p.CrossClusterSignalExecutionTask{
×
2631
                        TargetCluster: remoteClusterName1,
×
2632
                        SignalExecutionTask: p.SignalExecutionTask{
×
2633
                                TaskData: p.TaskData{
×
2634
                                        VisibilityTimestamp: now,
×
2635
                                        TaskID:              s.GetNextSequenceNumber(),
×
2636
                                        Version:             123,
×
2637
                                },
×
2638
                                TargetDomainID:          uuid.New(),
×
2639
                                TargetWorkflowID:        "target workflowID 2",
×
2640
                                TargetRunID:             uuid.New(),
×
2641
                                TargetChildWorkflowOnly: true,
×
2642
                                InitiatedID:             6,
×
2643
                        },
×
2644
                },
×
2645
        }
×
2646
        crossClusterTasks2 := []p.Task{
×
2647
                &p.CrossClusterCancelExecutionTask{
×
2648
                        TargetCluster: remoteClusterName2,
×
2649
                        CancelExecutionTask: p.CancelExecutionTask{
×
2650
                                TaskData: p.TaskData{
×
2651
                                        VisibilityTimestamp: now,
×
2652
                                        TaskID:              s.GetNextSequenceNumber(),
×
2653
                                        Version:             123,
×
2654
                                },
×
2655
                                TargetDomainID:          uuid.New(),
×
2656
                                TargetWorkflowID:        "target workflowID 3",
×
2657
                                TargetRunID:             uuid.New(),
×
2658
                                TargetChildWorkflowOnly: true,
×
2659
                                InitiatedID:             6,
×
2660
                        },
×
2661
                },
×
2662
                &p.CrossClusterRecordChildExecutionCompletedTask{
×
2663
                        TargetCluster: remoteClusterName2,
×
2664
                        RecordChildExecutionCompletedTask: p.RecordChildExecutionCompletedTask{
×
2665
                                TaskData: p.TaskData{
×
2666
                                        VisibilityTimestamp: now,
×
2667
                                        TaskID:              s.GetNextSequenceNumber(),
×
2668
                                        Version:             123,
×
2669
                                },
×
2670
                                TargetDomainID:   uuid.New(),
×
2671
                                TargetWorkflowID: "target workflowID 4",
×
2672
                                TargetRunID:      uuid.New(),
×
2673
                        },
×
2674
                },
×
2675
                &p.CrossClusterApplyParentClosePolicyTask{
×
2676
                        TargetCluster: remoteClusterName2,
×
2677
                        ApplyParentClosePolicyTask: p.ApplyParentClosePolicyTask{
×
2678
                                TaskData: p.TaskData{
×
2679
                                        VisibilityTimestamp: now,
×
2680
                                        TaskID:              s.GetNextSequenceNumber(),
×
2681
                                        Version:             123,
×
2682
                                },
×
2683
                                TargetDomainIDs: map[string]struct{}{uuid.New(): {}, uuid.New(): {}},
×
2684
                        },
×
2685
                },
×
2686
        }
×
2687
        crossClusterTasks := append(crossClusterTasks1, crossClusterTasks2...)
×
2688

×
2689
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2690
                {
×
2691
                        EventID: 3,
×
2692
                        Version: common.EmptyVersion,
×
2693
                },
×
2694
        })
×
2695
        versionHistories := p.NewVersionHistories(versionHistory)
×
2696
        err = s.UpdateWorklowStateAndReplication(ctx, updatedInfo1, updatedStats1, versionHistories, int64(3), crossClusterTasks)
×
2697
        s.NoError(err)
×
2698

×
2699
        // check created tasks for cluster 1
×
2700
        respTasks, err := s.GetCrossClusterTasks(ctx, remoteClusterName1, 0, 1, true)
×
2701
        s.NoError(err)
×
2702
        s.validateCrossClusterTasks(crossClusterTasks1, respTasks)
×
2703

×
2704
        // range delete tasks for cluster 1
×
2705
        err = s.RangeCompleteCrossClusterTask(ctx, remoteClusterName1, respTasks[0].TaskID-1, respTasks[len(respTasks)-1].TaskID)
×
2706
        s.NoError(err)
×
2707
        respTasks, err = s.GetCrossClusterTasks(ctx, remoteClusterName1, 0, 1, true)
×
2708
        s.NoError(err)
×
2709
        s.Empty(respTasks)
×
2710

×
2711
        // check created tasks for cluster 2
×
2712
        respTasks, err = s.GetCrossClusterTasks(ctx, remoteClusterName2, 0, 1, true)
×
2713
        s.NoError(err)
×
2714
        s.validateCrossClusterTasks(crossClusterTasks2, respTasks)
×
2715

×
2716
        // delete tasks for cluster 2
×
2717
        for idx := range respTasks {
×
2718
                err = s.CompleteCrossClusterTask(ctx, remoteClusterName2, respTasks[idx].TaskID)
×
2719
                s.NoError(err)
×
2720
        }
×
2721
        respTasks, err = s.GetCrossClusterTasks(ctx, remoteClusterName2, 0, 1, true)
×
2722
        s.NoError(err)
×
2723
        s.Empty(respTasks)
×
2724
}
2725

2726
func (s *ExecutionManagerSuite) validateCrossClusterTasks(
2727
        tasks []p.Task,
2728
        loadedTaskInfo []*p.CrossClusterTaskInfo,
2729
) {
×
2730
        s.Equal(len(tasks), len(loadedTaskInfo))
×
2731
        for index := range tasks {
×
2732
                s.Equal(tasks[index].GetTaskID(), loadedTaskInfo[index].GetTaskID())
×
2733
                s.Equal(tasks[index].GetType(), loadedTaskInfo[index].GetTaskType())
×
2734
                s.Equal(tasks[index].GetVersion(), loadedTaskInfo[index].GetVersion())
×
2735
                s.EqualTimesWithPrecision(tasks[index].GetVisibilityTimestamp(), loadedTaskInfo[index].GetVisibilityTimestamp(), time.Millisecond)
×
2736
                switch task := tasks[index].(type) {
×
2737
                case *p.CrossClusterStartChildExecutionTask:
×
2738
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2739
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2740
                        s.Equal(task.InitiatedID, loadedTaskInfo[index].ScheduleID)
×
2741
                case *p.CrossClusterSignalExecutionTask:
×
2742
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2743
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2744
                        s.Equal(task.TargetRunID, loadedTaskInfo[index].TargetRunID)
×
2745
                        s.Equal(task.TargetChildWorkflowOnly, loadedTaskInfo[index].TargetChildWorkflowOnly)
×
2746
                        s.Equal(task.InitiatedID, loadedTaskInfo[index].ScheduleID)
×
2747
                case *p.CrossClusterCancelExecutionTask:
×
2748
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2749
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2750
                        s.Equal(task.TargetRunID, loadedTaskInfo[index].TargetRunID)
×
2751
                        s.Equal(task.TargetChildWorkflowOnly, loadedTaskInfo[index].TargetChildWorkflowOnly)
×
2752
                        s.Equal(task.InitiatedID, loadedTaskInfo[index].ScheduleID)
×
2753
                case *p.CrossClusterRecordChildExecutionCompletedTask:
×
2754
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2755
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2756
                        s.Equal(task.TargetRunID, loadedTaskInfo[index].TargetRunID)
×
2757
                case *p.CrossClusterApplyParentClosePolicyTask:
×
2758
                        s.Equal(task.TargetDomainIDs, loadedTaskInfo[index].GetTargetDomainIDs())
×
2759
                default:
×
2760
                        s.FailNow("unknown cross cluster task type")
×
2761
                }
2762
        }
2763
}
2764

2765
// TestTransferTasksComplete test
2766
func (s *ExecutionManagerSuite) TestTransferTasksComplete() {
×
2767
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2768
        defer cancel()
×
2769

×
2770
        domainID := "8bfb47be-5b57-4d55-9109-5fb35e20b1d7"
×
2771
        workflowExecution := types.WorkflowExecution{
×
2772
                WorkflowID: "get-transfer-tasks-test-complete",
×
2773
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2774
        }
×
2775
        tasklist := "some random tasklist"
×
2776

×
2777
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist, "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2778
        s.NoError(err0)
×
2779
        s.NotNil(task0, "Expected non empty task identifier.")
×
2780

×
2781
        tasks1, err1 := s.GetTransferTasks(ctx, 1, false)
×
2782
        s.NoError(err1)
×
2783
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2784
        s.Equal(1, len(tasks1), "Expected 1 decision task.")
×
2785
        task1 := tasks1[0]
×
2786
        s.Equal(domainID, task1.DomainID)
×
2787
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2788
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2789
        s.Equal(tasklist, task1.TaskList)
×
2790
        s.Equal(p.TransferTaskTypeDecisionTask, task1.TaskType)
×
2791
        s.Equal(int64(2), task1.ScheduleID)
×
2792
        s.Equal(p.TransferTaskTransferTargetWorkflowID, task1.TargetWorkflowID)
×
2793
        s.Equal("", task1.TargetRunID)
×
2794
        err3 := s.CompleteTransferTask(ctx, task1.TaskID)
×
2795
        s.NoError(err3)
×
2796

×
2797
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2798
        s.NoError(err1)
×
2799
        info0 := state0.ExecutionInfo
×
2800
        s.NotNil(info0, "Valid Workflow info expected.")
×
2801

×
2802
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2803
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
2804
        updatedInfo.NextEventID = int64(6)
×
2805
        updatedInfo.LastProcessedEvent = int64(2)
×
2806
        scheduleID := int64(123)
×
2807
        targetDomainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d0"
×
2808
        targetWorkflowID := "some random target domain ID"
×
2809
        targetRunID := uuid.New()
×
2810
        currentTransferID := task1.TaskID
×
2811
        now := time.Now()
×
2812
        tasks := []p.Task{
×
2813
                &p.ActivityTask{
×
2814
                        TaskData: p.TaskData{
×
2815
                                VisibilityTimestamp: now,
×
2816
                                TaskID:              currentTransferID + 10000,
×
2817
                                Version:             111,
×
2818
                        },
×
2819
                        DomainID:   domainID,
×
2820
                        TaskList:   tasklist,
×
2821
                        ScheduleID: scheduleID,
×
2822
                },
×
2823
                &p.DecisionTask{
×
2824
                        TaskData: p.TaskData{
×
2825
                                VisibilityTimestamp: now,
×
2826
                                TaskID:              currentTransferID + 10002,
×
2827
                                Version:             222,
×
2828
                        },
×
2829
                        DomainID:         domainID,
×
2830
                        TaskList:         tasklist,
×
2831
                        ScheduleID:       scheduleID,
×
2832
                        RecordVisibility: false,
×
2833
                },
×
2834
                &p.CloseExecutionTask{
×
2835
                        TaskData: p.TaskData{
×
2836
                                VisibilityTimestamp: now,
×
2837
                                TaskID:              currentTransferID + 10003,
×
2838
                                Version:             333,
×
2839
                        }},
×
2840
                &p.CancelExecutionTask{
×
2841
                        TaskData: p.TaskData{
×
2842
                                VisibilityTimestamp: now,
×
2843
                                TaskID:              currentTransferID + 10004,
×
2844
                                Version:             444,
×
2845
                        },
×
2846
                        TargetDomainID:          targetDomainID,
×
2847
                        TargetWorkflowID:        targetWorkflowID,
×
2848
                        TargetRunID:             targetRunID,
×
2849
                        TargetChildWorkflowOnly: true,
×
2850
                        InitiatedID:             scheduleID,
×
2851
                },
×
2852
                &p.SignalExecutionTask{
×
2853
                        TaskData: p.TaskData{
×
2854
                                VisibilityTimestamp: now,
×
2855
                                TaskID:              currentTransferID + 10005,
×
2856
                                Version:             555,
×
2857
                        },
×
2858
                        TargetDomainID:          targetDomainID,
×
2859
                        TargetWorkflowID:        targetWorkflowID,
×
2860
                        TargetRunID:             targetRunID,
×
2861
                        TargetChildWorkflowOnly: true,
×
2862
                        InitiatedID:             scheduleID,
×
2863
                },
×
2864
                &p.StartChildExecutionTask{
×
2865
                        TaskData: p.TaskData{
×
2866
                                VisibilityTimestamp: now,
×
2867
                                TaskID:              currentTransferID + 10006,
×
2868
                                Version:             666,
×
2869
                        },
×
2870
                        TargetDomainID:   targetDomainID,
×
2871
                        TargetWorkflowID: targetWorkflowID,
×
2872
                        InitiatedID:      scheduleID,
×
2873
                },
×
2874
                &p.RecordWorkflowClosedTask{
×
2875
                        TaskData: p.TaskData{
×
2876
                                VisibilityTimestamp: now,
×
2877
                                TaskID:              currentTransferID + 10007,
×
2878
                                Version:             777,
×
2879
                        },
×
2880
                },
×
2881
                &p.RecordChildExecutionCompletedTask{
×
2882
                        TaskData: p.TaskData{
×
2883
                                VisibilityTimestamp: now,
×
2884
                                TaskID:              currentTransferID + 10008,
×
2885
                                Version:             888,
×
2886
                        },
×
2887
                        TargetDomainID:   targetDomainID,
×
2888
                        TargetWorkflowID: targetWorkflowID,
×
2889
                        TargetRunID:      targetRunID,
×
2890
                },
×
2891
                &p.ApplyParentClosePolicyTask{
×
2892
                        TaskData: p.TaskData{
×
2893
                                VisibilityTimestamp: now,
×
2894
                                TaskID:              currentTransferID + 10009,
×
2895
                                Version:             999,
×
2896
                        },
×
2897
                        TargetDomainIDs: map[string]struct{}{targetDomainID: {}},
×
2898
                },
×
2899
        }
×
2900
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2901
                {
×
2902
                        EventID: scheduleID,
×
2903
                        Version: common.EmptyVersion,
×
2904
                },
×
2905
        })
×
2906
        versionHistories := p.NewVersionHistories(versionHistory)
×
2907
        err2 := s.UpdateWorklowStateAndReplication(ctx, updatedInfo, updatedStats, versionHistories, int64(3), tasks)
×
2908
        s.NoError(err2)
×
2909

×
2910
        txTasks, err1 := s.GetTransferTasks(ctx, 1, true) // use page size one to force pagination
×
2911
        s.NoError(err1)
×
2912
        s.NotNil(txTasks, "expected valid list of tasks.")
×
2913
        s.Equal(len(tasks), len(txTasks))
×
2914
        for index := range tasks {
×
2915
                s.True(timeComparator(tasks[index].GetVisibilityTimestamp(), txTasks[index].VisibilityTimestamp, TimePrecision))
×
2916
        }
×
2917
        s.Equal(p.TransferTaskTypeActivityTask, txTasks[0].TaskType)
×
2918
        s.Equal(p.TransferTaskTypeDecisionTask, txTasks[1].TaskType)
×
2919
        s.Equal(p.TransferTaskTypeCloseExecution, txTasks[2].TaskType)
×
2920
        s.Equal(p.TransferTaskTypeCancelExecution, txTasks[3].TaskType)
×
2921
        s.Equal(p.TransferTaskTypeSignalExecution, txTasks[4].TaskType)
×
2922
        s.Equal(p.TransferTaskTypeStartChildExecution, txTasks[5].TaskType)
×
2923
        s.Equal(p.TransferTaskTypeRecordWorkflowClosed, txTasks[6].TaskType)
×
2924
        s.Equal(p.TransferTaskTypeRecordChildExecutionCompleted, txTasks[7].TaskType)
×
2925
        s.Equal(p.TransferTaskTypeApplyParentClosePolicy, txTasks[8].TaskType)
×
2926

×
2927
        for idx := range txTasks {
×
2928
                // TODO: add a check similar to validateCrossClusterTasks
×
2929
                s.Equal(int64(111*(idx+1)), txTasks[idx].Version)
×
2930
                err := s.CompleteTransferTask(ctx, txTasks[idx].TaskID)
×
2931
                s.NoError(err)
×
2932
        }
×
2933

2934
        txTasks, err2 = s.GetTransferTasks(ctx, 100, false)
×
2935
        s.NoError(err2)
×
2936
        s.Empty(txTasks, "expected empty task list.")
×
2937
}
2938

2939
// TestTransferTasksRangeComplete test
2940
func (s *ExecutionManagerSuite) TestTransferTasksRangeComplete() {
×
2941
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2942
        defer cancel()
×
2943

×
2944
        domainID := "8bfb47be-5b57-4d55-9109-5fb35e20b1d7"
×
2945
        workflowExecution := types.WorkflowExecution{
×
2946
                WorkflowID: "get-transfer-tasks-test-range-complete",
×
2947
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2948
        }
×
2949
        tasklist := "some random tasklist"
×
2950

×
2951
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist, "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2952
        s.NoError(err0)
×
2953
        s.NotNil(task0, "Expected non empty task identifier.")
×
2954

×
2955
        tasks1, err1 := s.GetTransferTasks(ctx, 1, false)
×
2956
        s.NoError(err1)
×
2957
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2958
        s.Equal(1, len(tasks1), "Expected 1 decision task.")
×
2959
        task1 := tasks1[0]
×
2960
        s.Equal(domainID, task1.DomainID)
×
2961
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2962
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2963
        s.Equal(tasklist, task1.TaskList)
×
2964
        s.Equal(p.TransferTaskTypeDecisionTask, task1.TaskType)
×
2965
        s.Equal(int64(2), task1.ScheduleID)
×
2966
        s.Equal(p.TransferTaskTransferTargetWorkflowID, task1.TargetWorkflowID)
×
2967
        s.Equal("", task1.TargetRunID)
×
2968
        err3 := s.CompleteTransferTask(ctx, task1.TaskID)
×
2969
        s.NoError(err3)
×
2970

×
2971
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2972
        s.NoError(err1)
×
2973
        info0 := state0.ExecutionInfo
×
2974
        s.NotNil(info0, "Valid Workflow info expected.")
×
2975

×
2976
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2977
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
2978
        updatedInfo.NextEventID = int64(6)
×
2979
        updatedInfo.LastProcessedEvent = int64(2)
×
2980
        scheduleID := int64(123)
×
2981
        targetDomainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d0"
×
2982
        targetWorkflowID := "some random target domain ID"
×
2983
        targetRunID := uuid.New()
×
2984
        currentTransferID := task1.TaskID
×
2985
        now := time.Now()
×
2986
        tasks := []p.Task{
×
2987
                &p.ActivityTask{
×
2988
                        TaskData: p.TaskData{
×
2989
                                VisibilityTimestamp: now,
×
2990
                                TaskID:              currentTransferID + 10001,
×
2991
                                Version:             111,
×
2992
                        },
×
2993
                        DomainID:   domainID,
×
2994
                        TaskList:   tasklist,
×
2995
                        ScheduleID: scheduleID,
×
2996
                },
×
2997
                &p.DecisionTask{
×
2998
                        TaskData: p.TaskData{
×
2999
                                VisibilityTimestamp: now,
×
3000
                                TaskID:              currentTransferID + 10002,
×
3001
                                Version:             222,
×
3002
                        },
×
3003
                        DomainID:         domainID,
×
3004
                        TaskList:         tasklist,
×
3005
                        ScheduleID:       scheduleID,
×
3006
                        RecordVisibility: false,
×
3007
                },
×
3008
                &p.CloseExecutionTask{
×
3009
                        TaskData: p.TaskData{
×
3010
                                VisibilityTimestamp: now,
×
3011
                                TaskID:              currentTransferID + 10003,
×
3012
                                Version:             333,
×
3013
                        },
×
3014
                },
×
3015
                &p.CancelExecutionTask{
×
3016
                        TaskData: p.TaskData{
×
3017
                                VisibilityTimestamp: now,
×
3018
                                TaskID:              currentTransferID + 10004,
×
3019
                                Version:             444,
×
3020
                        },
×
3021
                        TargetDomainID:          targetDomainID,
×
3022
                        TargetWorkflowID:        targetWorkflowID,
×
3023
                        TargetRunID:             targetRunID,
×
3024
                        TargetChildWorkflowOnly: true,
×
3025
                        InitiatedID:             scheduleID,
×
3026
                },
×
3027
                &p.SignalExecutionTask{
×
3028
                        TaskData: p.TaskData{
×
3029
                                VisibilityTimestamp: now,
×
3030
                                TaskID:              currentTransferID + 10005,
×
3031
                                Version:             555,
×
3032
                        },
×
3033
                        TargetDomainID:          targetDomainID,
×
3034
                        TargetWorkflowID:        targetWorkflowID,
×
3035
                        TargetRunID:             targetRunID,
×
3036
                        TargetChildWorkflowOnly: true,
×
3037
                        InitiatedID:             scheduleID,
×
3038
                },
×
3039
                &p.StartChildExecutionTask{
×
3040
                        TaskData: p.TaskData{
×
3041
                                VisibilityTimestamp: now,
×
3042
                                TaskID:              currentTransferID + 10006,
×
3043
                                Version:             666,
×
3044
                        },
×
3045
                        TargetDomainID:   targetDomainID,
×
3046
                        TargetWorkflowID: targetWorkflowID,
×
3047
                        InitiatedID:      scheduleID,
×
3048
                },
×
3049
        }
×
3050
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3051
                {
×
3052
                        EventID: scheduleID,
×
3053
                        Version: common.EmptyVersion,
×
3054
                },
×
3055
        })
×
3056
        versionHistories := p.NewVersionHistories(versionHistory)
×
3057
        err2 := s.UpdateWorklowStateAndReplication(ctx, updatedInfo, updatedStats, versionHistories, int64(3), tasks)
×
3058
        s.NoError(err2)
×
3059

×
3060
        txTasks, err1 := s.GetTransferTasks(ctx, 2, true) // use page size one to force pagination
×
3061
        s.NoError(err1)
×
3062
        s.NotNil(txTasks, "expected valid list of tasks.")
×
3063
        s.Equal(len(tasks), len(txTasks))
×
3064
        for index := range tasks {
×
3065
                s.True(timeComparator(tasks[index].GetVisibilityTimestamp(), txTasks[index].VisibilityTimestamp, TimePrecision))
×
3066
        }
×
3067
        s.Equal(p.TransferTaskTypeActivityTask, txTasks[0].TaskType)
×
3068
        s.Equal(p.TransferTaskTypeDecisionTask, txTasks[1].TaskType)
×
3069
        s.Equal(p.TransferTaskTypeCloseExecution, txTasks[2].TaskType)
×
3070
        s.Equal(p.TransferTaskTypeCancelExecution, txTasks[3].TaskType)
×
3071
        s.Equal(p.TransferTaskTypeSignalExecution, txTasks[4].TaskType)
×
3072
        s.Equal(p.TransferTaskTypeStartChildExecution, txTasks[5].TaskType)
×
3073
        s.Equal(int64(111), txTasks[0].Version)
×
3074
        s.Equal(int64(222), txTasks[1].Version)
×
3075
        s.Equal(int64(333), txTasks[2].Version)
×
3076
        s.Equal(int64(444), txTasks[3].Version)
×
3077
        s.Equal(int64(555), txTasks[4].Version)
×
3078
        s.Equal(int64(666), txTasks[5].Version)
×
3079
        s.Equal(currentTransferID+10001, txTasks[0].TaskID)
×
3080
        s.Equal(currentTransferID+10002, txTasks[1].TaskID)
×
3081
        s.Equal(currentTransferID+10003, txTasks[2].TaskID)
×
3082
        s.Equal(currentTransferID+10004, txTasks[3].TaskID)
×
3083
        s.Equal(currentTransferID+10005, txTasks[4].TaskID)
×
3084
        s.Equal(currentTransferID+10006, txTasks[5].TaskID)
×
3085

×
3086
        err2 = s.RangeCompleteTransferTask(ctx, txTasks[0].TaskID-1, txTasks[5].TaskID)
×
3087
        s.NoError(err2)
×
3088

×
3089
        txTasks, err2 = s.GetTransferTasks(ctx, 100, false)
×
3090
        s.NoError(err2)
×
3091
        s.Empty(txTasks, "expected empty task list.")
×
3092
}
3093

3094
// TestTimerTasksComplete test
3095
func (s *ExecutionManagerSuite) TestTimerTasksComplete() {
×
3096
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3097
        defer cancel()
×
3098

×
3099
        domainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d7"
×
3100
        workflowExecution := types.WorkflowExecution{
×
3101
                WorkflowID: "get-timer-tasks-test-complete",
×
3102
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3103
        }
×
3104

×
3105
        now := time.Now()
×
3106
        initialTasks := []p.Task{&p.DecisionTimeoutTask{
×
3107
                TaskData: p.TaskData{
×
3108
                        VisibilityTimestamp: now.Add(1 * time.Second),
×
3109
                        TaskID:              1,
×
3110
                        Version:             11,
×
3111
                },
×
3112
                EventID:         2,
×
3113
                ScheduleAttempt: 3,
×
3114
                TimeoutType:     int(types.TimeoutTypeStartToClose)},
×
3115
        }
×
3116

×
3117
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, initialTasks, nil)
×
3118
        s.NoError(err0)
×
3119
        s.NotNil(task0, "Expected non empty task identifier.")
×
3120

×
3121
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3122
        s.NoError(err1)
×
3123
        info0 := state0.ExecutionInfo
×
3124
        s.NotNil(info0, "Valid Workflow info expected.")
×
3125

×
3126
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3127
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3128
        updatedInfo.NextEventID = int64(5)
×
3129
        updatedInfo.LastProcessedEvent = int64(2)
×
3130
        tasks := []p.Task{
×
3131
                &p.WorkflowTimeoutTask{
×
3132
                        TaskData: p.TaskData{
×
3133
                                Version:             12,
×
3134
                                TaskID:              2,
×
3135
                                VisibilityTimestamp: now.Add(2 * time.Second),
×
3136
                        },
×
3137
                },
×
3138
                &p.DeleteHistoryEventTask{
×
3139
                        TaskData: p.TaskData{
×
3140
                                Version:             13,
×
3141
                                TaskID:              3,
×
3142
                                VisibilityTimestamp: now.Add(2 * time.Second),
×
3143
                        },
×
3144
                },
×
3145
                &p.ActivityTimeoutTask{
×
3146
                        TaskData: p.TaskData{
×
3147
                                Version:             14,
×
3148
                                TaskID:              4,
×
3149
                                VisibilityTimestamp: now.Add(3 * time.Second),
×
3150
                        },
×
3151
                        TimeoutType: int(types.TimeoutTypeStartToClose),
×
3152
                        EventID:     7,
×
3153
                        Attempt:     0,
×
3154
                },
×
3155
                &p.UserTimerTask{
×
3156
                        TaskData: p.TaskData{
×
3157
                                Version:             15,
×
3158
                                TaskID:              5,
×
3159
                                VisibilityTimestamp: now.Add(3 * time.Second),
×
3160
                        },
×
3161
                        EventID: 7,
×
3162
                },
×
3163
        }
×
3164
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3165
                {
×
3166
                        EventID: updatedInfo.NextEventID,
×
3167
                        Version: common.EmptyVersion,
×
3168
                },
×
3169
        })
×
3170
        versionHistories := p.NewVersionHistories(versionHistory)
×
3171
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), tasks, nil, nil, nil, nil)
×
3172
        s.NoError(err2)
×
3173

×
3174
        timerTasks, err1 := s.GetTimerIndexTasks(ctx, 1, true) // use page size one to force pagination
×
3175
        s.NoError(err1)
×
3176
        s.NotNil(timerTasks, "expected valid list of tasks.")
×
3177
        s.Equal(len(tasks)+len(initialTasks), len(timerTasks))
×
3178
        s.Equal(p.TaskTypeDecisionTimeout, timerTasks[0].TaskType)
×
3179
        s.Equal(p.TaskTypeWorkflowTimeout, timerTasks[1].TaskType)
×
3180
        s.Equal(p.TaskTypeDeleteHistoryEvent, timerTasks[2].TaskType)
×
3181
        s.Equal(p.TaskTypeActivityTimeout, timerTasks[3].TaskType)
×
3182
        s.Equal(p.TaskTypeUserTimer, timerTasks[4].TaskType)
×
3183
        s.Equal(int64(11), timerTasks[0].Version)
×
3184
        s.Equal(int64(12), timerTasks[1].Version)
×
3185
        s.Equal(int64(13), timerTasks[2].Version)
×
3186
        s.Equal(int64(14), timerTasks[3].Version)
×
3187
        s.Equal(int64(15), timerTasks[4].Version)
×
3188

×
3189
        err2 = s.RangeCompleteTimerTask(ctx, timerTasks[0].VisibilityTimestamp, timerTasks[4].VisibilityTimestamp.Add(1*time.Second))
×
3190
        s.NoError(err2)
×
3191

×
3192
        timerTasks2, err2 := s.GetTimerIndexTasks(ctx, 100, false)
×
3193
        s.NoError(err2)
×
3194
        s.Empty(timerTasks2, "expected empty task list.")
×
3195
}
×
3196

3197
// TestTimerTasksRangeComplete test
3198
func (s *ExecutionManagerSuite) TestTimerTasksRangeComplete() {
×
3199
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3200
        defer cancel()
×
3201

×
3202
        domainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d7"
×
3203
        workflowExecution := types.WorkflowExecution{
×
3204
                WorkflowID: "get-timer-tasks-test-range-complete",
×
3205
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3206
        }
×
3207

×
3208
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3209
        s.NoError(err0)
×
3210
        s.NotNil(task0, "Expected non empty task identifier.")
×
3211

×
3212
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3213
        s.NoError(err1)
×
3214
        info0 := state0.ExecutionInfo
×
3215
        s.NotNil(info0, "Valid Workflow info expected.")
×
3216

×
3217
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3218
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3219
        updatedInfo.NextEventID = int64(5)
×
3220
        updatedInfo.LastProcessedEvent = int64(2)
×
3221
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3222
                {
×
3223
                        EventID: updatedInfo.NextEventID,
×
3224
                        Version: common.EmptyVersion,
×
3225
                },
×
3226
        })
×
3227
        versionHistories := p.NewVersionHistories(versionHistory)
×
3228
        now := time.Now().UTC()
×
3229
        tasks := []p.Task{
×
3230
                &p.DecisionTimeoutTask{
×
3231
                        TaskData: p.TaskData{
×
3232
                                VisibilityTimestamp: now,
×
3233
                                TaskID:              1,
×
3234
                                Version:             11,
×
3235
                        },
×
3236
                        EventID:         2,
×
3237
                        ScheduleAttempt: 3,
×
3238
                        TimeoutType:     int(types.TimeoutTypeStartToClose),
×
3239
                },
×
3240
                &p.WorkflowTimeoutTask{
×
3241
                        TaskData: p.TaskData{
×
3242
                                VisibilityTimestamp: now,
×
3243
                                TaskID:              2,
×
3244
                                Version:             12,
×
3245
                        },
×
3246
                },
×
3247
                &p.DeleteHistoryEventTask{
×
3248
                        TaskData: p.TaskData{
×
3249
                                VisibilityTimestamp: now,
×
3250
                                TaskID:              3,
×
3251
                                Version:             13,
×
3252
                        },
×
3253
                },
×
3254
                &p.ActivityTimeoutTask{
×
3255
                        TaskData: p.TaskData{
×
3256
                                VisibilityTimestamp: now,
×
3257
                                TaskID:              4,
×
3258
                                Version:             14,
×
3259
                        },
×
3260
                        TimeoutType: int(types.TimeoutTypeStartToClose),
×
3261
                        EventID:     7,
×
3262
                        Attempt:     0,
×
3263
                },
×
3264
                &p.UserTimerTask{
×
3265
                        TaskData: p.TaskData{
×
3266
                                VisibilityTimestamp: now,
×
3267
                                TaskID:              5,
×
3268
                                Version:             15,
×
3269
                        },
×
3270
                        EventID: 7,
×
3271
                },
×
3272
        }
×
3273
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), tasks, nil, nil, nil, nil)
×
3274
        s.NoError(err2)
×
3275

×
3276
        timerTasks, err1 := s.GetTimerIndexTasks(ctx, 1, true) // use page size one to force pagination
×
3277
        s.NoError(err1)
×
3278
        s.NotNil(timerTasks, "expected valid list of tasks.")
×
3279
        s.Equal(len(tasks), len(timerTasks))
×
3280
        s.Equal(p.TaskTypeDecisionTimeout, timerTasks[0].TaskType)
×
3281
        s.Equal(p.TaskTypeWorkflowTimeout, timerTasks[1].TaskType)
×
3282
        s.Equal(p.TaskTypeDeleteHistoryEvent, timerTasks[2].TaskType)
×
3283
        s.Equal(p.TaskTypeActivityTimeout, timerTasks[3].TaskType)
×
3284
        s.Equal(p.TaskTypeUserTimer, timerTasks[4].TaskType)
×
3285
        s.Equal(int64(11), timerTasks[0].Version)
×
3286
        s.Equal(int64(12), timerTasks[1].Version)
×
3287
        s.Equal(int64(13), timerTasks[2].Version)
×
3288
        s.Equal(int64(14), timerTasks[3].Version)
×
3289
        s.Equal(int64(15), timerTasks[4].Version)
×
3290

×
3291
        err2 = s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, nil, nil, int64(5), nil, nil, nil, nil, nil)
×
3292
        s.NoError(err2)
×
3293

×
3294
        err2 = s.CompleteTimerTask(ctx, timerTasks[0].VisibilityTimestamp, timerTasks[0].TaskID)
×
3295
        s.NoError(err2)
×
3296

×
3297
        err2 = s.CompleteTimerTask(ctx, timerTasks[1].VisibilityTimestamp, timerTasks[1].TaskID)
×
3298
        s.NoError(err2)
×
3299

×
3300
        err2 = s.CompleteTimerTask(ctx, timerTasks[2].VisibilityTimestamp, timerTasks[2].TaskID)
×
3301
        s.NoError(err2)
×
3302

×
3303
        err2 = s.CompleteTimerTask(ctx, timerTasks[3].VisibilityTimestamp, timerTasks[3].TaskID)
×
3304
        s.NoError(err2)
×
3305

×
3306
        err2 = s.CompleteTimerTask(ctx, timerTasks[4].VisibilityTimestamp, timerTasks[4].TaskID)
×
3307
        s.NoError(err2)
×
3308

×
3309
        timerTasks2, err2 := s.GetTimerIndexTasks(ctx, 100, false)
×
3310
        s.NoError(err2)
×
3311
        s.Empty(timerTasks2, "expected empty task list.")
×
3312
}
×
3313

3314
// TestWorkflowMutableStateActivities test
3315
func (s *ExecutionManagerSuite) TestWorkflowMutableStateActivities() {
×
3316
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3317
        defer cancel()
×
3318

×
3319
        domainID := "7fcf0aa9-e121-4292-bdad-0a75181b4aa3"
×
3320
        workflowExecution := types.WorkflowExecution{
×
3321
                WorkflowID: "test-workflow-mutable-test",
×
3322
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3323
        }
×
3324

×
3325
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3326
        s.NoError(err0)
×
3327
        s.NotNil(task0, "Expected non empty task identifier.")
×
3328

×
3329
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3330
        s.NoError(err1)
×
3331
        info0 := state0.ExecutionInfo
×
3332
        s.NotNil(info0, "Valid Workflow info expected.")
×
3333

×
3334
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3335
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3336
        updatedInfo.NextEventID = int64(5)
×
3337
        updatedInfo.LastProcessedEvent = int64(2)
×
3338
        currentTime := time.Now()
×
3339
        activityInfos := []*p.ActivityInfo{{
×
3340
                Version:                  7789,
×
3341
                ScheduleID:               1,
×
3342
                ScheduledEventBatchID:    1,
×
3343
                ScheduledEvent:           &types.HistoryEvent{ID: 1},
×
3344
                ScheduledTime:            currentTime,
×
3345
                ActivityID:               uuid.New(),
×
3346
                RequestID:                uuid.New(),
×
3347
                Details:                  []byte(uuid.New()),
×
3348
                StartedID:                2,
×
3349
                StartedEvent:             &types.HistoryEvent{ID: 2},
×
3350
                StartedTime:              currentTime,
×
3351
                ScheduleToCloseTimeout:   1,
×
3352
                ScheduleToStartTimeout:   2,
×
3353
                StartToCloseTimeout:      3,
×
3354
                HeartbeatTimeout:         4,
×
3355
                LastHeartBeatUpdatedTime: currentTime,
×
3356
                TimerTaskStatus:          1,
×
3357
                CancelRequested:          true,
×
3358
                CancelRequestID:          math.MaxInt64,
×
3359
                Attempt:                  math.MaxInt32,
×
3360
                DomainID:                 domainID,
×
3361
                StartedIdentity:          uuid.New(),
×
3362
                TaskList:                 uuid.New(),
×
3363
                HasRetryPolicy:           true,
×
3364
                InitialInterval:          math.MaxInt32,
×
3365
                MaximumInterval:          math.MaxInt32,
×
3366
                MaximumAttempts:          math.MaxInt32,
×
3367
                BackoffCoefficient:       5.55,
×
3368
                ExpirationTime:           currentTime,
×
3369
                NonRetriableErrors:       []string{"accessDenied", "badRequest"},
×
3370
                LastFailureReason:        "some random error",
×
3371
                LastWorkerIdentity:       uuid.New(),
×
3372
                LastFailureDetails:       []byte(uuid.New()),
×
3373
        }}
×
3374
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3375
                {
×
3376
                        EventID: updatedInfo.NextEventID,
×
3377
                        Version: common.EmptyVersion,
×
3378
                },
×
3379
        })
×
3380
        versionHistories := p.NewVersionHistories(versionHistory)
×
3381
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, activityInfos, nil, nil, nil)
×
3382
        s.NoError(err2)
×
3383

×
3384
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3385
        s.NoError(err1)
×
3386
        s.NotNil(state, "expected valid state.")
×
3387
        s.Equal(1, len(state.ActivityInfos))
×
3388
        s.T().Logf("%+v\n", state.ActivityInfos)
×
3389
        ai, ok := state.ActivityInfos[1]
×
3390
        s.True(ok)
×
3391
        s.NotNil(ai)
×
3392
        s.Equal(int64(7789), ai.Version)
×
3393
        s.Equal(int64(1), ai.ScheduleID)
×
3394
        s.Equal(int64(1), ai.ScheduledEventBatchID)
×
3395
        s.Equal(int64(1), ai.ScheduledEvent.ID)
×
3396
        s.EqualTimes(currentTime, ai.ScheduledTime)
×
3397
        s.Equal(activityInfos[0].ActivityID, ai.ActivityID)
×
3398
        s.Equal(activityInfos[0].RequestID, ai.RequestID)
×
3399
        s.Equal(activityInfos[0].Details, ai.Details)
×
3400
        s.Equal(int64(2), ai.StartedID)
×
3401
        s.Equal(int64(2), ai.StartedEvent.ID)
×
3402
        s.EqualTimes(currentTime, ai.StartedTime)
×
3403
        s.Equal(int32(1), ai.ScheduleToCloseTimeout)
×
3404
        s.Equal(int32(2), ai.ScheduleToStartTimeout)
×
3405
        s.Equal(int32(3), ai.StartToCloseTimeout)
×
3406
        s.Equal(int32(4), ai.HeartbeatTimeout)
×
3407
        s.EqualTimes(currentTime, ai.LastHeartBeatUpdatedTime)
×
3408
        s.Equal(int32(1), ai.TimerTaskStatus)
×
3409
        s.Equal(activityInfos[0].CancelRequested, ai.CancelRequested)
×
3410
        s.Equal(activityInfos[0].CancelRequestID, ai.CancelRequestID)
×
3411
        s.Equal(activityInfos[0].Attempt, ai.Attempt)
×
3412
        s.Equal(activityInfos[0].DomainID, ai.DomainID)
×
3413
        s.Equal(activityInfos[0].StartedIdentity, ai.StartedIdentity)
×
3414
        s.Equal(activityInfos[0].TaskList, ai.TaskList)
×
3415
        s.Equal(activityInfos[0].HasRetryPolicy, ai.HasRetryPolicy)
×
3416
        s.Equal(activityInfos[0].InitialInterval, ai.InitialInterval)
×
3417
        s.Equal(activityInfos[0].MaximumInterval, ai.MaximumInterval)
×
3418
        s.Equal(activityInfos[0].MaximumAttempts, ai.MaximumAttempts)
×
3419
        s.Equal(activityInfos[0].BackoffCoefficient, ai.BackoffCoefficient)
×
3420
        s.EqualTimes(activityInfos[0].ExpirationTime, ai.ExpirationTime)
×
3421
        s.Equal(activityInfos[0].NonRetriableErrors, ai.NonRetriableErrors)
×
3422
        s.Equal(activityInfos[0].LastFailureReason, ai.LastFailureReason)
×
3423
        s.Equal(activityInfos[0].LastWorkerIdentity, ai.LastWorkerIdentity)
×
3424
        s.Equal(activityInfos[0].LastFailureDetails, ai.LastFailureDetails)
×
3425

×
3426
        err2 = s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, nil, nil, int64(5), nil, nil, []int64{1}, nil, nil)
×
3427
        s.NoError(err2)
×
3428

×
3429
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3430
        s.NoError(err2)
×
3431
        s.NotNil(state, "expected valid state.")
×
3432
        s.Equal(0, len(state.ActivityInfos))
×
3433
}
×
3434

3435
// TestWorkflowMutableStateTimers test
3436
func (s *ExecutionManagerSuite) TestWorkflowMutableStateTimers() {
×
3437
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3438
        defer cancel()
×
3439

×
3440
        domainID := "025d178a-709b-4c07-8dd7-86dbf9bd2e06"
×
3441
        workflowExecution := types.WorkflowExecution{
×
3442
                WorkflowID: "test-workflow-mutable-timers-test",
×
3443
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3444
        }
×
3445

×
3446
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3447
        s.NoError(err0)
×
3448
        s.NotNil(task0, "Expected non empty task identifier.")
×
3449

×
3450
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3451
        s.NoError(err1)
×
3452
        info0 := state0.ExecutionInfo
×
3453
        s.NotNil(info0, "Valid Workflow info expected.")
×
3454

×
3455
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3456
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3457
        updatedInfo.NextEventID = int64(5)
×
3458
        updatedInfo.LastProcessedEvent = int64(2)
×
3459
        currentTime := time.Now().UTC()
×
3460
        timerID := "id_1"
×
3461
        timerInfos := []*p.TimerInfo{{
×
3462
                Version:    3345,
×
3463
                TimerID:    timerID,
×
3464
                ExpiryTime: currentTime,
×
3465
                TaskStatus: 2,
×
3466
                StartedID:  5,
×
3467
        }}
×
3468
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3469
                {
×
3470
                        EventID: updatedInfo.NextEventID,
×
3471
                        Version: common.EmptyVersion,
×
3472
                },
×
3473
        })
×
3474
        versionHistories := p.NewVersionHistories(versionHistory)
×
3475
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, nil, nil, timerInfos, nil)
×
3476
        s.NoError(err2)
×
3477

×
3478
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3479
        s.NoError(err1)
×
3480
        s.NotNil(state, "expected valid state.")
×
3481
        s.Equal(1, len(state.TimerInfos))
×
3482
        s.Equal(int64(3345), state.TimerInfos[timerID].Version)
×
3483
        s.Equal(timerID, state.TimerInfos[timerID].TimerID)
×
3484
        s.EqualTimesWithPrecision(currentTime, state.TimerInfos[timerID].ExpiryTime, time.Millisecond*500)
×
3485
        s.Equal(int64(2), state.TimerInfos[timerID].TaskStatus)
×
3486
        s.Equal(int64(5), state.TimerInfos[timerID].StartedID)
×
3487

×
3488
        err2 = s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, nil, nil, int64(5), nil, nil, nil, nil, []string{timerID})
×
3489
        s.NoError(err2)
×
3490

×
3491
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3492
        s.NoError(err2)
×
3493
        s.NotNil(state, "expected valid state.")
×
3494
        s.Equal(0, len(state.TimerInfos))
×
3495
}
×
3496

3497
// TestWorkflowMutableStateChildExecutions test
3498
func (s *ExecutionManagerSuite) TestWorkflowMutableStateChildExecutions() {
×
3499
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3500
        defer cancel()
×
3501

×
3502
        domainID := "88236cd2-c439-4cec-9957-2748ce3be074"
×
3503
        workflowExecution := types.WorkflowExecution{
×
3504
                WorkflowID: "test-workflow-mutable-child-executions-parent-test",
×
3505
                RunID:      "c63dba1e-929c-4fbf-8ec5-4533b16269a9",
×
3506
        }
×
3507

×
3508
        parentDomainID := "6036ded3-e541-42c9-8f69-3d9354dad081"
×
3509
        parentExecution := types.WorkflowExecution{
×
3510
                WorkflowID: "test-workflow-mutable-child-executions-child-test",
×
3511
                RunID:      "73e89362-25ec-4305-bcb8-d9448b90856c",
×
3512
        }
×
3513

×
3514
        partitionConfig := map[string]string{
×
3515
                "userID": uuid.New(),
×
3516
        }
×
3517
        task0, err0 := s.CreateChildWorkflowExecution(ctx, domainID, workflowExecution, parentDomainID, parentExecution, 1, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, partitionConfig)
×
3518
        s.NoError(err0)
×
3519
        s.NotNil(task0, "Expected non empty task identifier.")
×
3520

×
3521
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3522
        s.NoError(err1)
×
3523
        info0 := state0.ExecutionInfo
×
3524
        s.NotNil(info0, "Valid Workflow info expected.")
×
3525
        s.Equal(parentDomainID, info0.ParentDomainID)
×
3526
        s.Equal(parentExecution.GetWorkflowID(), info0.ParentWorkflowID)
×
3527
        s.Equal(parentExecution.GetRunID(), info0.ParentRunID)
×
3528
        s.Equal(int64(1), info0.InitiatedID)
×
3529
        s.Equal(partitionConfig, info0.PartitionConfig)
×
3530

×
3531
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3532
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3533
        updatedInfo.NextEventID = int64(5)
×
3534
        updatedInfo.LastProcessedEvent = int64(2)
×
3535
        childExecutionInfos := []*p.ChildExecutionInfo{{
×
3536
                Version:           1234,
×
3537
                InitiatedID:       1,
×
3538
                InitiatedEvent:    &types.HistoryEvent{ID: 1},
×
3539
                StartedID:         2,
×
3540
                StartedRunID:      uuid.New(),
×
3541
                StartedEvent:      &types.HistoryEvent{ID: 2},
×
3542
                CreateRequestID:   uuid.New(),
×
3543
                DomainID:          uuid.New(),
×
3544
                ParentClosePolicy: types.ParentClosePolicyTerminate,
×
3545
        }}
×
3546
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3547
                {
×
3548
                        EventID: updatedInfo.LastProcessedEvent,
×
3549
                        Version: common.EmptyVersion,
×
3550
                },
×
3551
        })
×
3552
        versionHistories := p.NewVersionHistories(versionHistory)
×
3553
        err2 := s.UpsertChildExecutionsState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), childExecutionInfos)
×
3554
        s.NoError(err2)
×
3555

×
3556
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3557
        s.NoError(err1)
×
3558
        s.NotNil(state, "expected valid state.")
×
3559
        s.Equal(1, len(state.ChildExecutionInfos))
×
3560
        ci, ok := state.ChildExecutionInfos[1]
×
3561
        s.True(ok)
×
3562
        s.NotNil(ci)
×
3563
        s.Equal(childExecutionInfos[0], ci)
×
3564

×
3565
        err2 = s.DeleteChildExecutionsState(ctx, updatedInfo, updatedStats, versionHistories, int64(5), int64(1))
×
3566
        s.NoError(err2)
×
3567

×
3568
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3569
        s.NoError(err2)
×
3570
        s.NotNil(state, "expected valid state.")
×
3571
        s.Equal(0, len(state.ChildExecutionInfos))
×
3572
}
×
3573

3574
// TestWorkflowMutableStateRequestCancel test
3575
func (s *ExecutionManagerSuite) TestWorkflowMutableStateRequestCancel() {
×
3576
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3577
        defer cancel()
×
3578

×
3579
        domainID := "568b8d19-cf64-4aac-be1b-f8a3edbc1fa9"
×
3580
        workflowExecution := types.WorkflowExecution{
×
3581
                WorkflowID: "test-workflow-mutable-request-cancel-test",
×
3582
                RunID:      "87f96253-b925-426e-90db-aa4ee89b5aca",
×
3583
        }
×
3584

×
3585
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3586
        s.NoError(err0)
×
3587
        s.NotNil(task0, "Expected non empty task identifier.")
×
3588

×
3589
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3590
        s.NoError(err1)
×
3591
        info0 := state0.ExecutionInfo
×
3592
        s.NotNil(info0, "Valid Workflow info expected.")
×
3593

×
3594
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3595
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3596
        updatedInfo.NextEventID = int64(5)
×
3597
        updatedInfo.LastProcessedEvent = int64(2)
×
3598
        requestCancelInfo := &p.RequestCancelInfo{
×
3599
                Version:               456,
×
3600
                InitiatedID:           2,
×
3601
                InitiatedEventBatchID: 1,
×
3602
                CancelRequestID:       uuid.New(),
×
3603
        }
×
3604
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3605
                {
×
3606
                        EventID: updatedInfo.LastProcessedEvent,
×
3607
                        Version: common.EmptyVersion,
×
3608
                },
×
3609
        })
×
3610
        versionHistories := p.NewVersionHistories(versionHistory)
×
3611
        err2 := s.UpsertRequestCancelState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), []*p.RequestCancelInfo{requestCancelInfo})
×
3612
        s.NoError(err2)
×
3613

×
3614
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3615
        s.NoError(err1)
×
3616
        s.NotNil(state, "expected valid state.")
×
3617
        s.Equal(1, len(state.RequestCancelInfos))
×
3618
        ri, ok := state.RequestCancelInfos[requestCancelInfo.InitiatedID]
×
3619
        s.True(ok)
×
3620
        s.NotNil(ri)
×
3621
        s.Equal(requestCancelInfo, ri)
×
3622

×
3623
        err2 = s.DeleteCancelState(ctx, updatedInfo, updatedStats, versionHistories, int64(5), requestCancelInfo.InitiatedID)
×
3624
        s.NoError(err2)
×
3625

×
3626
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3627
        s.NoError(err2)
×
3628
        s.NotNil(state, "expected valid state.")
×
3629
        s.Equal(0, len(state.RequestCancelInfos))
×
3630
}
×
3631

3632
// TestWorkflowMutableStateSignalInfo test
3633
func (s *ExecutionManagerSuite) TestWorkflowMutableStateSignalInfo() {
×
3634
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3635
        defer cancel()
×
3636

×
3637
        domainID := uuid.New()
×
3638
        runID := uuid.New()
×
3639
        workflowExecution := types.WorkflowExecution{
×
3640
                WorkflowID: "test-workflow-mutable-signal-info-test",
×
3641
                RunID:      runID,
×
3642
        }
×
3643

×
3644
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3645
        s.NoError(err0)
×
3646
        s.NotNil(task0, "Expected non empty task identifier.")
×
3647

×
3648
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3649
        s.NoError(err1)
×
3650
        info0 := state0.ExecutionInfo
×
3651
        s.NotNil(info0, "Valid Workflow info expected.")
×
3652

×
3653
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3654
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3655
        updatedInfo.NextEventID = int64(5)
×
3656
        updatedInfo.LastProcessedEvent = int64(2)
×
3657
        signalInfo := &p.SignalInfo{
×
3658
                Version:               123,
×
3659
                InitiatedID:           2,
×
3660
                InitiatedEventBatchID: 1,
×
3661
                SignalRequestID:       uuid.New(),
×
3662
                SignalName:            "my signal",
×
3663
                Input:                 []byte("test signal input"),
×
3664
                Control:               []byte(uuid.New()),
×
3665
        }
×
3666
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3667
                {
×
3668
                        EventID: updatedInfo.LastProcessedEvent,
×
3669
                        Version: common.EmptyVersion,
×
3670
                },
×
3671
        })
×
3672
        versionHistories := p.NewVersionHistories(versionHistory)
×
3673
        err2 := s.UpsertSignalInfoState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), []*p.SignalInfo{signalInfo})
×
3674
        s.NoError(err2)
×
3675

×
3676
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3677
        s.NoError(err1)
×
3678
        s.NotNil(state, "expected valid state.")
×
3679
        s.Equal(1, len(state.SignalInfos))
×
3680
        si, ok := state.SignalInfos[signalInfo.InitiatedID]
×
3681
        s.True(ok)
×
3682
        s.NotNil(si)
×
3683
        s.Equal(signalInfo, si)
×
3684

×
3685
        err2 = s.DeleteSignalState(ctx, updatedInfo, updatedStats, versionHistories, int64(5), signalInfo.InitiatedID)
×
3686
        s.NoError(err2)
×
3687

×
3688
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3689
        s.NoError(err2)
×
3690
        s.NotNil(state, "expected valid state.")
×
3691
        s.Equal(0, len(state.SignalInfos))
×
3692
}
×
3693

3694
// TestWorkflowMutableStateSignalRequested test
3695
func (s *ExecutionManagerSuite) TestWorkflowMutableStateSignalRequested() {
×
3696
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3697
        defer cancel()
×
3698

×
3699
        domainID := uuid.New()
×
3700
        runID := uuid.New()
×
3701
        workflowExecution := types.WorkflowExecution{
×
3702
                WorkflowID: "test-workflow-mutable-signal-requested-test",
×
3703
                RunID:      runID,
×
3704
        }
×
3705

×
3706
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3707
        s.NoError(err0)
×
3708
        s.NotNil(task0, "Expected non empty task identifier.")
×
3709

×
3710
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3711
        s.NoError(err1)
×
3712
        info0 := state0.ExecutionInfo
×
3713
        s.NotNil(info0, "Valid Workflow info expected.")
×
3714

×
3715
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3716
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3717
        updatedInfo.NextEventID = int64(5)
×
3718
        updatedInfo.LastProcessedEvent = int64(2)
×
3719
        signalRequestedID := uuid.New()
×
3720
        signalsRequested := []string{signalRequestedID}
×
3721
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3722
                {
×
3723
                        EventID: updatedInfo.LastProcessedEvent,
×
3724
                        Version: common.EmptyVersion,
×
3725
                },
×
3726
        })
×
3727
        versionHistories := p.NewVersionHistories(versionHistory)
×
3728
        err2 := s.UpsertSignalsRequestedState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), signalsRequested)
×
3729
        s.NoError(err2)
×
3730

×
3731
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3732
        s.NoError(err1)
×
3733
        s.NotNil(state, "expected valid state.")
×
3734
        s.Equal(1, len(state.SignalRequestedIDs))
×
3735
        ri, ok := state.SignalRequestedIDs[signalRequestedID]
×
3736
        s.True(ok)
×
3737
        s.NotNil(ri)
×
3738

×
3739
        err2 = s.DeleteSignalsRequestedState(ctx, updatedInfo, updatedStats, versionHistories, int64(5), []string{signalRequestedID, uuid.New()})
×
3740
        s.NoError(err2)
×
3741

×
3742
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3743
        s.NoError(err2)
×
3744
        s.NotNil(state, "expected valid state.")
×
3745
        s.Equal(0, len(state.SignalRequestedIDs))
×
3746
}
×
3747

3748
// TestWorkflowMutableStateInfo test
3749
func (s *ExecutionManagerSuite) TestWorkflowMutableStateInfo() {
×
3750
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3751
        defer cancel()
×
3752

×
3753
        domainID := "9ed8818b-3090-4160-9f21-c6b70e64d2dd"
×
3754
        workflowExecution := types.WorkflowExecution{
×
3755
                WorkflowID: "test-workflow-mutable-state-test",
×
3756
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3757
        }
×
3758

×
3759
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3760
        s.NoError(err0)
×
3761
        s.NotNil(task0, "Expected non empty task identifier.")
×
3762

×
3763
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3764
        s.NoError(err1)
×
3765
        info0 := state0.ExecutionInfo
×
3766
        s.NotNil(info0, "Valid Workflow info expected.")
×
3767

×
3768
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3769
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3770
        updatedInfo.NextEventID = int64(5)
×
3771
        updatedInfo.LastProcessedEvent = int64(2)
×
3772
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3773
                {
×
3774
                        EventID: updatedInfo.LastProcessedEvent,
×
3775
                        Version: common.EmptyVersion,
×
3776
                },
×
3777
        })
×
3778
        versionHistories := p.NewVersionHistories(versionHistory)
×
3779
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, nil, nil, nil, nil)
×
3780
        s.NoError(err2)
×
3781

×
3782
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3783
        s.NoError(err1)
×
3784
        s.NotNil(state, "expected valid state.")
×
3785
        s.NotNil(state.ExecutionInfo, "expected valid MS Info state.")
×
3786
        s.Equal(updatedInfo.NextEventID, state.ExecutionInfo.NextEventID)
×
3787
        s.Equal(updatedInfo.State, state.ExecutionInfo.State)
×
3788
}
×
3789

3790
// TestContinueAsNew test
3791
func (s *ExecutionManagerSuite) TestContinueAsNew() {
×
3792
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3793
        defer cancel()
×
3794

×
3795
        domainID := "c1c0bb55-04e6-4a9c-89d0-1be7b96459f8"
×
3796
        workflowExecution := types.WorkflowExecution{
×
3797
                WorkflowID: "continue-as-new-workflow-test",
×
3798
                RunID:      "551c88d2-d9e6-404f-8131-9eec14f36643",
×
3799
        }
×
3800

×
3801
        partitionConfig := map[string]string{
×
3802
                "userID": uuid.New(),
×
3803
        }
×
3804
        _, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, partitionConfig)
×
3805
        s.NoError(err0)
×
3806

×
3807
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3808
        s.NoError(err1)
×
3809
        info0 := state0.ExecutionInfo
×
3810
        continueAsNewInfo := copyWorkflowExecutionInfo(info0)
×
3811
        continueAsNewStats := copyExecutionStats(state0.ExecutionStats)
×
3812
        continueAsNewInfo.State = p.WorkflowStateCreated
×
3813
        continueAsNewInfo.CloseStatus = p.WorkflowCloseStatusNone
×
3814
        continueAsNewInfo.NextEventID = int64(5)
×
3815
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
3816

×
3817
        newWorkflowExecution := types.WorkflowExecution{
×
3818
                WorkflowID: "continue-as-new-workflow-test",
×
3819
                RunID:      "64c7e15a-3fd7-4182-9c6f-6f25a4fa2614",
×
3820
        }
×
3821

×
3822
        testResetPoints := types.ResetPoints{
×
3823
                Points: []*types.ResetPointInfo{
×
3824
                        {
×
3825
                                BinaryChecksum:           "test-binary-checksum",
×
3826
                                RunID:                    "test-runID",
×
3827
                                FirstDecisionCompletedID: 123,
×
3828
                                CreatedTimeNano:          common.Int64Ptr(456),
×
3829
                                Resettable:               true,
×
3830
                                ExpiringTimeNano:         common.Int64Ptr(789),
×
3831
                        },
×
3832
                },
×
3833
        }
×
3834

×
3835
        err2 := s.ContinueAsNewExecution(ctx, continueAsNewInfo, continueAsNewStats, info0.NextEventID, newWorkflowExecution, int64(3), int64(2), &testResetPoints)
×
3836
        s.NoError(err2)
×
3837

×
3838
        prevExecutionState, err3 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3839
        s.NoError(err3)
×
3840
        prevExecutionInfo := prevExecutionState.ExecutionInfo
×
3841
        s.Equal("551c88d2-d9e6-404f-8131-9eec14f36643", prevExecutionInfo.FirstExecutionRunID)
×
3842
        s.Equal(p.WorkflowStateCompleted, prevExecutionInfo.State)
×
3843
        s.Equal(p.WorkflowCloseStatusContinuedAsNew, prevExecutionInfo.CloseStatus)
×
3844
        s.Equal(int64(5), prevExecutionInfo.NextEventID)
×
3845
        s.Equal(int64(2), prevExecutionInfo.LastProcessedEvent)
×
3846
        s.Equal(prevExecutionInfo.AutoResetPoints, &types.ResetPoints{})
×
3847
        s.Equal(partitionConfig, prevExecutionInfo.PartitionConfig)
×
3848

×
3849
        newExecutionState, err4 := s.GetWorkflowExecutionInfo(ctx, domainID, newWorkflowExecution)
×
3850
        s.NoError(err4)
×
3851
        newExecutionInfo := newExecutionState.ExecutionInfo
×
3852
        s.Equal("551c88d2-d9e6-404f-8131-9eec14f36643", newExecutionInfo.FirstExecutionRunID)
×
3853
        s.Equal(p.WorkflowStateCreated, newExecutionInfo.State)
×
3854
        s.Equal(p.WorkflowCloseStatusNone, newExecutionInfo.CloseStatus)
×
3855
        s.Equal(int64(3), newExecutionInfo.NextEventID)
×
3856
        s.Equal(common.EmptyEventID, newExecutionInfo.LastProcessedEvent)
×
3857
        s.Equal(int64(2), newExecutionInfo.DecisionScheduleID)
×
3858
        s.Equal(testResetPoints, *newExecutionInfo.AutoResetPoints)
×
3859
        s.Equal(partitionConfig, newExecutionInfo.PartitionConfig)
×
3860

×
3861
        newRunID, err5 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
3862
        s.NoError(err5)
×
3863
        s.Equal(newWorkflowExecution.GetRunID(), newRunID)
×
3864
}
×
3865

3866
// TestReplicationTransferTaskTasks test
3867
func (s *ExecutionManagerSuite) TestReplicationTransferTaskTasks() {
×
3868
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3869
        defer cancel()
×
3870

×
3871
        domainID := "2466d7de-6602-4ad8-b939-fb8f8c36c711"
×
3872
        workflowExecution := types.WorkflowExecution{
×
3873
                WorkflowID: "replication-transfer-task-test",
×
3874
                RunID:      "dcde9d85-5d7a-43c7-8b18-cb2cae0e29e0",
×
3875
        }
×
3876

×
3877
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3878
        s.NoError(err)
×
3879
        s.NotNil(task0, "Expected non empty task identifier.")
×
3880

×
3881
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
3882
        s.NoError(err)
×
3883
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
3884
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
3885
        s.NoError(err)
×
3886

×
3887
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3888
        s.NoError(err)
×
3889
        info1 := state1.ExecutionInfo
×
3890
        s.NotNil(info1, "Valid Workflow info expected.")
×
3891
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
3892
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
3893

×
3894
        replicationTasks := []p.Task{&p.HistoryReplicationTask{
×
3895
                TaskData: p.TaskData{
×
3896
                        TaskID:  s.GetNextSequenceNumber(),
×
3897
                        Version: 9,
×
3898
                },
×
3899
                FirstEventID: 1,
×
3900
                NextEventID:  3,
×
3901
        }}
×
3902
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3903
                {
×
3904
                        EventID: 3,
×
3905
                        Version: common.EmptyVersion,
×
3906
                },
×
3907
        })
×
3908
        versionHistories := p.NewVersionHistories(versionHistory)
×
3909
        err = s.UpdateWorklowStateAndReplication(ctx, updatedInfo1, updatedStats1, versionHistories, int64(3), replicationTasks)
×
3910
        s.NoError(err)
×
3911

×
3912
        tasks1, err := s.GetReplicationTasks(ctx, 1, false)
×
3913
        s.NoError(err)
×
3914
        s.NotNil(tasks1, "expected valid list of tasks.")
×
3915
        s.Equal(1, len(tasks1), "Expected 1 replication task.")
×
3916
        task1 := tasks1[0]
×
3917
        s.Equal(p.ReplicationTaskTypeHistory, task1.TaskType)
×
3918
        s.Equal(domainID, task1.DomainID)
×
3919
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
3920
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
3921
        s.Equal(int64(1), task1.FirstEventID)
×
3922
        s.Equal(int64(3), task1.NextEventID)
×
3923
        s.Equal(int64(9), task1.Version)
×
3924

×
3925
        err = s.CompleteReplicationTask(ctx, task1.TaskID)
×
3926
        s.NoError(err)
×
3927
        tasks2, err := s.GetReplicationTasks(ctx, 1, false)
×
3928
        s.NoError(err)
×
3929
        s.Equal(0, len(tasks2))
×
3930
}
×
3931

3932
// TestReplicationTransferTaskRangeComplete test
3933
func (s *ExecutionManagerSuite) TestReplicationTransferTaskRangeComplete() {
×
3934
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3935
        defer cancel()
×
3936

×
3937
        domainID := uuid.New()
×
3938
        workflowExecution := types.WorkflowExecution{
×
3939
                WorkflowID: "replication-transfer-task--range-complete-test",
×
3940
                RunID:      uuid.New(),
×
3941
        }
×
3942

×
3943
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3944
        s.NoError(err)
×
3945
        s.NotNil(task0, "Expected non empty task identifier.")
×
3946

×
3947
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
3948
        s.NoError(err)
×
3949
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
3950
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
3951
        s.NoError(err)
×
3952

×
3953
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3954
        s.NoError(err)
×
3955
        info1 := state1.ExecutionInfo
×
3956
        s.NotNil(info1, "Valid Workflow info expected.")
×
3957
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
3958
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
3959

×
3960
        replicationTasks := []p.Task{
×
3961
                &p.HistoryReplicationTask{
×
3962
                        TaskData: p.TaskData{
×
3963
                                TaskID:  s.GetNextSequenceNumber(),
×
3964
                                Version: 9,
×
3965
                        },
×
3966
                        FirstEventID: 1,
×
3967
                        NextEventID:  3,
×
3968
                },
×
3969
                &p.HistoryReplicationTask{
×
3970
                        TaskData: p.TaskData{
×
3971
                                TaskID:  s.GetNextSequenceNumber(),
×
3972
                                Version: 9,
×
3973
                        },
×
3974
                        FirstEventID: 4,
×
3975
                        NextEventID:  5,
×
3976
                },
×
3977
        }
×
3978
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3979
                {
×
3980
                        EventID: 3,
×
3981
                        Version: common.EmptyVersion,
×
3982
                },
×
3983
        })
×
3984
        versionHistories := p.NewVersionHistories(versionHistory)
×
3985
        err = s.UpdateWorklowStateAndReplication(ctx,
×
3986
                updatedInfo1,
×
3987
                updatedStats1,
×
3988
                versionHistories,
×
3989
                int64(3),
×
3990
                replicationTasks,
×
3991
        )
×
3992
        s.NoError(err)
×
3993

×
3994
        tasks1, err := s.GetReplicationTasks(ctx, 2, false)
×
3995
        s.NoError(err)
×
3996
        s.NotNil(tasks1, "expected valid list of tasks.")
×
3997
        s.Equal(2, len(tasks1), "Expected 2 replication tasks.")
×
3998
        task1 := tasks1[0]
×
3999
        s.Equal(p.ReplicationTaskTypeHistory, task1.TaskType)
×
4000
        s.Equal(domainID, task1.DomainID)
×
4001
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
4002
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
4003
        s.Equal(int64(1), task1.FirstEventID)
×
4004
        s.Equal(int64(3), task1.NextEventID)
×
4005
        s.Equal(int64(9), task1.Version)
×
4006

×
4007
        task2 := tasks1[1]
×
4008
        s.Equal(p.ReplicationTaskTypeHistory, task2.TaskType)
×
4009
        s.Equal(domainID, task2.DomainID)
×
4010
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
4011
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
4012
        s.Equal(int64(4), task2.FirstEventID)
×
4013
        s.Equal(int64(5), task2.NextEventID)
×
4014
        s.Equal(int64(9), task2.Version)
×
4015
        err = s.RangeCompleteReplicationTask(ctx, task2.TaskID)
×
4016
        s.NoError(err)
×
4017
        tasks2, err := s.GetReplicationTasks(ctx, 1, false)
×
4018
        s.NoError(err)
×
4019
        s.Equal(0, len(tasks2))
×
4020
}
×
4021

4022
// TestUpdateAndClearBufferedEvents test
4023
func (s *ExecutionManagerSuite) TestUpdateAndClearBufferedEvents() {
×
4024
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4025
        defer cancel()
×
4026

×
4027
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
4028
        workflowExecution := types.WorkflowExecution{
×
4029
                WorkflowID: "test-update-and-clear-buffered-events",
×
4030
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4031
        }
×
4032

×
4033
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
4034
        s.NoError(err0)
×
4035
        s.NotNil(task0, "Expected non empty task identifier.")
×
4036

×
4037
        stats0, state0, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4038
        s.NoError(err1)
×
4039
        info0 := state0.ExecutionInfo
×
4040
        s.NotNil(info0, "Valid Workflow info expected.")
×
4041
        s.Equal(0, stats0.BufferedEventsCount)
×
4042
        s.Equal(0, stats0.BufferedEventsSize)
×
4043

×
4044
        eventsBatch1 := []*types.HistoryEvent{
×
4045
                {
×
4046
                        ID:        5,
×
4047
                        EventType: types.EventTypeDecisionTaskCompleted.Ptr(),
×
4048
                        Version:   11,
×
4049
                        DecisionTaskCompletedEventAttributes: &types.DecisionTaskCompletedEventAttributes{
×
4050
                                ScheduledEventID: 2,
×
4051
                                StartedEventID:   3,
×
4052
                                Identity:         "test_worker",
×
4053
                        },
×
4054
                },
×
4055
                {
×
4056
                        ID:        6,
×
4057
                        EventType: types.EventTypeTimerStarted.Ptr(),
×
4058
                        Version:   11,
×
4059
                        TimerStartedEventAttributes: &types.TimerStartedEventAttributes{
×
4060
                                TimerID:                      "ID1",
×
4061
                                StartToFireTimeoutSeconds:    common.Int64Ptr(101),
×
4062
                                DecisionTaskCompletedEventID: 5,
×
4063
                        },
×
4064
                },
×
4065
        }
×
4066

×
4067
        eventsBatch2 := []*types.HistoryEvent{
×
4068
                {
×
4069
                        ID:        21,
×
4070
                        EventType: types.EventTypeTimerFired.Ptr(),
×
4071
                        Version:   12,
×
4072
                        TimerFiredEventAttributes: &types.TimerFiredEventAttributes{
×
4073
                                TimerID:        "2",
×
4074
                                StartedEventID: 3,
×
4075
                        },
×
4076
                },
×
4077
        }
×
4078
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4079
                {
×
4080
                        EventID: eventsBatch2[0].ID,
×
4081
                        Version: common.EmptyVersion,
×
4082
                },
×
4083
        })
×
4084
        versionHistories := p.NewVersionHistories(versionHistory)
×
4085
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
4086
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
4087
        updatedState := &p.WorkflowMutableState{
×
4088
                ExecutionInfo:    updatedInfo,
×
4089
                ExecutionStats:   updatedStats,
×
4090
                VersionHistories: versionHistories,
×
4091
        }
×
4092

×
4093
        err2 := s.UpdateAllMutableState(ctx, updatedState, int64(3))
×
4094
        s.NoError(err2)
×
4095

×
4096
        partialState, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
4097
        s.NoError(err2)
×
4098
        s.NotNil(partialState, "expected valid state.")
×
4099
        partialInfo := partialState.ExecutionInfo
×
4100
        s.NotNil(partialInfo, "Valid Workflow info expected.")
×
4101

×
4102
        bufferUpdateInfo := copyWorkflowExecutionInfo(partialInfo)
×
4103
        bufferedUpdatedStats := copyExecutionStats(state0.ExecutionStats)
×
4104
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
4105
        s.NoError(err2)
×
4106
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
4107
        s.NoError(err2)
×
4108
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch1, false, versionHistories)
×
4109
        s.NoError(err2)
×
4110
        stats0, state0, err2 = s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4111
        s.NoError(err2)
×
4112
        s.Equal(1, stats0.BufferedEventsCount)
×
4113
        s.True(stats0.BufferedEventsSize > 0)
×
4114
        testHistory := &types.History{Events: make([]*types.HistoryEvent, 0)}
×
4115
        testHistory.Events = append(testHistory.Events, eventsBatch1...)
×
4116
        history0 := &types.History{Events: state0.BufferedEvents}
×
4117
        s.Equal(testHistory, history0)
×
4118
        testHistory.Events = append(testHistory.Events, eventsBatch2...)
×
4119

×
4120
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch2, false, versionHistories)
×
4121
        s.NoError(err2)
×
4122

×
4123
        stats1, state1, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4124
        s.NoError(err1)
×
4125
        s.NotNil(state1, "expected valid state.")
×
4126
        info1 := state1.ExecutionInfo
×
4127
        s.NotNil(info1, "Valid Workflow info expected.")
×
4128
        s.Equal(2, stats1.BufferedEventsCount)
×
4129
        s.True(stats1.BufferedEventsSize > 0)
×
4130
        history1 := &types.History{Events: state1.BufferedEvents}
×
4131
        s.Equal(testHistory, history1)
×
4132

×
4133
        err3 := s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, nil, true, versionHistories)
×
4134
        s.NoError(err3)
×
4135

×
4136
        stats3, state3, err3 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4137
        s.NoError(err3)
×
4138
        s.NotNil(state3, "expected valid state.")
×
4139
        info3 := state3.ExecutionInfo
×
4140
        s.NotNil(info3, "Valid Workflow info expected.")
×
4141
        s.Equal(0, stats3.BufferedEventsCount)
×
4142
        s.Equal(0, stats3.BufferedEventsSize)
×
4143
}
×
4144

4145
// TestConflictResolveWorkflowExecutionCurrentIsSelf test
4146
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSelf() {
×
4147
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4148
        defer cancel()
×
4149

×
4150
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
4151
        workflowExecution := types.WorkflowExecution{
×
4152
                WorkflowID: "test-reset-mutable-state-test-current-is-self",
×
4153
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4154
        }
×
4155
        partitionConfig := map[string]string{
×
4156
                "userid": uuid.New(),
×
4157
        }
×
4158
        task0, err0 := s.CreateWorkflowExecution(
×
4159
                ctx,
×
4160
                domainID,
×
4161
                workflowExecution,
×
4162
                "taskList",
×
4163
                "wType",
×
4164
                20,
×
4165
                13,
×
4166
                nil,
×
4167
                3,
×
4168
                0,
×
4169
                2,
×
4170
                nil,
×
4171
                partitionConfig,
×
4172
        )
×
4173
        s.NoError(err0)
×
4174
        s.NotNil(task0, "Expected non empty task identifier.")
×
4175

×
4176
        stats0, state0, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4177
        s.NoError(err1)
×
4178
        info0 := state0.ExecutionInfo
×
4179
        s.NotNil(info0, "Valid Workflow info expected.")
×
4180
        s.Equal(0, stats0.BufferedEventsCount)
×
4181
        s.Equal(0, stats0.BufferedEventsSize)
×
4182

×
4183
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
4184
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
4185
        updatedInfo.NextEventID = int64(5)
×
4186
        updatedInfo.LastProcessedEvent = int64(2)
×
4187
        currentTime := time.Now().UTC()
×
4188
        expiryTime := currentTime.Add(10 * time.Second)
×
4189
        eventsBatch1 := []*types.HistoryEvent{
×
4190
                {
×
4191
                        ID:        5,
×
4192
                        EventType: types.EventTypeDecisionTaskCompleted.Ptr(),
×
4193
                        Version:   11,
×
4194
                        DecisionTaskCompletedEventAttributes: &types.DecisionTaskCompletedEventAttributes{
×
4195
                                ScheduledEventID: 2,
×
4196
                                StartedEventID:   3,
×
4197
                                Identity:         "test_worker",
×
4198
                        },
×
4199
                },
×
4200
                {
×
4201
                        ID:        6,
×
4202
                        EventType: types.EventTypeTimerStarted.Ptr(),
×
4203
                        Version:   11,
×
4204
                        TimerStartedEventAttributes: &types.TimerStartedEventAttributes{
×
4205
                                TimerID:                      "ID1",
×
4206
                                StartToFireTimeoutSeconds:    common.Int64Ptr(101),
×
4207
                                DecisionTaskCompletedEventID: 5,
×
4208
                        },
×
4209
                },
×
4210
        }
×
4211

×
4212
        eventsBatch2 := []*types.HistoryEvent{
×
4213
                {
×
4214
                        ID:        21,
×
4215
                        EventType: types.EventTypeTimerFired.Ptr(),
×
4216
                        Version:   12,
×
4217
                        TimerFiredEventAttributes: &types.TimerFiredEventAttributes{
×
4218
                                TimerID:        "2",
×
4219
                                StartedEventID: 3,
×
4220
                        },
×
4221
                },
×
4222
        }
×
4223

×
4224
        csum := s.newRandomChecksum()
×
4225

×
4226
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4227
                {
×
4228
                        EventID: updatedInfo.LastProcessedEvent,
×
4229
                        Version: common.EmptyVersion,
×
4230
                },
×
4231
        })
×
4232
        versionHistories := p.NewVersionHistories(versionHistory)
×
4233
        updatedState := &p.WorkflowMutableState{
×
4234
                ExecutionInfo:  updatedInfo,
×
4235
                ExecutionStats: updatedStats,
×
4236
                ActivityInfos: map[int64]*p.ActivityInfo{
×
4237
                        4: {
×
4238
                                Version:                  7789,
×
4239
                                ScheduleID:               4,
×
4240
                                ScheduledEventBatchID:    3,
×
4241
                                ScheduledEvent:           &types.HistoryEvent{ID: 40},
×
4242
                                ScheduledTime:            currentTime,
×
4243
                                StartedID:                6,
×
4244
                                StartedEvent:             &types.HistoryEvent{ID: 60},
×
4245
                                StartedTime:              currentTime,
×
4246
                                ScheduleToCloseTimeout:   1,
×
4247
                                ScheduleToStartTimeout:   2,
×
4248
                                StartToCloseTimeout:      3,
×
4249
                                HeartbeatTimeout:         4,
×
4250
                                LastHeartBeatUpdatedTime: currentTime,
×
4251
                                TimerTaskStatus:          1,
×
4252
                        },
×
4253
                        5: {
×
4254
                                Version:                  7789,
×
4255
                                ScheduleID:               5,
×
4256
                                ScheduledEventBatchID:    3,
×
4257
                                ScheduledEvent:           &types.HistoryEvent{ID: 50},
×
4258
                                ScheduledTime:            currentTime,
×
4259
                                StartedID:                7,
×
4260
                                StartedEvent:             &types.HistoryEvent{ID: 70},
×
4261
                                StartedTime:              currentTime,
×
4262
                                ScheduleToCloseTimeout:   1,
×
4263
                                ScheduleToStartTimeout:   2,
×
4264
                                StartToCloseTimeout:      3,
×
4265
                                HeartbeatTimeout:         4,
×
4266
                                LastHeartBeatUpdatedTime: currentTime,
×
4267
                                TimerTaskStatus:          1,
×
4268
                        }},
×
4269

×
4270
                TimerInfos: map[string]*p.TimerInfo{
×
4271
                        "t1": {
×
4272
                                Version:    2333,
×
4273
                                TimerID:    "t1",
×
4274
                                StartedID:  1,
×
4275
                                ExpiryTime: expiryTime,
×
4276
                                TaskStatus: 500,
×
4277
                        },
×
4278
                        "t2": {
×
4279
                                Version:    2333,
×
4280
                                TimerID:    "t2",
×
4281
                                StartedID:  2,
×
4282
                                ExpiryTime: expiryTime,
×
4283
                                TaskStatus: 501,
×
4284
                        },
×
4285
                        "t3": {
×
4286
                                Version:    2333,
×
4287
                                TimerID:    "t3",
×
4288
                                StartedID:  3,
×
4289
                                ExpiryTime: expiryTime,
×
4290
                                TaskStatus: 502,
×
4291
                        },
×
4292
                },
×
4293

×
4294
                ChildExecutionInfos: map[int64]*p.ChildExecutionInfo{
×
4295
                        9: {
×
4296
                                Version:         2334,
×
4297
                                InitiatedID:     9,
×
4298
                                InitiatedEvent:  &types.HistoryEvent{ID: 123},
×
4299
                                StartedID:       11,
×
4300
                                StartedRunID:    uuid.New(),
×
4301
                                StartedEvent:    nil,
×
4302
                                CreateRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4303
                                DomainID:        uuid.New(),
×
4304
                        },
×
4305
                },
×
4306

×
4307
                RequestCancelInfos: map[int64]*p.RequestCancelInfo{
×
4308
                        19: {
×
4309
                                Version:               2335,
×
4310
                                InitiatedID:           19,
×
4311
                                InitiatedEventBatchID: 17,
×
4312
                                CancelRequestID:       "cancel_requested_id",
×
4313
                        },
×
4314
                },
×
4315

×
4316
                SignalInfos: map[int64]*p.SignalInfo{
×
4317
                        39: {
×
4318
                                Version:               2336,
×
4319
                                InitiatedID:           39,
×
4320
                                InitiatedEventBatchID: 38,
×
4321
                                SignalRequestID:       "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4322
                                SignalName:            "signalA",
×
4323
                                Input:                 []byte("signal_input_A"),
×
4324
                                Control:               []byte("signal_control_A"),
×
4325
                        },
×
4326
                },
×
4327

×
4328
                SignalRequestedIDs: map[string]struct{}{
×
4329
                        "00000000-0000-0000-0000-000000000001": {},
×
4330
                        "00000000-0000-0000-0000-000000000002": {},
×
4331
                        "00000000-0000-0000-0000-000000000003": {},
×
4332
                },
×
4333
                Checksum:         csum,
×
4334
                VersionHistories: versionHistories,
×
4335
        }
×
4336

×
4337
        err2 := s.UpdateAllMutableState(ctx, updatedState, int64(3))
×
4338
        s.NoError(err2)
×
4339

×
4340
        partialState, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
4341
        s.NoError(err2)
×
4342
        s.NotNil(partialState, "expected valid state.")
×
4343
        partialInfo := partialState.ExecutionInfo
×
4344
        s.NotNil(partialInfo, "Valid Workflow info expected.")
×
4345
        s.assertChecksumsEqual(csum, partialState.Checksum)
×
4346

×
4347
        bufferUpdateInfo := copyWorkflowExecutionInfo(partialInfo)
×
4348
        bufferedUpdatedStats := copyExecutionStats(partialState.ExecutionStats)
×
4349
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
4350
        s.NoError(err2)
×
4351
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
4352
        s.NoError(err2)
×
4353
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch1, false, versionHistories)
×
4354
        s.NoError(err2)
×
4355
        stats0, state0, err2 = s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4356
        s.NoError(err2)
×
4357
        s.Equal(1, stats0.BufferedEventsCount)
×
4358
        s.True(stats0.BufferedEventsSize > 0)
×
4359
        s.assertChecksumsEqual(testWorkflowChecksum, state0.Checksum)
×
4360
        testHistory := &types.History{Events: make([]*types.HistoryEvent, 0)}
×
4361
        testHistory.Events = append(testHistory.Events, eventsBatch1...)
×
4362
        history0 := &types.History{Events: state0.BufferedEvents}
×
4363
        s.Equal(testHistory, history0)
×
4364
        testHistory.Events = append(testHistory.Events, eventsBatch2...)
×
4365

×
4366
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch2, false, versionHistories)
×
4367
        s.NoError(err2)
×
4368

×
4369
        stats1, state1, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4370
        s.NoError(err1)
×
4371
        s.NotNil(state1, "expected valid state.")
×
4372
        info1 := state1.ExecutionInfo
×
4373
        s.NotNil(info1, "Valid Workflow info expected.")
×
4374
        s.Equal(2, stats1.BufferedEventsCount)
×
4375
        s.True(stats1.BufferedEventsSize > 0)
×
4376
        s.assertChecksumsEqual(testWorkflowChecksum, state1.Checksum)
×
4377
        history1 := &types.History{Events: state1.BufferedEvents}
×
4378
        s.Equal(testHistory, history1)
×
4379

×
4380
        s.Equal(2, len(state1.ActivityInfos))
×
4381
        ai, ok := state1.ActivityInfos[4]
×
4382
        s.True(ok)
×
4383
        s.NotNil(ai)
×
4384
        s.Equal(int64(7789), ai.Version)
×
4385
        s.Equal(int64(4), ai.ScheduleID)
×
4386
        s.Equal(int64(3), ai.ScheduledEventBatchID)
×
4387
        s.Equal(int64(40), ai.ScheduledEvent.ID)
×
4388
        s.EqualTimes(currentTime, ai.ScheduledTime)
×
4389
        s.Equal(int64(6), ai.StartedID)
×
4390
        s.Equal(int64(60), ai.StartedEvent.ID)
×
4391
        s.EqualTimes(currentTime, ai.StartedTime)
×
4392
        s.Equal(int32(1), ai.ScheduleToCloseTimeout)
×
4393
        s.Equal(int32(2), ai.ScheduleToStartTimeout)
×
4394
        s.Equal(int32(3), ai.StartToCloseTimeout)
×
4395
        s.Equal(int32(4), ai.HeartbeatTimeout)
×
4396
        s.EqualTimes(currentTime, ai.LastHeartBeatUpdatedTime)
×
4397
        s.Equal(int32(1), ai.TimerTaskStatus)
×
4398

×
4399
        ai, ok = state1.ActivityInfos[5]
×
4400
        s.True(ok)
×
4401
        s.NotNil(ai)
×
4402
        s.Equal(int64(7789), ai.Version)
×
4403
        s.Equal(int64(5), ai.ScheduleID)
×
4404
        s.Equal(int64(3), ai.ScheduledEventBatchID)
×
4405
        s.Equal(int64(50), ai.ScheduledEvent.ID)
×
4406
        s.EqualTimes(currentTime, ai.ScheduledTime)
×
4407
        s.Equal(int64(7), ai.StartedID)
×
4408
        s.Equal(int64(70), ai.StartedEvent.ID)
×
4409
        s.EqualTimes(currentTime, ai.StartedTime)
×
4410
        s.Equal(int32(1), ai.ScheduleToCloseTimeout)
×
4411
        s.Equal(int32(2), ai.ScheduleToStartTimeout)
×
4412
        s.Equal(int32(3), ai.StartToCloseTimeout)
×
4413
        s.Equal(int32(4), ai.HeartbeatTimeout)
×
4414
        s.EqualTimes(currentTime, ai.LastHeartBeatUpdatedTime)
×
4415
        s.Equal(int32(1), ai.TimerTaskStatus)
×
4416

×
4417
        s.Equal(3, len(state1.TimerInfos))
×
4418
        ti, ok := state1.TimerInfos["t1"]
×
4419
        s.True(ok)
×
4420
        s.NotNil(ti)
×
4421
        s.Equal(int64(2333), ti.Version)
×
4422
        s.Equal("t1", ti.TimerID)
×
4423
        s.Equal(int64(1), ti.StartedID)
×
4424
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4425
        s.Equal(int64(500), ti.TaskStatus)
×
4426

×
4427
        ti, ok = state1.TimerInfos["t2"]
×
4428
        s.True(ok)
×
4429
        s.NotNil(ti)
×
4430
        s.Equal(int64(2333), ti.Version)
×
4431
        s.Equal("t2", ti.TimerID)
×
4432
        s.Equal(int64(2), ti.StartedID)
×
4433
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4434
        s.Equal(int64(501), ti.TaskStatus)
×
4435

×
4436
        ti, ok = state1.TimerInfos["t3"]
×
4437
        s.True(ok)
×
4438
        s.NotNil(ti)
×
4439
        s.Equal(int64(2333), ti.Version)
×
4440
        s.Equal("t3", ti.TimerID)
×
4441
        s.Equal(int64(3), ti.StartedID)
×
4442
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4443
        s.Equal(int64(502), ti.TaskStatus)
×
4444

×
4445
        s.Equal(1, len(state1.ChildExecutionInfos))
×
4446
        ci, ok := state1.ChildExecutionInfos[9]
×
4447
        s.True(ok)
×
4448
        s.NotNil(ci)
×
4449
        s.Equal(updatedState.ChildExecutionInfos[9], ci)
×
4450

×
4451
        s.Equal(1, len(state1.RequestCancelInfos))
×
4452
        rci, ok := state1.RequestCancelInfos[19]
×
4453
        s.True(ok)
×
4454
        s.NotNil(rci)
×
4455
        s.Equal(int64(2335), rci.Version)
×
4456

×
4457
        s.Equal(1, len(state1.SignalInfos))
×
4458
        si, ok := state1.SignalInfos[39]
×
4459
        s.True(ok)
×
4460
        s.NotNil(si)
×
4461
        s.Equal(int64(2336), si.Version)
×
4462

×
4463
        s.Equal(3, len(state1.SignalRequestedIDs))
×
4464
        _, contains := state1.SignalRequestedIDs["00000000-0000-0000-0000-000000000001"]
×
4465
        s.True(contains)
×
4466
        _, contains = state1.SignalRequestedIDs["00000000-0000-0000-0000-000000000002"]
×
4467
        s.True(contains)
×
4468
        _, contains = state1.SignalRequestedIDs["00000000-0000-0000-0000-000000000003"]
×
4469
        s.True(contains)
×
4470

×
4471
        s.Equal(3, len(state1.BufferedEvents))
×
4472

×
4473
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
4474
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
4475
        updatedInfo1.NextEventID = int64(3)
×
4476
        resetActivityInfos := []*p.ActivityInfo{
×
4477
                {
×
4478
                        Version:                  8789,
×
4479
                        ScheduleID:               40,
×
4480
                        ScheduledEventBatchID:    30,
×
4481
                        ScheduledEvent:           &types.HistoryEvent{ID: 400},
×
4482
                        ScheduledTime:            currentTime,
×
4483
                        StartedID:                60,
×
4484
                        StartedEvent:             &types.HistoryEvent{ID: 600},
×
4485
                        StartedTime:              currentTime,
×
4486
                        ScheduleToCloseTimeout:   10,
×
4487
                        ScheduleToStartTimeout:   20,
×
4488
                        StartToCloseTimeout:      30,
×
4489
                        HeartbeatTimeout:         40,
×
4490
                        LastHeartBeatUpdatedTime: currentTime,
×
4491
                        TimerTaskStatus:          1,
×
4492
                }}
×
4493

×
4494
        resetTimerInfos := []*p.TimerInfo{
×
4495
                {
×
4496
                        Version:    3333,
×
4497
                        TimerID:    "t1_new",
×
4498
                        StartedID:  1,
×
4499
                        ExpiryTime: expiryTime,
×
4500
                        TaskStatus: 600,
×
4501
                },
×
4502
                {
×
4503
                        Version:    3333,
×
4504
                        TimerID:    "t2_new",
×
4505
                        StartedID:  2,
×
4506
                        ExpiryTime: expiryTime,
×
4507
                        TaskStatus: 601,
×
4508
                }}
×
4509

×
4510
        resetChildExecutionInfos := []*p.ChildExecutionInfo{
×
4511
                {
×
4512
                        Version:         3334,
×
4513
                        InitiatedID:     10,
×
4514
                        InitiatedEvent:  &types.HistoryEvent{ID: 10},
×
4515
                        StartedID:       15,
×
4516
                        StartedRunID:    uuid.New(),
×
4517
                        StartedEvent:    nil,
×
4518
                        CreateRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4519
                        DomainID:        uuid.New(),
×
4520
                }}
×
4521

×
4522
        resetRequestCancelInfos := []*p.RequestCancelInfo{
×
4523
                {
×
4524
                        Version:         3335,
×
4525
                        InitiatedID:     29,
×
4526
                        CancelRequestID: "new_cancel_requested_id",
×
4527
                }}
×
4528

×
4529
        resetSignalInfos := []*p.SignalInfo{
×
4530
                {
×
4531
                        Version:         3336,
×
4532
                        InitiatedID:     39,
×
4533
                        SignalRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4534
                        SignalName:      "signalB",
×
4535
                        Input:           []byte("signal_input_b"),
×
4536
                        Control:         []byte("signal_control_b"),
×
4537
                },
×
4538
                {
×
4539
                        Version:         3336,
×
4540
                        InitiatedID:     42,
×
4541
                        SignalRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4542
                        SignalName:      "signalC",
×
4543
                        Input:           []byte("signal_input_c"),
×
4544
                        Control:         []byte("signal_control_c"),
×
4545
                }}
×
4546
        err3 := s.ConflictResolveWorkflowExecution(
×
4547
                ctx,
×
4548
                updatedInfo1,
×
4549
                updatedStats1,
×
4550
                int64(5),
×
4551
                resetActivityInfos,
×
4552
                resetTimerInfos,
×
4553
                resetChildExecutionInfos,
×
4554
                resetRequestCancelInfos,
×
4555
                resetSignalInfos,
×
4556
                nil,
×
4557
                versionHistories,
×
4558
        )
×
4559
        s.NoError(err3)
×
4560

×
4561
        stats4, state4, err4 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4562
        s.NoError(err4)
×
4563
        s.NotNil(state4, "expected valid state.")
×
4564
        s.Equal(0, stats4.BufferedEventsCount)
×
4565
        s.Equal(0, stats4.BufferedEventsSize)
×
4566

×
4567
        info4 := state4.ExecutionInfo
×
4568
        s.T().Logf("%+v\n", info4)
×
4569
        s.NotNil(info4, "Valid Workflow info expected.")
×
4570
        s.Equal(int64(3), info4.NextEventID)
×
4571
        s.Equal("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", info4.FirstExecutionRunID)
×
4572
        s.Equal(partitionConfig, info4.PartitionConfig)
×
4573

×
4574
        s.Equal(1, len(state4.ActivityInfos))
×
4575
        ai, ok = state4.ActivityInfos[40]
×
4576
        s.True(ok)
×
4577
        s.NotNil(ai)
×
4578
        s.Equal(int64(8789), ai.Version)
×
4579
        s.Equal(int64(40), ai.ScheduleID)
×
4580
        s.Equal(int64(30), ai.ScheduledEventBatchID)
×
4581
        s.Equal(int64(400), ai.ScheduledEvent.ID)
×
4582
        s.Equal(currentTime.Unix(), ai.ScheduledTime.Unix())
×
4583
        s.Equal(int64(60), ai.StartedID)
×
4584
        s.Equal(int64(600), ai.StartedEvent.ID)
×
4585
        s.Equal(currentTime.Unix(), ai.StartedTime.Unix())
×
4586
        s.Equal(int32(10), ai.ScheduleToCloseTimeout)
×
4587
        s.Equal(int32(20), ai.ScheduleToStartTimeout)
×
4588
        s.Equal(int32(30), ai.StartToCloseTimeout)
×
4589
        s.Equal(int32(40), ai.HeartbeatTimeout)
×
4590
        s.Equal(currentTime.Unix(), ai.LastHeartBeatUpdatedTime.Unix())
×
4591
        s.Equal(int32(1), ai.TimerTaskStatus)
×
4592

×
4593
        s.Equal(2, len(state4.TimerInfos))
×
4594
        ti, ok = state4.TimerInfos["t1_new"]
×
4595
        s.True(ok)
×
4596
        s.NotNil(ai)
×
4597
        s.Equal(int64(3333), ti.Version)
×
4598
        s.Equal("t1_new", ti.TimerID)
×
4599
        s.Equal(int64(1), ti.StartedID)
×
4600
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4601
        s.Equal(int64(600), ti.TaskStatus)
×
4602

×
4603
        ti, ok = state4.TimerInfos["t2_new"]
×
4604
        s.True(ok)
×
4605
        s.NotNil(ai)
×
4606
        s.Equal(int64(3333), ti.Version)
×
4607
        s.Equal("t2_new", ti.TimerID)
×
4608
        s.Equal(int64(2), ti.StartedID)
×
4609
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4610
        s.Equal(int64(601), ti.TaskStatus)
×
4611

×
4612
        s.Equal(1, len(state4.ChildExecutionInfos))
×
4613
        ci, ok = state4.ChildExecutionInfos[10]
×
4614
        s.True(ok)
×
4615
        s.NotNil(ci)
×
4616
        s.Equal(resetChildExecutionInfos[0], ci)
×
4617

×
4618
        s.Equal(1, len(state4.RequestCancelInfos))
×
4619
        rci, ok = state4.RequestCancelInfos[29]
×
4620
        s.True(ok)
×
4621
        s.NotNil(rci)
×
4622
        s.Equal(int64(3335), rci.Version)
×
4623
        s.Equal(int64(29), rci.InitiatedID)
×
4624
        s.Equal("new_cancel_requested_id", rci.CancelRequestID)
×
4625

×
4626
        s.Equal(2, len(state4.SignalInfos))
×
4627
        si, ok = state4.SignalInfos[39]
×
4628
        s.True(ok)
×
4629
        s.NotNil(si)
×
4630
        s.Equal(int64(3336), si.Version)
×
4631
        s.Equal(int64(39), si.InitiatedID)
×
4632
        s.Equal("signalB", si.SignalName)
×
4633
        s.Equal([]byte("signal_input_b"), si.Input)
×
4634
        s.Equal([]byte("signal_control_b"), si.Control)
×
4635

×
4636
        si, ok = state4.SignalInfos[42]
×
4637
        s.True(ok)
×
4638
        s.NotNil(si)
×
4639
        s.Equal(int64(3336), si.Version)
×
4640
        s.Equal(int64(42), si.InitiatedID)
×
4641
        s.Equal("signalC", si.SignalName)
×
4642
        s.Equal([]byte("signal_input_c"), si.Input)
×
4643
        s.Equal([]byte("signal_control_c"), si.Control)
×
4644

×
4645
        s.Equal(0, len(state4.SignalRequestedIDs))
×
4646

×
4647
        s.Equal(0, len(state4.BufferedEvents))
×
4648
        s.assertChecksumsEqual(testWorkflowChecksum, state4.Checksum)
×
4649

×
4650
}
×
4651

4652
// TestConflictResolveWorkflowExecutionWithCASMismatch test
4653
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithCASMismatch() {
×
4654
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4655
        defer cancel()
×
4656

×
4657
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
4658
        workflowID := "test-reset-mutable-state-test-mismatch"
×
4659

×
4660
        // first create a workflow and continue as new it
×
4661
        workflowExecutionReset := types.WorkflowExecution{
×
4662
                WorkflowID: workflowID,
×
4663
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4664
        }
×
4665
        partitionConfig := map[string]string{
×
4666
                "userid": uuid.New(),
×
4667
        }
×
4668
        nextEventID := int64(3)
×
4669
        resp, err := s.CreateWorkflowExecution(
×
4670
                ctx,
×
4671
                domainID,
×
4672
                workflowExecutionReset,
×
4673
                "taskList",
×
4674
                "wType",
×
4675
                20,
×
4676
                13,
×
4677
                nil,
×
4678
                nextEventID,
×
4679
                0,
×
4680
                2,
×
4681
                nil,
×
4682
                partitionConfig,
×
4683
        )
×
4684
        s.NoError(err)
×
4685
        s.NotNil(resp)
×
4686

×
4687
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4688
        s.NoError(err)
×
4689

×
4690
        info := state.ExecutionInfo
×
4691
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
4692
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
4693
        continueAsNewInfo.State = p.WorkflowStateRunning
×
4694
        continueAsNewInfo.NextEventID = int64(5)
×
4695
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
4696

×
4697
        workflowExecutionCurrent := types.WorkflowExecution{
×
4698
                WorkflowID: workflowID,
×
4699
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
4700
        }
×
4701
        err = s.ContinueAsNewExecution(
×
4702
                ctx,
×
4703
                continueAsNewInfo,
×
4704
                continueAsNewStats,
×
4705
                info.NextEventID,
×
4706
                workflowExecutionCurrent,
×
4707
                int64(3),
×
4708
                int64(2),
×
4709
                nil,
×
4710
        )
×
4711
        s.NoError(err)
×
4712

×
4713
        runID1, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4714
        s.NoError(err)
×
4715
        s.Equal(workflowExecutionCurrent.GetRunID(), runID1)
×
4716
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4717
        s.NoError(err)
×
4718
        currentInfo := copyWorkflowExecutionInfo(state.ExecutionInfo)
×
4719
        currentStats := copyExecutionStats(state.ExecutionStats)
×
4720
        currentInfo.State = p.WorkflowStateCompleted
×
4721
        currentInfo.CloseStatus = p.WorkflowCloseStatusCompleted
×
4722
        currentInfo.NextEventID = int64(6)
×
4723
        currentInfo.LastProcessedEvent = int64(2)
×
4724
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4725
                {
×
4726
                        EventID: currentInfo.LastProcessedEvent,
×
4727
                        Version: common.EmptyVersion,
×
4728
                },
×
4729
        })
×
4730
        versionHistories := p.NewVersionHistories(versionHistory)
×
4731
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, currentInfo, currentStats, int64(3), versionHistories)
×
4732
        s.NoError(err3)
×
4733
        runID1, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4734
        s.NoError(err)
×
4735
        s.Equal(workflowExecutionCurrent.GetRunID(), runID1)
×
4736

×
4737
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
4738
                DomainID:                    domainID,
×
4739
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
4740
                RunID:                       workflowExecutionReset.GetRunID(),
×
4741
                ParentDomainID:              uuid.New(),
×
4742
                ParentWorkflowID:            "some random parent workflow ID",
×
4743
                ParentRunID:                 uuid.New(),
×
4744
                InitiatedID:                 12345,
×
4745
                TaskList:                    "some random tasklist",
×
4746
                WorkflowTypeName:            "some random workflow type name",
×
4747
                WorkflowTimeout:             1112,
×
4748
                DecisionStartToCloseTimeout: 14,
×
4749
                State:                       p.WorkflowStateRunning,
×
4750
                LastFirstEventID:            common.FirstEventID,
×
4751
                NextEventID:                 123,
×
4752
                CreateRequestID:             uuid.New(),
×
4753
                DecisionVersion:             common.EmptyVersion,
×
4754
                DecisionScheduleID:          111,
×
4755
                DecisionStartedID:           222,
×
4756
                DecisionRequestID:           uuid.New(),
×
4757
                DecisionTimeout:             0,
×
4758
        }
×
4759
        resetStats := &p.ExecutionStats{}
×
4760
        resetActivityInfos := []*p.ActivityInfo{}
×
4761
        resetTimerInfos := []*p.TimerInfo{}
×
4762
        resetChildExecutionInfos := []*p.ChildExecutionInfo{}
×
4763
        resetRequestCancelInfos := []*p.RequestCancelInfo{}
×
4764
        resetSignalInfos := []*p.SignalInfo{}
×
4765

×
4766
        err = s.ConflictResolveWorkflowExecution(
×
4767
                ctx,
×
4768
                resetExecutionInfo,
×
4769
                resetStats,
×
4770
                continueAsNewInfo.NextEventID,
×
4771
                resetActivityInfos,
×
4772
                resetTimerInfos,
×
4773
                resetChildExecutionInfos,
×
4774
                resetRequestCancelInfos,
×
4775
                resetSignalInfos,
×
4776
                nil,
×
4777
                versionHistories,
×
4778
        )
×
4779
        s.NotNil(err)
×
4780

×
4781
        err = s.ConflictResolveWorkflowExecution(
×
4782
                ctx,
×
4783
                resetExecutionInfo,
×
4784
                resetStats,
×
4785
                continueAsNewInfo.NextEventID,
×
4786
                resetActivityInfos,
×
4787
                resetTimerInfos,
×
4788
                resetChildExecutionInfos,
×
4789
                resetRequestCancelInfos,
×
4790
                resetSignalInfos,
×
4791
                nil,
×
4792
                versionHistories,
×
4793
        )
×
4794
        s.NotNil(err)
×
4795

×
4796
        err = s.ConflictResolveWorkflowExecution(
×
4797
                ctx,
×
4798
                resetExecutionInfo,
×
4799
                resetStats,
×
4800
                continueAsNewInfo.NextEventID,
×
4801
                resetActivityInfos,
×
4802
                resetTimerInfos,
×
4803
                resetChildExecutionInfos,
×
4804
                resetRequestCancelInfos,
×
4805
                resetSignalInfos,
×
4806
                nil,
×
4807
                versionHistories,
×
4808
        )
×
4809
        s.NotNil(err)
×
4810

×
4811
        // this test only assert whether the current workflow execution record is reset
×
4812
        runID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4813
        s.NoError(err)
×
4814
        s.Equal(workflowExecutionCurrent.GetRunID(), runID)
×
4815
}
×
4816

4817
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelf test
4818
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelf() {
×
4819
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4820
        defer cancel()
×
4821

×
4822
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
4823
        workflowID := "test-reset-mutable-state-test-with-transaction-current-is-not-self"
×
4824

×
4825
        // first create a workflow and continue as new it
×
4826
        workflowExecutionReset := types.WorkflowExecution{
×
4827
                WorkflowID: workflowID,
×
4828
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4829
        }
×
4830
        nextEventID := int64(3)
×
4831
        partitionConfig := map[string]string{
×
4832
                "userid": uuid.New(),
×
4833
        }
×
4834
        resp, err := s.CreateWorkflowExecution(
×
4835
                ctx,
×
4836
                domainID,
×
4837
                workflowExecutionReset,
×
4838
                "taskList",
×
4839
                "wType",
×
4840
                20,
×
4841
                13,
×
4842
                nil,
×
4843
                nextEventID,
×
4844
                0,
×
4845
                2,
×
4846
                nil,
×
4847
                partitionConfig,
×
4848
        )
×
4849
        s.NoError(err)
×
4850
        s.NotNil(resp)
×
4851

×
4852
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4853
        s.NoError(err)
×
4854

×
4855
        info := state.ExecutionInfo
×
4856
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
4857
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
4858
        continueAsNewInfo.State = p.WorkflowStateRunning
×
4859
        continueAsNewInfo.NextEventID = int64(5)
×
4860
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
4861

×
4862
        workflowExecutionCurrent := types.WorkflowExecution{
×
4863
                WorkflowID: workflowID,
×
4864
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
4865
        }
×
4866
        err = s.ContinueAsNewExecution(
×
4867
                ctx,
×
4868
                continueAsNewInfo,
×
4869
                continueAsNewStats,
×
4870
                info.NextEventID,
×
4871
                workflowExecutionCurrent,
×
4872
                int64(3),
×
4873
                int64(2),
×
4874
                nil,
×
4875
        )
×
4876
        s.NoError(err)
×
4877

×
4878
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4879
        s.NoError(err)
×
4880
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
4881
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4882
        s.NoError(err)
×
4883
        currentInfo := copyWorkflowExecutionInfo(state.ExecutionInfo)
×
4884
        currentInfo.State = p.WorkflowStateCompleted
×
4885
        currentInfo.CloseStatus = p.WorkflowCloseStatusTerminated
×
4886

×
4887
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
4888
                DomainID:                    domainID,
×
4889
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
4890
                RunID:                       workflowExecutionReset.GetRunID(),
×
4891
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
4892
                ParentDomainID:              uuid.New(),
×
4893
                ParentWorkflowID:            "some random parent workflow ID",
×
4894
                ParentRunID:                 uuid.New(),
×
4895
                InitiatedID:                 12345,
×
4896
                TaskList:                    "some random tasklist",
×
4897
                WorkflowTypeName:            "some random workflow type name",
×
4898
                WorkflowTimeout:             1112,
×
4899
                DecisionStartToCloseTimeout: 14,
×
4900
                State:                       p.WorkflowStateCompleted,
×
4901
                CloseStatus:                 p.WorkflowCloseStatusCompleted,
×
4902
                LastFirstEventID:            common.FirstEventID,
×
4903
                NextEventID:                 123,
×
4904
                CreateRequestID:             uuid.New(),
×
4905
                DecisionVersion:             common.EmptyVersion,
×
4906
                DecisionScheduleID:          111,
×
4907
                DecisionStartedID:           222,
×
4908
                DecisionRequestID:           uuid.New(),
×
4909
                DecisionTimeout:             0,
×
4910
                AutoResetPoints:             &types.ResetPoints{},
×
4911
                PartitionConfig:             nil,
×
4912
        }
×
4913
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4914
                {
×
4915
                        EventID: resetExecutionInfo.DecisionScheduleID,
×
4916
                        Version: common.EmptyVersion,
×
4917
                },
×
4918
        })
×
4919
        versionHistories := p.NewVersionHistories(versionHistory)
×
4920

×
4921
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
4922
                RangeID: s.ShardInfo.RangeID,
×
4923
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
4924
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
4925
                        ExecutionInfo:  resetExecutionInfo,
×
4926
                        ExecutionStats: &p.ExecutionStats{},
×
4927
                        Condition:      int64(5),
×
4928

×
4929
                        ActivityInfos:       []*p.ActivityInfo{},
×
4930
                        TimerInfos:          []*p.TimerInfo{},
×
4931
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4932
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
4933
                        SignalInfos:         []*p.SignalInfo{},
×
4934
                        SignalRequestedIDs:  []string{},
×
4935
                        VersionHistories:    versionHistories,
×
4936
                },
×
4937
                NewWorkflowSnapshot: nil,
×
4938
                CurrentWorkflowMutation: &p.WorkflowMutation{
×
4939
                        ExecutionInfo:  currentInfo,
×
4940
                        ExecutionStats: &p.ExecutionStats{},
×
4941
                        Condition:      int64(3),
×
4942

×
4943
                        UpsertActivityInfos:       []*p.ActivityInfo{},
×
4944
                        UpsertTimerInfos:          []*p.TimerInfo{},
×
4945
                        UpsertChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4946
                        UpsertRequestCancelInfos:  []*p.RequestCancelInfo{},
×
4947
                        UpsertSignalInfos:         []*p.SignalInfo{},
×
4948
                        UpsertSignalRequestedIDs:  []string{},
×
4949
                        VersionHistories:          versionHistories,
×
4950
                },
×
4951
                Encoding: pickRandomEncoding(),
×
4952
        }
×
4953
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4954
        s.Error(err)
×
4955
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
4956
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4957
        s.NoError(err)
×
4958

×
4959
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
4960
                DomainID:   domainID,
×
4961
                WorkflowID: workflowID,
×
4962
        })
×
4963
        s.NoError(err)
×
4964
        s.Equal(resetExecutionInfo.RunID, currentRecord.RunID)
×
4965
        s.Equal(resetExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
4966
        s.Equal(resetExecutionInfo.State, currentRecord.State)
×
4967
        s.Equal(resetExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
4968
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
4969

×
4970
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4971
        s.NoError(err)
×
4972
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
4973
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
4974
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
4975
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
4976

×
4977
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4978
        s.NoError(err)
×
4979
        state.ExecutionInfo.StartTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.StartTimestamp
×
4980
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.LastUpdatedTimestamp
×
4981
        state.ExecutionInfo.ExpirationTime = resetReq.CurrentWorkflowMutation.ExecutionInfo.ExpirationTime
×
4982
        s.Equal(resetReq.CurrentWorkflowMutation.ExecutionInfo, state.ExecutionInfo)
×
4983
}
×
4984

4985
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelfWithContinueAsNew test
4986
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelfWithContinueAsNew() {
×
4987
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4988
        defer cancel()
×
4989

×
4990
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
4991
        workflowID := "test-reset-mutable-state-test-with-transaction-current-is-not-self-with-continue-as-new"
×
4992

×
4993
        // first create a workflow and continue as new it
×
4994
        workflowExecutionReset := types.WorkflowExecution{
×
4995
                WorkflowID: workflowID,
×
4996
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4997
        }
×
4998
        nextEventID := int64(3)
×
4999
        partitionConfig := map[string]string{
×
5000
                "userid": uuid.New(),
×
5001
        }
×
5002
        resp, err := s.CreateWorkflowExecution(
×
5003
                ctx,
×
5004
                domainID,
×
5005
                workflowExecutionReset,
×
5006
                "taskList",
×
5007
                "wType",
×
5008
                20,
×
5009
                13,
×
5010
                nil,
×
5011
                nextEventID,
×
5012
                0,
×
5013
                2,
×
5014
                nil,
×
5015
                partitionConfig,
×
5016
        )
×
5017
        s.NoError(err)
×
5018
        s.NotNil(resp)
×
5019

×
5020
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5021
        s.NoError(err)
×
5022
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
5023

×
5024
        info := state.ExecutionInfo
×
5025
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
5026
        continueAsNewInfo.State = p.WorkflowStateRunning
×
5027
        continueAsNewInfo.NextEventID = int64(5)
×
5028
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
5029

×
5030
        workflowExecutionCurrent := types.WorkflowExecution{
×
5031
                WorkflowID: workflowID,
×
5032
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
5033
        }
×
5034
        err = s.ContinueAsNewExecution(
×
5035
                ctx,
×
5036
                continueAsNewInfo,
×
5037
                continueAsNewStats,
×
5038
                info.NextEventID,
×
5039
                workflowExecutionCurrent,
×
5040
                int64(3),
×
5041
                int64(2),
×
5042
                nil,
×
5043
        )
×
5044
        s.NoError(err)
×
5045

×
5046
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
5047
        s.NoError(err)
×
5048
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
5049
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
5050
        s.NoError(err)
×
5051
        currentInfo := copyWorkflowExecutionInfo(state.ExecutionInfo)
×
5052
        currentStats := copyExecutionStats(state.ExecutionStats)
×
5053
        currentInfo.State = p.WorkflowStateCompleted
×
5054
        currentInfo.CloseStatus = p.WorkflowCloseStatusTerminated
×
5055
        decisionScheduleID := int64(111)
×
5056
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
5057
                {
×
5058
                        EventID: decisionScheduleID,
×
5059
                        Version: common.EmptyVersion,
×
5060
                },
×
5061
        })
×
5062
        versionHistories := p.NewVersionHistories(versionHistory)
×
5063

×
5064
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
5065
                DomainID:                    domainID,
×
5066
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
5067
                RunID:                       workflowExecutionReset.GetRunID(),
×
5068
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
5069
                ParentDomainID:              uuid.New(),
×
5070
                ParentWorkflowID:            "some random parent workflow ID",
×
5071
                ParentRunID:                 uuid.New(),
×
5072
                InitiatedID:                 12345,
×
5073
                TaskList:                    "some random tasklist",
×
5074
                WorkflowTypeName:            "some random workflow type name",
×
5075
                WorkflowTimeout:             1112,
×
5076
                DecisionStartToCloseTimeout: 14,
×
5077
                State:                       p.WorkflowStateCompleted,
×
5078
                CloseStatus:                 p.WorkflowCloseStatusContinuedAsNew,
×
5079
                LastFirstEventID:            common.FirstEventID,
×
5080
                NextEventID:                 123,
×
5081
                CreateRequestID:             uuid.New(),
×
5082
                DecisionVersion:             common.EmptyVersion,
×
5083
                DecisionScheduleID:          decisionScheduleID,
×
5084
                DecisionStartedID:           222,
×
5085
                DecisionRequestID:           uuid.New(),
×
5086
                DecisionTimeout:             0,
×
5087
                AutoResetPoints:             &types.ResetPoints{},
×
5088
                PartitionConfig:             map[string]string{"zone": "dca1"},
×
5089
        }
×
5090
        newWorkflowExecutionInfo := copyWorkflowExecutionInfo(resetExecutionInfo)
×
5091
        newWorkflowExecutionStats := &p.ExecutionStats{}
×
5092
        newWorkflowExecutionInfo.CreateRequestID = uuid.New()
×
5093
        newWorkflowExecutionInfo.RunID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa2"
×
5094
        newWorkflowExecutionInfo.State = p.WorkflowStateRunning
×
5095
        newWorkflowExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
5096
        newWorkflowExecutionInfo.PartitionConfig = map[string]string{"user": uuid.New()}
×
5097

×
5098
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
5099
                RangeID: s.ShardInfo.RangeID,
×
5100
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
5101
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
5102
                        ExecutionInfo:  resetExecutionInfo,
×
5103
                        ExecutionStats: &p.ExecutionStats{},
×
5104
                        Condition:      int64(5),
×
5105

×
5106
                        ActivityInfos:       []*p.ActivityInfo{},
×
5107
                        TimerInfos:          []*p.TimerInfo{},
×
5108
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5109
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5110
                        SignalInfos:         []*p.SignalInfo{},
×
5111
                        SignalRequestedIDs:  []string{},
×
5112
                        VersionHistories:    versionHistories,
×
5113
                },
×
5114
                NewWorkflowSnapshot: &p.WorkflowSnapshot{
×
5115
                        ExecutionInfo:  newWorkflowExecutionInfo,
×
5116
                        ExecutionStats: newWorkflowExecutionStats,
×
5117
                        Condition:      0,
×
5118

×
5119
                        ActivityInfos:       []*p.ActivityInfo{},
×
5120
                        TimerInfos:          []*p.TimerInfo{},
×
5121
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5122
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5123
                        SignalInfos:         []*p.SignalInfo{},
×
5124
                        SignalRequestedIDs:  []string{},
×
5125
                        VersionHistories:    versionHistories,
×
5126
                },
×
5127
                CurrentWorkflowMutation: &p.WorkflowMutation{
×
5128
                        ExecutionInfo:  currentInfo,
×
5129
                        ExecutionStats: currentStats,
×
5130
                        Condition:      int64(3),
×
5131

×
5132
                        UpsertActivityInfos:       []*p.ActivityInfo{},
×
5133
                        UpsertTimerInfos:          []*p.TimerInfo{},
×
5134
                        UpsertChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5135
                        UpsertRequestCancelInfos:  []*p.RequestCancelInfo{},
×
5136
                        UpsertSignalInfos:         []*p.SignalInfo{},
×
5137
                        UpsertSignalRequestedIDs:  []string{},
×
5138
                        VersionHistories:          versionHistories,
×
5139
                },
×
5140
                Encoding: pickRandomEncoding(),
×
5141
        }
×
5142
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5143
        s.Error(err)
×
5144
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
5145
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5146
        s.NoError(err)
×
5147

×
5148
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5149
                DomainID:   domainID,
×
5150
                WorkflowID: workflowID,
×
5151
        })
×
5152
        s.NoError(err)
×
5153
        s.Equal(newWorkflowExecutionInfo.RunID, currentRecord.RunID)
×
5154
        s.Equal(newWorkflowExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
5155
        s.Equal(newWorkflowExecutionInfo.State, currentRecord.State)
×
5156
        s.Equal(newWorkflowExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
5157
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
5158

×
5159
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5160
        s.NoError(err)
×
5161
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5162
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5163
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5164
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5165

×
5166
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
5167
        s.NoError(err)
×
5168
        state.ExecutionInfo.StartTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.StartTimestamp
×
5169
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.LastUpdatedTimestamp
×
5170
        state.ExecutionInfo.ExpirationTime = resetReq.CurrentWorkflowMutation.ExecutionInfo.ExpirationTime
×
5171
        s.Equal(resetReq.CurrentWorkflowMutation.ExecutionInfo, state.ExecutionInfo)
×
5172

×
5173
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, types.WorkflowExecution{
×
5174
                WorkflowID: workflowID,
×
5175
                RunID:      resetReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
5176
        })
×
5177
        s.NoError(err)
×
5178
        state.ExecutionInfo.StartTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5179
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5180
        state.ExecutionInfo.ExpirationTime = resetReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5181
        s.Equal(resetReq.NewWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5182
}
×
5183

5184
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelf test
5185
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelf() {
×
5186
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5187
        defer cancel()
×
5188

×
5189
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
5190
        workflowID := "test-reset-mutable-state-test-with-transaction-current-is-self"
×
5191

×
5192
        // first create a workflow and continue as new it
×
5193
        workflowExecutionReset := types.WorkflowExecution{
×
5194
                WorkflowID: workflowID,
×
5195
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
5196
        }
×
5197
        partitionConfig := map[string]string{
×
5198
                "userid": uuid.New(),
×
5199
        }
×
5200
        nextEventID := int64(3)
×
5201
        resp, err := s.CreateWorkflowExecution(
×
5202
                ctx,
×
5203
                domainID,
×
5204
                workflowExecutionReset,
×
5205
                "taskList",
×
5206
                "wType",
×
5207
                20,
×
5208
                13,
×
5209
                nil,
×
5210
                nextEventID,
×
5211
                0,
×
5212
                2,
×
5213
                nil,
×
5214
                partitionConfig,
×
5215
        )
×
5216
        s.NoError(err)
×
5217
        s.NotNil(resp)
×
5218

×
5219
        _, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5220
        s.NoError(err)
×
5221

×
5222
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
5223
                DomainID:                    domainID,
×
5224
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
5225
                RunID:                       workflowExecutionReset.GetRunID(),
×
5226
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
5227
                ParentDomainID:              uuid.New(),
×
5228
                ParentWorkflowID:            "some random parent workflow ID",
×
5229
                ParentRunID:                 uuid.New(),
×
5230
                InitiatedID:                 12345,
×
5231
                TaskList:                    "some random tasklist",
×
5232
                WorkflowTypeName:            "some random workflow type name",
×
5233
                WorkflowTimeout:             1112,
×
5234
                DecisionStartToCloseTimeout: 14,
×
5235
                State:                       p.WorkflowStateRunning,
×
5236
                CloseStatus:                 p.WorkflowCloseStatusNone,
×
5237
                LastFirstEventID:            common.FirstEventID,
×
5238
                NextEventID:                 123,
×
5239
                CreateRequestID:             uuid.New(),
×
5240
                DecisionVersion:             common.EmptyVersion,
×
5241
                DecisionScheduleID:          111,
×
5242
                DecisionStartedID:           222,
×
5243
                DecisionRequestID:           uuid.New(),
×
5244
                DecisionTimeout:             0,
×
5245
                AutoResetPoints:             &types.ResetPoints{},
×
5246
                PartitionConfig:             nil,
×
5247
        }
×
5248
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
5249
                {
×
5250
                        EventID: resetExecutionInfo.DecisionScheduleID,
×
5251
                        Version: common.EmptyVersion,
×
5252
                },
×
5253
        })
×
5254
        versionHistories := p.NewVersionHistories(versionHistory)
×
5255

×
5256
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
5257
                RangeID: s.ShardInfo.RangeID,
×
5258
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
5259
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
5260
                        ExecutionInfo:  resetExecutionInfo,
×
5261
                        ExecutionStats: &p.ExecutionStats{},
×
5262
                        Condition:      nextEventID,
×
5263

×
5264
                        ActivityInfos:       []*p.ActivityInfo{},
×
5265
                        TimerInfos:          []*p.TimerInfo{},
×
5266
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5267
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5268
                        SignalInfos:         []*p.SignalInfo{},
×
5269
                        SignalRequestedIDs:  []string{},
×
5270
                        VersionHistories:    versionHistories,
×
5271
                },
×
5272
                NewWorkflowSnapshot:     nil,
×
5273
                CurrentWorkflowMutation: nil,
×
5274
                Encoding:                pickRandomEncoding(),
×
5275
        }
×
5276
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5277
        s.Error(err)
×
5278
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
5279
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5280
        s.NoError(err)
×
5281

×
5282
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5283
                DomainID:   domainID,
×
5284
                WorkflowID: workflowID,
×
5285
        })
×
5286
        s.NoError(err)
×
5287
        s.Equal(resetExecutionInfo.RunID, currentRecord.RunID)
×
5288
        s.Equal(resetExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
5289
        s.Equal(resetExecutionInfo.State, currentRecord.State)
×
5290
        s.Equal(resetExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
5291
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
5292

×
5293
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5294
        s.NoError(err)
×
5295
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5296
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5297
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5298
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5299
}
×
5300

5301
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelfWithContinueAsNew test
5302
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelfWithContinueAsNew() {
×
5303
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5304
        defer cancel()
×
5305

×
5306
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
5307
        workflowID := "test-reset-mutable-state-test-with-transaction-current-is-self-with-continue-as-new"
×
5308

×
5309
        // first create a workflow and continue as new it
×
5310
        workflowExecutionReset := types.WorkflowExecution{
×
5311
                WorkflowID: workflowID,
×
5312
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
5313
        }
×
5314
        partitionConfig := map[string]string{
×
5315
                "userid": uuid.New(),
×
5316
        }
×
5317
        nextEventID := int64(3)
×
5318
        resp, err := s.CreateWorkflowExecution(
×
5319
                ctx,
×
5320
                domainID,
×
5321
                workflowExecutionReset,
×
5322
                "taskList",
×
5323
                "wType",
×
5324
                20,
×
5325
                13,
×
5326
                nil,
×
5327
                nextEventID,
×
5328
                0,
×
5329
                2,
×
5330
                nil,
×
5331
                partitionConfig,
×
5332
        )
×
5333
        s.NoError(err)
×
5334
        s.NotNil(resp)
×
5335

×
5336
        _, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5337
        s.NoError(err)
×
5338

×
5339
        decisionScheduleID := int64(111)
×
5340
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
5341
                {
×
5342
                        EventID: decisionScheduleID,
×
5343
                        Version: common.EmptyVersion,
×
5344
                },
×
5345
        })
×
5346
        versionHistories := p.NewVersionHistories(versionHistory)
×
5347
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
5348
                DomainID:                    domainID,
×
5349
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
5350
                RunID:                       workflowExecutionReset.GetRunID(),
×
5351
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
5352
                ParentDomainID:              uuid.New(),
×
5353
                ParentWorkflowID:            "some random parent workflow ID",
×
5354
                ParentRunID:                 uuid.New(),
×
5355
                InitiatedID:                 12345,
×
5356
                TaskList:                    "some random tasklist",
×
5357
                WorkflowTypeName:            "some random workflow type name",
×
5358
                WorkflowTimeout:             1112,
×
5359
                DecisionStartToCloseTimeout: 14,
×
5360
                State:                       p.WorkflowStateCompleted,
×
5361
                CloseStatus:                 p.WorkflowCloseStatusContinuedAsNew,
×
5362
                LastFirstEventID:            common.FirstEventID,
×
5363
                NextEventID:                 123,
×
5364
                CreateRequestID:             uuid.New(),
×
5365
                DecisionVersion:             common.EmptyVersion,
×
5366
                DecisionScheduleID:          decisionScheduleID,
×
5367
                DecisionStartedID:           222,
×
5368
                DecisionRequestID:           uuid.New(),
×
5369
                DecisionTimeout:             0,
×
5370
                AutoResetPoints:             &types.ResetPoints{},
×
5371
                PartitionConfig:             nil,
×
5372
        }
×
5373
        newWorkflowExecutionInfo := copyWorkflowExecutionInfo(resetExecutionInfo)
×
5374
        newWorkflowExecutionStats := &p.ExecutionStats{}
×
5375
        newWorkflowExecutionInfo.CreateRequestID = uuid.New()
×
5376
        newWorkflowExecutionInfo.RunID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa2"
×
5377
        newWorkflowExecutionInfo.State = p.WorkflowStateRunning
×
5378
        newWorkflowExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
5379
        newWorkflowExecutionInfo.PartitionConfig = map[string]string{"zone": "dca1"}
×
5380

×
5381
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
5382
                RangeID: s.ShardInfo.RangeID,
×
5383
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
5384
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
5385
                        ExecutionInfo:  resetExecutionInfo,
×
5386
                        ExecutionStats: &p.ExecutionStats{},
×
5387
                        Condition:      nextEventID,
×
5388

×
5389
                        ActivityInfos:       []*p.ActivityInfo{},
×
5390
                        TimerInfos:          []*p.TimerInfo{},
×
5391
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5392
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5393
                        SignalInfos:         []*p.SignalInfo{},
×
5394
                        SignalRequestedIDs:  []string{},
×
5395
                        VersionHistories:    versionHistories,
×
5396
                },
×
5397
                NewWorkflowSnapshot: &p.WorkflowSnapshot{
×
5398
                        ExecutionInfo:  newWorkflowExecutionInfo,
×
5399
                        ExecutionStats: newWorkflowExecutionStats,
×
5400
                        Condition:      0,
×
5401

×
5402
                        ActivityInfos:       []*p.ActivityInfo{},
×
5403
                        TimerInfos:          []*p.TimerInfo{},
×
5404
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5405
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5406
                        SignalInfos:         []*p.SignalInfo{},
×
5407
                        SignalRequestedIDs:  []string{},
×
5408
                        VersionHistories:    versionHistories,
×
5409
                },
×
5410
                CurrentWorkflowMutation: nil,
×
5411
                Encoding:                pickRandomEncoding(),
×
5412
        }
×
5413
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5414
        s.Error(err)
×
5415
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
5416
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5417
        s.NoError(err)
×
5418

×
5419
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5420
                DomainID:   domainID,
×
5421
                WorkflowID: workflowID,
×
5422
        })
×
5423
        s.NoError(err)
×
5424
        s.Equal(newWorkflowExecutionInfo.RunID, currentRecord.RunID)
×
5425
        s.Equal(newWorkflowExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
5426
        s.Equal(newWorkflowExecutionInfo.State, currentRecord.State)
×
5427
        s.Equal(newWorkflowExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
5428
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
5429

×
5430
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5431
        s.NoError(err)
×
5432
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5433
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5434
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5435
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5436
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, types.WorkflowExecution{
×
5437
                WorkflowID: workflowID,
×
5438
                RunID:      resetReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
5439
        })
×
5440
        s.NoError(err)
×
5441
        state.ExecutionInfo.StartTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5442
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5443
        state.ExecutionInfo.ExpirationTime = resetReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5444
        s.Equal(resetReq.NewWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5445
}
×
5446

5447
// TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelf test
5448
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelf() {
×
5449
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5450
        defer cancel()
×
5451

×
5452
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
5453
        workflowID := "test-reset-mutable-state-test-with-transaction-current-is-zombie"
×
5454

×
5455
        // first create a workflow and continue as new it
×
5456
        workflowExecutionReset := types.WorkflowExecution{
×
5457
                WorkflowID: workflowID,
×
5458
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
5459
        }
×
5460
        partitionConfig := map[string]string{
×
5461
                "userid": uuid.New(),
×
5462
        }
×
5463
        nextEventID := int64(3)
×
5464
        resp, err := s.CreateWorkflowExecution(
×
5465
                ctx,
×
5466
                domainID,
×
5467
                workflowExecutionReset,
×
5468
                "taskList",
×
5469
                "wType",
×
5470
                20,
×
5471
                13,
×
5472
                nil,
×
5473
                nextEventID,
×
5474
                0,
×
5475
                2,
×
5476
                nil,
×
5477
                partitionConfig,
×
5478
        )
×
5479
        s.NoError(err)
×
5480
        s.NotNil(resp)
×
5481

×
5482
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5483
        s.NoError(err)
×
5484

×
5485
        info := state.ExecutionInfo
×
5486
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
5487
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
5488
        continueAsNewInfo.State = p.WorkflowStateRunning
×
5489
        continueAsNewInfo.NextEventID = int64(5)
×
5490
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
5491

×
5492
        workflowExecutionCurrent := types.WorkflowExecution{
×
5493
                WorkflowID: workflowID,
×
5494
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
5495
        }
×
5496
        err = s.ContinueAsNewExecution(
×
5497
                ctx,
×
5498
                continueAsNewInfo,
×
5499
                continueAsNewStats,
×
5500
                info.NextEventID,
×
5501
                workflowExecutionCurrent,
×
5502
                int64(3),
×
5503
                int64(2),
×
5504
                nil,
×
5505
        )
×
5506
        s.NoError(err)
×
5507

×
5508
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
5509
        s.NoError(err)
×
5510
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
5511

×
5512
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
5513
                DomainID:                    domainID,
×
5514
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
5515
                RunID:                       workflowExecutionReset.GetRunID(),
×
5516
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
5517
                ParentDomainID:              uuid.New(),
×
5518
                ParentWorkflowID:            "some random parent workflow ID",
×
5519
                ParentRunID:                 uuid.New(),
×
5520
                InitiatedID:                 12345,
×
5521
                TaskList:                    "some random tasklist",
×
5522
                WorkflowTypeName:            "some random workflow type name",
×
5523
                WorkflowTimeout:             1112,
×
5524
                DecisionStartToCloseTimeout: 14,
×
5525
                State:                       p.WorkflowStateCompleted,
×
5526
                CloseStatus:                 p.WorkflowCloseStatusCompleted,
×
5527
                LastFirstEventID:            common.FirstEventID,
×
5528
                NextEventID:                 123,
×
5529
                CreateRequestID:             uuid.New(),
×
5530
                DecisionVersion:             common.EmptyVersion,
×
5531
                DecisionScheduleID:          111,
×
5532
                DecisionStartedID:           222,
×
5533
                DecisionRequestID:           uuid.New(),
×
5534
                DecisionTimeout:             0,
×
5535
                AutoResetPoints:             &types.ResetPoints{},
×
5536
                PartitionConfig:             nil,
×
5537
        }
×
5538
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
5539
                {
×
5540
                        EventID: resetExecutionInfo.DecisionScheduleID,
×
5541
                        Version: common.EmptyVersion,
×
5542
                },
×
5543
        })
×
5544
        versionHistories := p.NewVersionHistories(versionHistory)
×
5545

×
5546
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
5547
                RangeID: s.ShardInfo.RangeID,
×
5548
                Mode:    p.ConflictResolveWorkflowModeUpdateCurrent,
×
5549
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
5550
                        ExecutionInfo:  resetExecutionInfo,
×
5551
                        ExecutionStats: &p.ExecutionStats{},
×
5552
                        Condition:      int64(5),
×
5553

×
5554
                        ActivityInfos:       []*p.ActivityInfo{},
×
5555
                        TimerInfos:          []*p.TimerInfo{},
×
5556
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5557
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5558
                        SignalInfos:         []*p.SignalInfo{},
×
5559
                        SignalRequestedIDs:  []string{},
×
5560
                        VersionHistories:    versionHistories,
×
5561
                },
×
5562
                NewWorkflowSnapshot:     nil,
×
5563
                CurrentWorkflowMutation: nil,
×
5564
                Encoding:                pickRandomEncoding(),
×
5565
        }
×
5566
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5567
        s.Error(err)
×
5568
        resetReq.Mode = p.ConflictResolveWorkflowModeBypassCurrent
×
5569
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5570
        s.NoError(err)
×
5571

×
5572
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5573
                DomainID:   domainID,
×
5574
                WorkflowID: workflowID,
×
5575
        })
×
5576
        s.NoError(err)
×
5577
        s.Equal(currentRunID, currentRecord.RunID)
×
5578

×
5579
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5580
        s.NoError(err)
×
5581
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5582
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5583
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5584
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5585
}
×
5586

5587
// TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelfWithContinueAsNew test
5588
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelfWithContinueAsNew() {
×
5589
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5590
        defer cancel()
×
5591

×
5592
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
5593
        workflowID := "test-reset-mutable-state-test-with-transaction-current-is-zombie-with-continue-as-new"
×
5594

×
5595
        // first create a workflow and continue as new it
×
5596
        workflowExecutionReset := types.WorkflowExecution{
×
5597
                WorkflowID: workflowID,
×
5598
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
5599
        }
×
5600
        partitionConfig := map[string]string{
×
5601
                "userid": uuid.New(),
×
5602
        }
×
5603
        nextEventID := int64(3)
×
5604
        resp, err := s.CreateWorkflowExecution(
×
5605
                ctx,
×
5606
                domainID,
×
5607
                workflowExecutionReset,
×
5608
                "taskList",
×
5609
                "wType",
×
5610
                20,
×
5611
                13,
×
5612
                nil,
×
5613
                nextEventID,
×
5614
                0,
×
5615
                2,
×
5616
                nil,
×
5617
                partitionConfig,
×
5618
        )
×
5619
        s.NoError(err)
×
5620
        s.NotNil(resp)
×
5621

×
5622
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5623
        s.NoError(err)
×
5624
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
5625

×
5626
        info := state.ExecutionInfo
×
5627
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
5628
        continueAsNewInfo.State = p.WorkflowStateRunning
×
5629
        continueAsNewInfo.NextEventID = int64(5)
×
5630
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
5631

×
5632
        workflowExecutionCurrent := types.WorkflowExecution{
×
5633
                WorkflowID: workflowID,
×
5634
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
5635
        }
×
5636
        err = s.ContinueAsNewExecution(
×
5637
                ctx,
×
5638
                continueAsNewInfo,
×
5639
                continueAsNewStats,
×
5640
                info.NextEventID,
×
5641
                workflowExecutionCurrent,
×
5642
                int64(3),
×
5643
                int64(2),
×
5644
                nil,
×
5645
        )
×
5646
        s.NoError(err)
×
5647

×
5648
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
5649
        s.NoError(err)
×
5650
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
5651

×
5652
        decisionScheduleID := int64(111)
×
5653
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
5654
                {
×
5655
                        EventID: decisionScheduleID,
×
5656
                        Version: common.EmptyVersion,
×
5657
                },
×
5658
        })
×
5659
        versionHistories := p.NewVersionHistories(versionHistory)
×
5660
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
5661
                DomainID:                    domainID,
×
5662
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
5663
                RunID:                       workflowExecutionReset.GetRunID(),
×
5664
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
5665
                ParentDomainID:              uuid.New(),
×
5666
                ParentWorkflowID:            "some random parent workflow ID",
×
5667
                ParentRunID:                 uuid.New(),
×
5668
                InitiatedID:                 12345,
×
5669
                TaskList:                    "some random tasklist",
×
5670
                WorkflowTypeName:            "some random workflow type name",
×
5671
                WorkflowTimeout:             1112,
×
5672
                DecisionStartToCloseTimeout: 14,
×
5673
                State:                       p.WorkflowStateCompleted,
×
5674
                CloseStatus:                 p.WorkflowCloseStatusContinuedAsNew,
×
5675
                LastFirstEventID:            common.FirstEventID,
×
5676
                NextEventID:                 123,
×
5677
                CreateRequestID:             uuid.New(),
×
5678
                DecisionVersion:             common.EmptyVersion,
×
5679
                DecisionScheduleID:          decisionScheduleID,
×
5680
                DecisionStartedID:           222,
×
5681
                DecisionRequestID:           uuid.New(),
×
5682
                DecisionTimeout:             0,
×
5683
                AutoResetPoints:             &types.ResetPoints{},
×
5684
                PartitionConfig:             nil,
×
5685
        }
×
5686
        newWorkflowExecutionInfo := copyWorkflowExecutionInfo(resetExecutionInfo)
×
5687
        newWorkflowExecutionStats := &p.ExecutionStats{}
×
5688
        newWorkflowExecutionInfo.CreateRequestID = uuid.New()
×
5689
        newWorkflowExecutionInfo.RunID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa2"
×
5690
        newWorkflowExecutionInfo.State = p.WorkflowStateZombie
×
5691
        newWorkflowExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
5692
        newWorkflowExecutionInfo.PartitionConfig = map[string]string{"zone": "dca1"}
×
5693
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
5694
                RangeID: s.ShardInfo.RangeID,
×
5695
                Mode:    p.ConflictResolveWorkflowModeUpdateCurrent,
×
5696
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
5697
                        ExecutionInfo:  resetExecutionInfo,
×
5698
                        ExecutionStats: &p.ExecutionStats{},
×
5699
                        Condition:      int64(5),
×
5700

×
5701
                        ActivityInfos:       []*p.ActivityInfo{},
×
5702
                        TimerInfos:          []*p.TimerInfo{},
×
5703
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5704
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5705
                        SignalInfos:         []*p.SignalInfo{},
×
5706
                        SignalRequestedIDs:  []string{},
×
5707
                        VersionHistories:    versionHistories,
×
5708
                },
×
5709
                NewWorkflowSnapshot: &p.WorkflowSnapshot{
×
5710
                        ExecutionInfo:  newWorkflowExecutionInfo,
×
5711
                        ExecutionStats: newWorkflowExecutionStats,
×
5712
                        Condition:      0,
×
5713

×
5714
                        ActivityInfos:       []*p.ActivityInfo{},
×
5715
                        TimerInfos:          []*p.TimerInfo{},
×
5716
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5717
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5718
                        SignalInfos:         []*p.SignalInfo{},
×
5719
                        SignalRequestedIDs:  []string{},
×
5720
                        VersionHistories:    versionHistories,
×
5721
                },
×
5722
                CurrentWorkflowMutation: nil,
×
5723
                Encoding:                pickRandomEncoding(),
×
5724
        }
×
5725
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5726
        s.Error(err)
×
5727
        resetReq.Mode = p.ConflictResolveWorkflowModeBypassCurrent
×
5728
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5729
        s.NoError(err)
×
5730

×
5731
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5732
                DomainID:   domainID,
×
5733
                WorkflowID: workflowID,
×
5734
        })
×
5735
        s.NoError(err)
×
5736
        s.Equal(currentRunID, currentRecord.RunID)
×
5737

×
5738
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5739
        s.NoError(err)
×
5740
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5741
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5742
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5743
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5744

×
5745
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, types.WorkflowExecution{
×
5746
                WorkflowID: workflowID,
×
5747
                RunID:      resetReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
5748
        })
×
5749
        s.NoError(err)
×
5750
        state.ExecutionInfo.StartTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5751
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5752
        state.ExecutionInfo.ExpirationTime = resetReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5753
        s.Equal(resetReq.NewWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5754
}
×
5755

5756
// TestReplicationDLQ test
5757
func (s *ExecutionManagerSuite) TestReplicationDLQ() {
×
5758
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5759
        defer cancel()
×
5760

×
5761
        sourceCluster := "test"
×
5762
        taskInfo := &p.ReplicationTaskInfo{
×
5763
                DomainID:   uuid.New(),
×
5764
                WorkflowID: uuid.New(),
×
5765
                RunID:      uuid.New(),
×
5766
                TaskID:     0,
×
5767
                TaskType:   0,
×
5768
        }
×
5769
        err := s.PutReplicationTaskToDLQ(ctx, sourceCluster, taskInfo)
×
5770
        s.NoError(err)
×
5771
        resp, err := s.GetReplicationTasksFromDLQ(ctx, sourceCluster, -1, 0, 1, nil)
×
5772
        s.NoError(err)
×
5773
        s.Len(resp.Tasks, 1)
×
5774
        err = s.DeleteReplicationTaskFromDLQ(ctx, sourceCluster, 0)
×
5775
        s.NoError(err)
×
5776
        resp, err = s.GetReplicationTasksFromDLQ(ctx, sourceCluster, -1, 0, 1, nil)
×
5777
        s.NoError(err)
×
5778
        s.Len(resp.Tasks, 0)
×
5779

×
5780
        taskInfo1 := &p.ReplicationTaskInfo{
×
5781
                DomainID:   uuid.New(),
×
5782
                WorkflowID: uuid.New(),
×
5783
                RunID:      uuid.New(),
×
5784
                TaskID:     1,
×
5785
                TaskType:   0,
×
5786
        }
×
5787
        taskInfo2 := &p.ReplicationTaskInfo{
×
5788
                DomainID:   uuid.New(),
×
5789
                WorkflowID: uuid.New(),
×
5790
                RunID:      uuid.New(),
×
5791
                TaskID:     2,
×
5792
                TaskType:   0,
×
5793
        }
×
5794
        err = s.PutReplicationTaskToDLQ(ctx, sourceCluster, taskInfo1)
×
5795
        s.NoError(err)
×
5796
        err = s.PutReplicationTaskToDLQ(ctx, sourceCluster, taskInfo2)
×
5797
        s.NoError(err)
×
5798
        resp, err = s.GetReplicationTasksFromDLQ(ctx, sourceCluster, 0, 2, 2, nil)
×
5799
        s.NoError(err)
×
5800
        s.Len(resp.Tasks, 2)
×
5801
        sizeResp, err := s.GetReplicationDLQSize(ctx, sourceCluster)
×
5802
        s.NoError(err)
×
5803
        s.Equal(int64(2), sizeResp.Size)
×
5804
        err = s.RangeDeleteReplicationTaskFromDLQ(ctx, sourceCluster, 0, 2)
×
5805
        s.NoError(err)
×
5806
        resp, err = s.GetReplicationTasksFromDLQ(ctx, sourceCluster, 0, 2, 2, nil)
×
5807
        s.NoError(err)
×
5808
        s.Len(resp.Tasks, 0)
×
5809
}
×
5810

5811
// TestCreateFailoverMarkerTasks test
5812
func (s *ExecutionManagerSuite) TestCreateFailoverMarkerTasks() {
×
5813
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5814
        defer cancel()
×
5815

×
5816
        domainID := uuid.New()
×
5817
        markers := []*p.FailoverMarkerTask{
×
5818
                {
×
5819
                        TaskData: p.TaskData{
×
5820
                                TaskID:              1,
×
5821
                                VisibilityTimestamp: time.Now(),
×
5822
                                Version:             1,
×
5823
                        },
×
5824
                        DomainID: domainID,
×
5825
                },
×
5826
        }
×
5827
        err := s.CreateFailoverMarkers(ctx, markers)
×
5828
        s.NoError(err)
×
5829

×
5830
        tasks, err := s.GetReplicationTasks(ctx, 1, true)
×
5831
        s.NoError(err)
×
5832
        s.Equal(len(tasks), 1)
×
5833
        s.Equal(tasks[0].Version, int64(1))
×
5834
        s.Equal(tasks[0].TaskID, int64(1))
×
5835
        s.Equal(tasks[0].DomainID, domainID)
×
5836
        s.Equal(tasks[0].TaskType, p.ReplicationTaskTypeFailoverMarker)
×
5837
}
×
5838

5839
func copyWorkflowExecutionInfo(sourceInfo *p.WorkflowExecutionInfo) *p.WorkflowExecutionInfo {
×
5840
        return &p.WorkflowExecutionInfo{
×
5841
                DomainID:                    sourceInfo.DomainID,
×
5842
                WorkflowID:                  sourceInfo.WorkflowID,
×
5843
                RunID:                       sourceInfo.RunID,
×
5844
                FirstExecutionRunID:         sourceInfo.FirstExecutionRunID,
×
5845
                ParentDomainID:              sourceInfo.ParentDomainID,
×
5846
                ParentWorkflowID:            sourceInfo.ParentWorkflowID,
×
5847
                ParentRunID:                 sourceInfo.ParentRunID,
×
5848
                InitiatedID:                 sourceInfo.InitiatedID,
×
5849
                CompletionEvent:             sourceInfo.CompletionEvent,
×
5850
                TaskList:                    sourceInfo.TaskList,
×
5851
                WorkflowTypeName:            sourceInfo.WorkflowTypeName,
×
5852
                WorkflowTimeout:             sourceInfo.WorkflowTimeout,
×
5853
                DecisionStartToCloseTimeout: sourceInfo.DecisionStartToCloseTimeout,
×
5854
                ExecutionContext:            sourceInfo.ExecutionContext,
×
5855
                State:                       sourceInfo.State,
×
5856
                CloseStatus:                 sourceInfo.CloseStatus,
×
5857
                LastFirstEventID:            sourceInfo.LastFirstEventID,
×
5858
                NextEventID:                 sourceInfo.NextEventID,
×
5859
                LastProcessedEvent:          sourceInfo.LastProcessedEvent,
×
5860
                LastUpdatedTimestamp:        sourceInfo.LastUpdatedTimestamp,
×
5861
                StartTimestamp:              sourceInfo.StartTimestamp,
×
5862
                CreateRequestID:             sourceInfo.CreateRequestID,
×
5863
                DecisionVersion:             sourceInfo.DecisionVersion,
×
5864
                DecisionScheduleID:          sourceInfo.DecisionScheduleID,
×
5865
                DecisionStartedID:           sourceInfo.DecisionStartedID,
×
5866
                DecisionRequestID:           sourceInfo.DecisionRequestID,
×
5867
                DecisionTimeout:             sourceInfo.DecisionTimeout,
×
5868
                BranchToken:                 sourceInfo.BranchToken,
×
5869
                AutoResetPoints:             sourceInfo.AutoResetPoints,
×
5870
                PartitionConfig:             sourceInfo.PartitionConfig,
×
5871
        }
×
5872
}
×
5873

5874
func copyExecutionStats(sourceStats *p.ExecutionStats) *p.ExecutionStats {
×
5875
        return &p.ExecutionStats{
×
5876
                HistorySize: sourceStats.HistorySize,
×
5877
        }
×
5878
}
×
5879

5880
// Note: cassandra only provide millisecond precision timestamp
5881
// ref: https://docs.datastax.com/en/cql/3.3/cql/cql_reference/timestamp_type_r.html
5882
// so to use equal function, we need to do conversion, getting rid of sub milliseconds
5883
func timestampConvertor(t time.Time) time.Time {
×
5884
        return time.Unix(
×
5885
                0,
×
5886
                p.DBTimestampToUnixNano(p.UnixNanoToDBTimestamp(t.UnixNano())),
×
5887
        ).UTC()
×
5888
}
×
5889

5890
func timeComparator(t1, t2 time.Time, timeTolerance time.Duration) bool {
×
5891
        diff := t2.Sub(t1)
×
5892
        return diff.Nanoseconds() <= timeTolerance.Nanoseconds()
×
5893
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc