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

uber / cadence / 0187fc45-1fa7-4f9b-9c10-2aef2ebb54e0

08 May 2023 05:10PM UTC coverage: 57.153% (-0.07%) from 57.225%
0187fc45-1fa7-4f9b-9c10-2aef2ebb54e0

push

buildkite

GitHub
Update persistence layer to adopt idl update for isolation (#5254)

204 of 204 new or added lines in 15 files covered. (100.0%)

85781 of 150089 relevant lines covered (57.15%)

2419.35 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
        "math"
29
        "math/rand"
30
        "os"
31
        "sync"
32
        "sync/atomic"
33
        "testing"
34
        "time"
35

36
        "github.com/pborman/uuid"
37
        log "github.com/sirupsen/logrus"
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
        if !actual.Flavor.IsValid() {
×
96
                // not all stores support checksum persistence today
×
97
                // if its not supported, assert that everything is zero'd out
×
98
                expected = checksum.Checksum{}
×
99
        }
×
100
        s.EqualValues(expected, actual)
×
101
}
102

103
// TestCreateWorkflowExecutionDeDup test
104
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionDeDup() {
×
105
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
106
        defer cancel()
×
107

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

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

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

×
179
        req.Mode = p.CreateWorkflowModeWorkflowIDReuse
×
180
        req.PreviousRunID = runID
×
181
        req.PreviousLastWriteVersion = common.EmptyVersion
×
182
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
183
        s.Error(err)
×
184
        s.IsType(&p.WorkflowExecutionAlreadyStartedError{}, err)
×
185
}
×
186

187
// TestCreateWorkflowExecutionStateCloseStatus test
188
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionStateCloseStatus() {
×
189
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
190
        defer cancel()
×
191

×
192
        domainID := uuid.New()
×
193
        invalidCloseStatuses := []int{
×
194
                p.WorkflowCloseStatusCompleted,
×
195
                p.WorkflowCloseStatusFailed,
×
196
                p.WorkflowCloseStatusCanceled,
×
197
                p.WorkflowCloseStatusTerminated,
×
198
                p.WorkflowCloseStatusContinuedAsNew,
×
199
                p.WorkflowCloseStatusTimedOut,
×
200
        }
×
201
        tasklist := "some random tasklist"
×
202
        workflowType := "some random workflow type"
×
203
        workflowTimeout := int32(10)
×
204
        decisionTimeout := int32(14)
×
205
        lastProcessedEventID := int64(0)
×
206
        nextEventID := int64(3)
×
207
        csum := s.newRandomChecksum()
×
208
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
209
                {
×
210
                        EventID: nextEventID,
×
211
                        Version: common.EmptyVersion,
×
212
                },
×
213
        })
×
214
        versionHistories := p.NewVersionHistories(versionHistory)
×
215

×
216
        req := &p.CreateWorkflowExecutionRequest{
×
217
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
218
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
219
                                CreateRequestID:             uuid.New(),
×
220
                                DomainID:                    domainID,
×
221
                                TaskList:                    tasklist,
×
222
                                WorkflowTypeName:            workflowType,
×
223
                                WorkflowTimeout:             workflowTimeout,
×
224
                                DecisionStartToCloseTimeout: decisionTimeout,
×
225
                                LastFirstEventID:            common.FirstEventID,
×
226
                                NextEventID:                 nextEventID,
×
227
                                LastProcessedEvent:          lastProcessedEventID,
×
228
                        },
×
229
                        ExecutionStats:   &p.ExecutionStats{},
×
230
                        Checksum:         csum,
×
231
                        VersionHistories: versionHistories,
×
232
                },
×
233
                RangeID: s.ShardInfo.RangeID,
×
234
                Mode:    p.CreateWorkflowModeBrandNew,
×
235
        }
×
236

×
237
        workflowExecutionStatusCreated := types.WorkflowExecution{
×
238
                WorkflowID: "create-workflow-test-state-created",
×
239
                RunID:      uuid.New(),
×
240
        }
×
241
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusCreated.GetWorkflowID()
×
242
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusCreated.GetRunID()
×
243
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusCreated.GetRunID()
×
244
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateCreated
×
245
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
246
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
247
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
248
                s.IsType(&types.InternalServiceError{}, err)
×
249
        }
×
250
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
251
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
252
        s.Nil(err)
×
253
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionStatusCreated)
×
254
        s.Nil(err)
×
255
        s.Equal(p.WorkflowStateCreated, info.ExecutionInfo.State)
×
256
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
257
        s.assertChecksumsEqual(csum, info.Checksum)
×
258

×
259
        workflowExecutionStatusRunning := types.WorkflowExecution{
×
260
                WorkflowID: "create-workflow-test-state-running",
×
261
                RunID:      uuid.New(),
×
262
        }
×
263
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusRunning.GetWorkflowID()
×
264
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusRunning.GetRunID()
×
265
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusRunning.GetRunID()
×
266
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
267
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
268
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
269
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
270
                s.IsType(&types.InternalServiceError{}, err)
×
271
        }
×
272
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
273
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
274
        s.Nil(err)
×
275
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionStatusRunning)
×
276
        s.Nil(err)
×
277
        s.Equal(p.WorkflowStateRunning, info.ExecutionInfo.State)
×
278
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
279
        s.assertChecksumsEqual(csum, info.Checksum)
×
280

×
281
        workflowExecutionStatusCompleted := types.WorkflowExecution{
×
282
                WorkflowID: "create-workflow-test-state-completed",
×
283
                RunID:      uuid.New(),
×
284
        }
×
285
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusCompleted.GetWorkflowID()
×
286
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusCompleted.GetRunID()
×
287
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusCompleted.GetRunID()
×
288
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateCompleted
×
289
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
290
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
291
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
292
                s.IsType(&types.InternalServiceError{}, err)
×
293
        }
×
294
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
295
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
296
        s.IsType(&types.InternalServiceError{}, err)
×
297

×
298
        // for zombie workflow creation, we must use existing workflow ID which got created
×
299
        // since we do not allow creation of zombie workflow without current record
×
300
        workflowExecutionStatusZombie := types.WorkflowExecution{
×
301
                WorkflowID: workflowExecutionStatusRunning.WorkflowID,
×
302
                RunID:      uuid.New(),
×
303
        }
×
304
        req.Mode = p.CreateWorkflowModeZombie
×
305
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionStatusZombie.GetWorkflowID()
×
306
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionStatusZombie.GetRunID()
×
307
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionStatusZombie.GetRunID()
×
308
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateZombie
×
309
        for _, invalidCloseStatus := range invalidCloseStatuses {
×
310
                req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = invalidCloseStatus
×
311
                _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
312
                s.IsType(&types.InternalServiceError{}, err)
×
313
        }
×
314
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
315
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
316
        s.Nil(err)
×
317
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionStatusZombie)
×
318
        s.Nil(err)
×
319
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
320
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
321
        s.assertChecksumsEqual(csum, info.Checksum)
×
322
}
323

324
// TestCreateWorkflowExecutionWithZombieState test
325
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionWithZombieState() {
×
326
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
327
        defer cancel()
×
328

×
329
        domainID := uuid.New()
×
330
        workflowID := "create-workflow-test-with-zombie-state"
×
331
        workflowExecutionZombie1 := types.WorkflowExecution{
×
332
                WorkflowID: workflowID,
×
333
                RunID:      uuid.New(),
×
334
        }
×
335
        tasklist := "some random tasklist"
×
336
        workflowType := "some random workflow type"
×
337
        workflowTimeout := int32(10)
×
338
        decisionTimeout := int32(14)
×
339
        lastProcessedEventID := int64(0)
×
340
        nextEventID := int64(3)
×
341
        csum := s.newRandomChecksum()
×
342
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
343
                {
×
344
                        EventID: nextEventID,
×
345
                        Version: common.EmptyVersion,
×
346
                },
×
347
        })
×
348
        versionHistories := p.NewVersionHistories(versionHistory)
×
349

×
350
        req := &p.CreateWorkflowExecutionRequest{
×
351
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
352
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
353
                                CreateRequestID:             uuid.New(),
×
354
                                DomainID:                    domainID,
×
355
                                WorkflowID:                  workflowID,
×
356
                                RunID:                       workflowExecutionZombie1.GetRunID(),
×
357
                                FirstExecutionRunID:         workflowExecutionZombie1.GetRunID(),
×
358
                                TaskList:                    tasklist,
×
359
                                WorkflowTypeName:            workflowType,
×
360
                                WorkflowTimeout:             workflowTimeout,
×
361
                                DecisionStartToCloseTimeout: decisionTimeout,
×
362
                                NextEventID:                 nextEventID,
×
363
                                LastProcessedEvent:          lastProcessedEventID,
×
364
                                State:                       p.WorkflowStateZombie,
×
365
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
366
                        },
×
367
                        ExecutionStats:   &p.ExecutionStats{},
×
368
                        Checksum:         csum,
×
369
                        VersionHistories: versionHistories,
×
370
                },
×
371
                RangeID: s.ShardInfo.RangeID,
×
372
                Mode:    p.CreateWorkflowModeZombie,
×
373
        }
×
374
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
375
        s.Nil(err) // allow creating a zombie workflow if no current running workflow
×
376
        _, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
377
        s.IsType(&types.EntityNotExistsError{}, err) // no current workflow
×
378

×
379
        workflowExecutionRunning := types.WorkflowExecution{
×
380
                WorkflowID: workflowID,
×
381
                RunID:      uuid.New(),
×
382
        }
×
383
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionRunning.GetRunID()
×
384
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionRunning.GetRunID()
×
385
        req.Mode = p.CreateWorkflowModeBrandNew
×
386
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
387
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
388
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
389
        s.Nil(err)
×
390
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
391
        s.Nil(err)
×
392
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
393

×
394
        workflowExecutionZombie := types.WorkflowExecution{
×
395
                WorkflowID: workflowID,
×
396
                RunID:      uuid.New(),
×
397
        }
×
398
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionZombie.GetRunID()
×
399
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionZombie.GetRunID()
×
400
        req.Mode = p.CreateWorkflowModeZombie
×
401
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateZombie
×
402
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
403
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
404
        s.Nil(err)
×
405
        // current run ID is still the prev running run ID
×
406
        currentRunID, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecutionRunning.GetWorkflowID())
×
407
        s.Nil(err)
×
408
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
409
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionZombie)
×
410
        s.Nil(err)
×
411
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
412
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
413
        s.assertChecksumsEqual(csum, info.Checksum)
×
414
}
×
415

416
// TestUpdateWorkflowExecutionStateCloseStatus test
417
func (s *ExecutionManagerSuite) TestUpdateWorkflowExecutionStateCloseStatus() {
×
418
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
419
        defer cancel()
×
420

×
421
        domainID := uuid.New()
×
422
        workflowExecution := types.WorkflowExecution{
×
423
                WorkflowID: "update-workflow-test-state",
×
424
                RunID:      uuid.New(),
×
425
        }
×
426
        closeStatuses := []int{
×
427
                p.WorkflowCloseStatusCompleted,
×
428
                p.WorkflowCloseStatusFailed,
×
429
                p.WorkflowCloseStatusCanceled,
×
430
                p.WorkflowCloseStatusTerminated,
×
431
                p.WorkflowCloseStatusContinuedAsNew,
×
432
                p.WorkflowCloseStatusTimedOut,
×
433
        }
×
434
        tasklist := "some random tasklist"
×
435
        workflowType := "some random workflow type"
×
436
        workflowTimeout := int32(10)
×
437
        decisionTimeout := int32(14)
×
438
        lastProcessedEventID := int64(0)
×
439
        nextEventID := int64(3)
×
440
        csum := s.newRandomChecksum()
×
441
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
442
                {
×
443
                        EventID: nextEventID,
×
444
                        Version: common.EmptyVersion,
×
445
                },
×
446
        })
×
447
        versionHistories := p.NewVersionHistories(versionHistory)
×
448

×
449
        req := &p.CreateWorkflowExecutionRequest{
×
450
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
451
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
452
                                CreateRequestID:             uuid.New(),
×
453
                                DomainID:                    domainID,
×
454
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
455
                                RunID:                       workflowExecution.GetRunID(),
×
456
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
457
                                TaskList:                    tasklist,
×
458
                                WorkflowTypeName:            workflowType,
×
459
                                WorkflowTimeout:             workflowTimeout,
×
460
                                DecisionStartToCloseTimeout: decisionTimeout,
×
461
                                LastFirstEventID:            common.FirstEventID,
×
462
                                NextEventID:                 nextEventID,
×
463
                                LastProcessedEvent:          lastProcessedEventID,
×
464
                        },
×
465
                        ExecutionStats:   &p.ExecutionStats{},
×
466
                        Checksum:         csum,
×
467
                        VersionHistories: versionHistories,
×
468
                },
×
469
                RangeID: s.ShardInfo.RangeID,
×
470
                Mode:    p.CreateWorkflowModeBrandNew,
×
471
        }
×
472

×
473
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateCreated
×
474
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
475
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
476
        s.Nil(err)
×
477
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
478
        s.Nil(err)
×
479
        s.Equal(p.WorkflowStateCreated, info.ExecutionInfo.State)
×
480
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
481
        s.assertChecksumsEqual(csum, info.Checksum)
×
482

×
483
        csum = s.newRandomChecksum() // update the checksum to new value
×
484
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
485
        updatedStats := copyExecutionStats(info.ExecutionStats)
×
486
        updatedInfo.State = p.WorkflowStateRunning
×
487
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
488
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
489
                UpdateWorkflowMutation: p.WorkflowMutation{
×
490
                        ExecutionInfo:    updatedInfo,
×
491
                        ExecutionStats:   updatedStats,
×
492
                        Condition:        nextEventID,
×
493
                        Checksum:         csum,
×
494
                        VersionHistories: versionHistories,
×
495
                },
×
496
                RangeID: s.ShardInfo.RangeID,
×
497
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
498
        })
×
499
        s.NoError(err)
×
500
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
501
        s.Nil(err)
×
502
        s.Equal(p.WorkflowStateRunning, info.ExecutionInfo.State)
×
503
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
504
        s.assertChecksumsEqual(csum, info.Checksum)
×
505

×
506
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
507
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
508
        updatedInfo.State = p.WorkflowStateRunning
×
509
        for _, closeStatus := range closeStatuses {
×
510
                updatedInfo.CloseStatus = closeStatus
×
511
                _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
512
                        UpdateWorkflowMutation: p.WorkflowMutation{
×
513
                                ExecutionInfo:  updatedInfo,
×
514
                                ExecutionStats: updatedStats,
×
515
                                Condition:      nextEventID,
×
516
                        },
×
517
                        RangeID: s.ShardInfo.RangeID,
×
518
                        Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
519
                })
×
520
                s.IsType(&types.InternalServiceError{}, err)
×
521
        }
×
522

523
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
524
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
525
        updatedInfo.State = p.WorkflowStateCompleted
×
526
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
527
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
528
                UpdateWorkflowMutation: p.WorkflowMutation{
×
529
                        ExecutionInfo:  updatedInfo,
×
530
                        ExecutionStats: updatedStats,
×
531
                        Condition:      nextEventID,
×
532
                },
×
533
                RangeID: s.ShardInfo.RangeID,
×
534
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
535
        })
×
536
        s.IsType(&types.InternalServiceError{}, err)
×
537

×
538
        for _, closeStatus := range closeStatuses {
×
539
                updatedInfo.CloseStatus = closeStatus
×
540
                _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
541
                        UpdateWorkflowMutation: p.WorkflowMutation{
×
542
                                ExecutionInfo:    updatedInfo,
×
543
                                ExecutionStats:   updatedStats,
×
544
                                Condition:        nextEventID,
×
545
                                VersionHistories: versionHistories,
×
546
                        },
×
547
                        RangeID: s.ShardInfo.RangeID,
×
548
                        Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
549
                })
×
550
                s.Nil(err)
×
551
                info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
552
                s.Nil(err)
×
553
                s.Equal(p.WorkflowStateCompleted, info.ExecutionInfo.State)
×
554
                s.Equal(closeStatus, info.ExecutionInfo.CloseStatus)
×
555
        }
×
556

557
        // create a new workflow with same domain ID & workflow ID
558
        // to enable update workflow with zombie status
559
        workflowExecutionRunning := types.WorkflowExecution{
×
560
                WorkflowID: workflowExecution.WorkflowID,
×
561
                RunID:      uuid.New(),
×
562
        }
×
563
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionRunning.GetWorkflowID()
×
564
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionRunning.GetRunID()
×
565
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionRunning.GetRunID()
×
566
        req.Mode = p.CreateWorkflowModeWorkflowIDReuse
×
567
        req.PreviousRunID = workflowExecution.GetRunID()
×
568
        req.PreviousLastWriteVersion = common.EmptyVersion
×
569
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
570
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
571
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
572
        s.Nil(err)
×
573

×
574
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
575
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
576
        updatedInfo.State = p.WorkflowStateZombie
×
577
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
578
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
579
                UpdateWorkflowMutation: p.WorkflowMutation{
×
580
                        ExecutionInfo:    updatedInfo,
×
581
                        ExecutionStats:   updatedStats,
×
582
                        Condition:        nextEventID,
×
583
                        VersionHistories: versionHistories,
×
584
                },
×
585
                RangeID: s.ShardInfo.RangeID,
×
586
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
587
        })
×
588
        s.NoError(err)
×
589
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
590
        s.Nil(err)
×
591
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
592
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
593

×
594
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
595
        updatedStats = copyExecutionStats(info.ExecutionStats)
×
596
        updatedInfo.State = p.WorkflowStateZombie
×
597
        for _, closeStatus := range closeStatuses {
×
598
                updatedInfo.CloseStatus = closeStatus
×
599
                _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
600
                        UpdateWorkflowMutation: p.WorkflowMutation{
×
601
                                ExecutionInfo:  updatedInfo,
×
602
                                ExecutionStats: updatedStats,
×
603
                                Condition:      nextEventID,
×
604
                        },
×
605
                        RangeID: s.ShardInfo.RangeID,
×
606
                        Mode:    p.UpdateWorkflowModeBypassCurrent,
×
607
                })
×
608
                s.IsType(&types.InternalServiceError{}, err)
×
609
        }
×
610
}
611

612
// TestUpdateWorkflowExecutionWithZombieState test
613
func (s *ExecutionManagerSuite) TestUpdateWorkflowExecutionWithZombieState() {
×
614
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
615
        defer cancel()
×
616

×
617
        domainID := uuid.New()
×
618
        workflowID := "create-workflow-test-with-zombie-state"
×
619
        workflowExecution := types.WorkflowExecution{
×
620
                WorkflowID: workflowID,
×
621
                RunID:      uuid.New(),
×
622
        }
×
623
        tasklist := "some random tasklist"
×
624
        workflowType := "some random workflow type"
×
625
        workflowTimeout := int32(10)
×
626
        decisionTimeout := int32(14)
×
627
        lastProcessedEventID := int64(0)
×
628
        nextEventID := int64(3)
×
629
        csum := s.newRandomChecksum()
×
630
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
631
                {
×
632
                        EventID: nextEventID,
×
633
                        Version: common.EmptyVersion,
×
634
                },
×
635
        })
×
636
        versionHistories := p.NewVersionHistories(versionHistory)
×
637

×
638
        // create and update a workflow to make it completed
×
639
        req := &p.CreateWorkflowExecutionRequest{
×
640
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
641
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
642
                                CreateRequestID:             uuid.New(),
×
643
                                DomainID:                    domainID,
×
644
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
645
                                RunID:                       workflowExecution.GetRunID(),
×
646
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
647
                                TaskList:                    tasklist,
×
648
                                WorkflowTypeName:            workflowType,
×
649
                                WorkflowTimeout:             workflowTimeout,
×
650
                                DecisionStartToCloseTimeout: decisionTimeout,
×
651
                                NextEventID:                 nextEventID,
×
652
                                LastProcessedEvent:          lastProcessedEventID,
×
653
                                State:                       p.WorkflowStateRunning,
×
654
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
655
                        },
×
656
                        ExecutionStats:   &p.ExecutionStats{},
×
657
                        Checksum:         csum,
×
658
                        VersionHistories: versionHistories,
×
659
                },
×
660
                RangeID: s.ShardInfo.RangeID,
×
661
                Mode:    p.CreateWorkflowModeBrandNew,
×
662
        }
×
663
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
664
        s.Nil(err)
×
665
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
666
        s.Nil(err)
×
667
        s.Equal(workflowExecution.GetRunID(), currentRunID)
×
668

×
669
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
670
        s.Nil(err)
×
671
        s.assertChecksumsEqual(csum, info.Checksum)
×
672

×
673
        // try to turn current workflow into zombie state, this should end with an error
×
674
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
675
        updateStats := copyExecutionStats(info.ExecutionStats)
×
676
        updatedInfo.State = p.WorkflowStateZombie
×
677
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
678
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
679
                UpdateWorkflowMutation: p.WorkflowMutation{
×
680
                        ExecutionInfo:  updatedInfo,
×
681
                        ExecutionStats: updateStats,
×
682
                        Condition:      nextEventID,
×
683
                        Checksum:       csum,
×
684
                },
×
685
                RangeID: s.ShardInfo.RangeID,
×
686
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
687
        })
×
688
        s.NotNil(err)
×
689

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

×
706
        // create a new workflow with same domain ID & workflow ID
×
707
        workflowExecutionRunning := types.WorkflowExecution{
×
708
                WorkflowID: workflowID,
×
709
                RunID:      uuid.New(),
×
710
        }
×
711
        csum = checksum.Checksum{} // set checksum to nil
×
712
        req.NewWorkflowSnapshot.ExecutionInfo.WorkflowID = workflowExecutionRunning.GetWorkflowID()
×
713
        req.NewWorkflowSnapshot.ExecutionInfo.RunID = workflowExecutionRunning.GetRunID()
×
714
        req.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = workflowExecutionRunning.GetRunID()
×
715
        req.Mode = p.CreateWorkflowModeWorkflowIDReuse
×
716
        req.PreviousRunID = workflowExecution.GetRunID()
×
717
        req.PreviousLastWriteVersion = common.EmptyVersion
×
718
        req.NewWorkflowSnapshot.ExecutionInfo.State = p.WorkflowStateRunning
×
719
        req.NewWorkflowSnapshot.ExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
720
        req.NewWorkflowSnapshot.Checksum = csum
×
721
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
722
        s.Nil(err)
×
723
        currentRunID, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
724
        s.Nil(err)
×
725
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
726

×
727
        // get the workflow to be turned into a zombie
×
728
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
729
        s.Nil(err)
×
730
        s.assertChecksumsEqual(csum, info.Checksum)
×
731
        updatedInfo = copyWorkflowExecutionInfo(info.ExecutionInfo)
×
732
        updateStats = copyExecutionStats(info.ExecutionStats)
×
733
        updatedInfo.State = p.WorkflowStateZombie
×
734
        updatedInfo.CloseStatus = p.WorkflowCloseStatusNone
×
735
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
736
                UpdateWorkflowMutation: p.WorkflowMutation{
×
737
                        ExecutionInfo:    updatedInfo,
×
738
                        ExecutionStats:   updateStats,
×
739
                        Condition:        nextEventID,
×
740
                        Checksum:         csum,
×
741
                        VersionHistories: versionHistories,
×
742
                },
×
743
                RangeID: s.ShardInfo.RangeID,
×
744
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
745
        })
×
746
        s.NoError(err)
×
747
        info, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
748
        s.Nil(err)
×
749
        s.Equal(p.WorkflowStateZombie, info.ExecutionInfo.State)
×
750
        s.Equal(p.WorkflowCloseStatusNone, info.ExecutionInfo.CloseStatus)
×
751
        s.assertChecksumsEqual(csum, info.Checksum)
×
752
        // check current run ID is un touched
×
753
        currentRunID, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
754
        s.Nil(err)
×
755
        s.Equal(workflowExecutionRunning.GetRunID(), currentRunID)
×
756
}
×
757

758
// TestUpdateWorkflowExecutionTasks test
759
func (s *ExecutionManagerSuite) TestUpdateWorkflowExecutionTasks() {
×
760
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
761
        defer cancel()
×
762

×
763
        domainID := "b0a8571c-0257-40ea-afcd-3a14eae181c0"
×
764
        workflowExecution := types.WorkflowExecution{
×
765
                WorkflowID: "update-workflow-tasks-test",
×
766
                RunID:      "5ba5e531-e46b-48d9-b4b3-859919839553",
×
767
        }
×
768
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
769
        s.NoError(err0)
×
770
        s.NotNil(task0, "Expected non empty task identifier.")
×
771

×
772
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
773
        s.NoError(err)
×
774
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
775
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
776
        s.NoError(err)
×
777

×
778
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
779
        s.NoError(err)
×
780
        info1 := state1.ExecutionInfo
×
781
        s.NotNil(info1, "Valid Workflow info expected.")
×
782
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
783
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
784

×
785
        now := time.Now()
×
786
        remoteClusterName := "remote-cluster"
×
787
        transferTasks := []p.Task{
×
788
                &p.ActivityTask{
×
789
                        VisibilityTimestamp: now,
×
790
                        TaskID:              s.GetNextSequenceNumber(),
×
791
                        DomainID:            domainID,
×
792
                        TaskList:            "some randome tasklist name",
×
793
                        ScheduleID:          123,
×
794
                        Version:             common.EmptyVersion,
×
795
                },
×
796
        }
×
797
        timerTasks := []p.Task{
×
798
                &p.UserTimerTask{
×
799
                        VisibilityTimestamp: now.Add(time.Minute),
×
800
                        TaskID:              s.GetNextSequenceNumber(),
×
801
                        EventID:             124,
×
802
                        Version:             common.EmptyVersion,
×
803
                },
×
804
        }
×
805
        crossClusterTasks := []p.Task{
×
806
                &p.CrossClusterApplyParentClosePolicyTask{
×
807
                        ApplyParentClosePolicyTask: p.ApplyParentClosePolicyTask{
×
808
                                VisibilityTimestamp: now,
×
809
                                TaskID:              s.GetNextSequenceNumber(),
×
810
                                Version:             common.EmptyVersion,
×
811
                        },
×
812
                        TargetCluster: remoteClusterName,
×
813
                },
×
814
        }
×
815

×
816
        err = s.UpdateWorkflowExecutionTasks(
×
817
                ctx,
×
818
                updatedInfo1,
×
819
                updatedStats1,
×
820
                int64(3),
×
821
                transferTasks,
×
822
                timerTasks,
×
823
                crossClusterTasks,
×
824
        )
×
825
        s.NoError(err)
×
826

×
827
        loadedTransferTasks, err := s.GetTransferTasks(ctx, 10, true)
×
828
        s.NoError(err)
×
829
        s.Len(loadedTransferTasks, len(transferTasks))
×
830

×
831
        loadedTimerTasks, err := s.GetTimerIndexTasks(ctx, 10, true)
×
832
        s.NoError(err)
×
833
        s.Len(loadedTimerTasks, len(timerTasks))
×
834

×
835
        loadedCrossClusterTasks, err := s.GetCrossClusterTasks(ctx, remoteClusterName, 0, 10, true)
×
836
        s.NoError(err)
×
837
        s.Len(loadedCrossClusterTasks, len(crossClusterTasks))
×
838
}
×
839

840
// TestCreateWorkflowExecutionBrandNew test
841
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionBrandNew() {
×
842
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
843
        defer cancel()
×
844

×
845
        domainID := uuid.New()
×
846
        workflowExecution := types.WorkflowExecution{
×
847
                WorkflowID: "create-workflow-test-brand-new",
×
848
                RunID:      uuid.New(),
×
849
        }
×
850
        tasklist := "some random tasklist"
×
851
        workflowType := "some random workflow type"
×
852
        workflowTimeout := int32(10)
×
853
        decisionTimeout := int32(14)
×
854
        lastProcessedEventID := int64(0)
×
855
        nextEventID := int64(3)
×
856
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
857
                {
×
858
                        EventID: nextEventID,
×
859
                        Version: common.EmptyVersion,
×
860
                },
×
861
        })
×
862
        versionHistories := p.NewVersionHistories(versionHistory)
×
863

×
864
        req := &p.CreateWorkflowExecutionRequest{
×
865
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
866
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
867
                                CreateRequestID:             uuid.New(),
×
868
                                DomainID:                    domainID,
×
869
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
870
                                RunID:                       workflowExecution.GetRunID(),
×
871
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
872
                                TaskList:                    tasklist,
×
873
                                WorkflowTypeName:            workflowType,
×
874
                                WorkflowTimeout:             workflowTimeout,
×
875
                                DecisionStartToCloseTimeout: decisionTimeout,
×
876
                                State:                       p.WorkflowStateRunning,
×
877
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
878
                                LastFirstEventID:            common.FirstEventID,
×
879
                                NextEventID:                 nextEventID,
×
880
                                LastProcessedEvent:          lastProcessedEventID,
×
881
                        },
×
882
                        ExecutionStats:   &p.ExecutionStats{},
×
883
                        VersionHistories: versionHistories,
×
884
                },
×
885
                RangeID: s.ShardInfo.RangeID,
×
886
                Mode:    p.CreateWorkflowModeBrandNew,
×
887
        }
×
888

×
889
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
890
        s.Nil(err)
×
891
        _, err = s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
892
        s.NotNil(err)
×
893
        alreadyStartedErr, ok := err.(*p.WorkflowExecutionAlreadyStartedError)
×
894
        s.True(ok, "err is not WorkflowExecutionAlreadyStartedError")
×
895
        s.Equal(req.NewWorkflowSnapshot.ExecutionInfo.CreateRequestID, alreadyStartedErr.StartRequestID)
×
896
        s.Equal(workflowExecution.GetRunID(), alreadyStartedErr.RunID)
×
897
        s.Equal(0, alreadyStartedErr.CloseStatus)
×
898
        s.Equal(p.WorkflowStateRunning, alreadyStartedErr.State)
×
899
}
×
900

901
// TestUpsertWorkflowActivity test
902
func (s *ExecutionManagerSuite) TestUpsertWorkflowActivity() {
×
903
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
904
        defer cancel()
×
905

×
906
        domainID := uuid.New()
×
907
        workflowID := "create-workflow-test-with-upsert-activity"
×
908
        workflowExecution := types.WorkflowExecution{
×
909
                WorkflowID: workflowID,
×
910
                RunID:      uuid.New(),
×
911
        }
×
912
        tasklist := "some random tasklist"
×
913
        workflowType := "some random workflow type"
×
914
        workflowTimeout := int32(10)
×
915
        decisionTimeout := int32(14)
×
916
        lastProcessedEventID := int64(0)
×
917
        nextEventID := int64(3)
×
918
        csum := s.newRandomChecksum()
×
919
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
920
                {
×
921
                        EventID: nextEventID,
×
922
                        Version: common.EmptyVersion,
×
923
                },
×
924
        })
×
925
        versionHistories := p.NewVersionHistories(versionHistory)
×
926

×
927
        // create and update a workflow to make it completed
×
928
        req := &p.CreateWorkflowExecutionRequest{
×
929
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
930
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
931
                                CreateRequestID:             uuid.New(),
×
932
                                DomainID:                    domainID,
×
933
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
934
                                RunID:                       workflowExecution.GetRunID(),
×
935
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
936
                                TaskList:                    tasklist,
×
937
                                WorkflowTypeName:            workflowType,
×
938
                                WorkflowTimeout:             workflowTimeout,
×
939
                                DecisionStartToCloseTimeout: decisionTimeout,
×
940
                                NextEventID:                 nextEventID,
×
941
                                LastProcessedEvent:          lastProcessedEventID,
×
942
                                State:                       p.WorkflowStateRunning,
×
943
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
944
                        },
×
945
                        ExecutionStats:   &p.ExecutionStats{},
×
946
                        Checksum:         csum,
×
947
                        VersionHistories: versionHistories,
×
948
                },
×
949
                RangeID: s.ShardInfo.RangeID,
×
950
                Mode:    p.CreateWorkflowModeBrandNew,
×
951
        }
×
952
        _, err := s.ExecutionManager.CreateWorkflowExecution(ctx, req)
×
953
        s.Nil(err)
×
954
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
955
        s.Nil(err)
×
956
        s.Equal(workflowExecution.GetRunID(), currentRunID)
×
957

×
958
        info, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
959
        s.Nil(err)
×
960
        s.assertChecksumsEqual(csum, info.Checksum)
×
961
        s.Equal(0, len(info.ActivityInfos))
×
962

×
963
        // insert a new activity
×
964
        updatedInfo := copyWorkflowExecutionInfo(info.ExecutionInfo)
×
965
        updateStats := copyExecutionStats(info.ExecutionStats)
×
966
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
967
                UpdateWorkflowMutation: p.WorkflowMutation{
×
968
                        ExecutionInfo:  updatedInfo,
×
969
                        ExecutionStats: updateStats,
×
970
                        Condition:      nextEventID,
×
971
                        Checksum:       csum,
×
972
                        UpsertActivityInfos: []*p.ActivityInfo{
×
973
                                {
×
974
                                        Version:    0,
×
975
                                        ScheduleID: 100,
×
976
                                        TaskList:   "test-activity-tasklist-1",
×
977
                                },
×
978
                        },
×
979
                        VersionHistories: versionHistories,
×
980
                },
×
981
                RangeID: s.ShardInfo.RangeID,
×
982
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
983
        })
×
984
        s.Nil(err)
×
985

×
986
        info2, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
987
        s.Nil(err)
×
988
        s.Equal(1, len(info2.ActivityInfos))
×
989
        s.Equal("test-activity-tasklist-1", info2.ActivityInfos[100].TaskList)
×
990

×
991
        // upsert the previous activity
×
992
        _, err = s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
993
                UpdateWorkflowMutation: p.WorkflowMutation{
×
994
                        ExecutionInfo:  updatedInfo,
×
995
                        ExecutionStats: updateStats,
×
996
                        Condition:      nextEventID,
×
997
                        Checksum:       csum,
×
998
                        UpsertActivityInfos: []*p.ActivityInfo{
×
999
                                {
×
1000
                                        Version:    0,
×
1001
                                        ScheduleID: 100,
×
1002
                                        TaskList:   "test-activity-tasklist-2",
×
1003
                                },
×
1004
                        },
×
1005
                        VersionHistories: versionHistories,
×
1006
                },
×
1007
                RangeID: s.ShardInfo.RangeID,
×
1008
                Mode:    p.UpdateWorkflowModeUpdateCurrent,
×
1009
        })
×
1010
        s.NoError(err)
×
1011
        info3, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1012
        s.Nil(err)
×
1013
        s.Equal(1, len(info3.ActivityInfos))
×
1014
        s.Equal("test-activity-tasklist-2", info3.ActivityInfos[100].TaskList)
×
1015
}
×
1016

1017
// TestCreateWorkflowExecutionRunIDReuseWithoutReplication test
1018
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionRunIDReuseWithoutReplication() {
×
1019
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1020
        defer cancel()
×
1021

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

×
1042
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist,
×
1043
                workflowType, workflowTimeout, decisionTimeout, nil, nextEventID,
×
1044
                lastProcessedEventID, decisionScheduleID, nil, nil)
×
1045
        s.NoError(err0)
×
1046
        s.NotNil(task0, "Expected non empty task identifier.")
×
1047

×
1048
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1049
        s.NoError(err1)
×
1050
        s.assertChecksumsEqual(testWorkflowChecksum, state0.Checksum)
×
1051
        info0 := state0.ExecutionInfo
×
1052
        closeInfo := copyWorkflowExecutionInfo(info0)
×
1053
        closeInfo.State = p.WorkflowStateCompleted
×
1054
        closeInfo.CloseStatus = p.WorkflowCloseStatusCompleted
×
1055
        closeInfo.NextEventID = int64(5)
×
1056
        closeInfo.LastProcessedEvent = int64(2)
×
1057

×
1058
        err2 := s.UpdateWorkflowExecution(ctx, closeInfo, state0.ExecutionStats, versionHistories, nil, nil, nextEventID,
×
1059
                nil, nil, nil, nil, nil)
×
1060
        s.NoError(err2)
×
1061

×
1062
        newExecution := types.WorkflowExecution{
×
1063
                WorkflowID: workflowExecution.GetWorkflowID(),
×
1064
                RunID:      uuid.New(),
×
1065
        }
×
1066
        // this create should work since we are relying the business logic in history engine
×
1067
        // to check whether the existing running workflow has finished
×
1068
        _, err3 := s.ExecutionManager.CreateWorkflowExecution(ctx, &p.CreateWorkflowExecutionRequest{
×
1069
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1070
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1071
                                CreateRequestID:             uuid.New(),
×
1072
                                DomainID:                    domainID,
×
1073
                                WorkflowID:                  newExecution.GetWorkflowID(),
×
1074
                                RunID:                       newExecution.GetRunID(),
×
1075
                                FirstExecutionRunID:         newExecution.GetRunID(),
×
1076
                                TaskList:                    tasklist,
×
1077
                                WorkflowTypeName:            workflowType,
×
1078
                                WorkflowTimeout:             workflowTimeout,
×
1079
                                DecisionStartToCloseTimeout: decisionTimeout,
×
1080
                                State:                       p.WorkflowStateRunning,
×
1081
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1082
                                LastFirstEventID:            common.FirstEventID,
×
1083
                                NextEventID:                 nextEventID,
×
1084
                                LastProcessedEvent:          lastProcessedEventID,
×
1085
                        },
×
1086
                        ExecutionStats:   &p.ExecutionStats{},
×
1087
                        VersionHistories: versionHistories,
×
1088
                },
×
1089
                RangeID:                  s.ShardInfo.RangeID,
×
1090
                Mode:                     p.CreateWorkflowModeWorkflowIDReuse,
×
1091
                PreviousRunID:            workflowExecution.GetRunID(),
×
1092
                PreviousLastWriteVersion: common.EmptyVersion,
×
1093
        })
×
1094
        s.NoError(err3)
×
1095
}
×
1096

1097
// TestCreateWorkflowExecutionConcurrentCreate test
1098
func (s *ExecutionManagerSuite) TestCreateWorkflowExecutionConcurrentCreate() {
×
1099
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1100
        defer cancel()
×
1101

×
1102
        domainID := uuid.New()
×
1103
        workflowExecution := types.WorkflowExecution{
×
1104
                WorkflowID: "create-workflow-test-concurrent-create",
×
1105
                RunID:      uuid.New(),
×
1106
        }
×
1107
        tasklist := "some random tasklist"
×
1108
        workflowType := "some random workflow type"
×
1109
        workflowTimeout := int32(10)
×
1110
        decisionTimeout := int32(14)
×
1111
        lastProcessedEventID := int64(0)
×
1112
        nextEventID := int64(3)
×
1113
        decisionScheduleID := int64(2)
×
1114

×
1115
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist,
×
1116
                workflowType, workflowTimeout, decisionTimeout, nil, nextEventID,
×
1117
                lastProcessedEventID, decisionScheduleID, nil, nil)
×
1118
        s.Nil(err0, "No error expected.")
×
1119
        s.NotNil(task0, "Expected non empty task identifier.")
×
1120

×
1121
        times := 2
×
1122
        var wg sync.WaitGroup
×
1123
        wg.Add(times)
×
1124
        var numOfErr int32
×
1125
        var lastError error
×
1126
        for i := 0; i < times; i++ {
×
1127
                go func() {
×
1128
                        newExecution := types.WorkflowExecution{
×
1129
                                WorkflowID: workflowExecution.GetWorkflowID(),
×
1130
                                RunID:      uuid.New(),
×
1131
                        }
×
1132

×
1133
                        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1134
                        s.NoError(err1)
×
1135
                        info0 := state0.ExecutionInfo
×
1136
                        continueAsNewInfo := copyWorkflowExecutionInfo(info0)
×
1137
                        continueAsNewInfo.State = p.WorkflowStateRunning
×
1138
                        continueAsNewInfo.NextEventID = int64(5)
×
1139
                        continueAsNewInfo.LastProcessedEvent = int64(2)
×
1140

×
1141
                        err2 := s.ContinueAsNewExecution(ctx, continueAsNewInfo, state0.ExecutionStats, info0.NextEventID, newExecution, int64(3), int64(2), nil)
×
1142
                        if err2 != nil {
×
1143
                                errCount := atomic.AddInt32(&numOfErr, 1)
×
1144
                                if errCount > 1 {
×
1145
                                        lastError = err2
×
1146
                                }
×
1147
                        }
1148
                        wg.Done()
×
1149
                }()
1150
        }
1151
        wg.Wait()
×
1152
        if lastError != nil {
×
1153
                s.Fail("More than one error: %v", lastError.Error())
×
1154
        }
×
1155
        s.Equal(int32(1), atomic.LoadInt32(&numOfErr))
×
1156
}
1157

1158
// TestPersistenceStartWorkflow test
1159
func (s *ExecutionManagerSuite) TestPersistenceStartWorkflow() {
×
1160
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1161
        defer cancel()
×
1162

×
1163
        domainID := "2d7994bf-9de8-459d-9c81-e723daedb246"
×
1164
        workflowExecution := types.WorkflowExecution{
×
1165
                WorkflowID: "start-workflow-test",
×
1166
                RunID:      "7f9fe8a0-9237-11e6-ae22-56b6b6499611",
×
1167
        }
×
1168
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1169
        s.NoError(err0)
×
1170
        s.NotNil(task0, "Expected non empty task identifier.")
×
1171

×
1172
        task1, err1 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType1", 20, 14, nil, 3, 0, 2, nil, nil)
×
1173
        s.Error(err1, "Expected workflow creation to fail.")
×
1174
        log.Infof("Unable to start workflow execution: %v", err1)
×
1175
        startedErr, ok := err1.(*p.WorkflowExecutionAlreadyStartedError)
×
1176
        s.True(ok, fmt.Sprintf("Expected WorkflowExecutionAlreadyStartedError, but actual is %v", err1))
×
1177
        s.Equal(workflowExecution.GetRunID(), startedErr.RunID, startedErr.Msg)
×
1178

×
1179
        s.Equal(p.WorkflowStateRunning, startedErr.State, startedErr.Msg)
×
1180
        s.Equal(p.WorkflowCloseStatusNone, startedErr.CloseStatus, startedErr.Msg)
×
1181
        s.Equal(common.EmptyVersion, startedErr.LastWriteVersion, startedErr.Msg)
×
1182
        s.Empty(task1, "Expected empty task identifier.")
×
1183
        decisionScheduleID := int64(2)
×
1184
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1185
                {
×
1186
                        EventID: decisionScheduleID,
×
1187
                        Version: common.EmptyVersion,
×
1188
                },
×
1189
        })
×
1190
        versionHistories := p.NewVersionHistories(versionHistory)
×
1191

×
1192
        response, err2 := s.ExecutionManager.CreateWorkflowExecution(ctx, &p.CreateWorkflowExecutionRequest{
×
1193
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1194
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1195
                                CreateRequestID:             uuid.New(),
×
1196
                                DomainID:                    domainID,
×
1197
                                WorkflowID:                  workflowExecution.GetWorkflowID(),
×
1198
                                RunID:                       workflowExecution.GetRunID(),
×
1199
                                FirstExecutionRunID:         workflowExecution.GetRunID(),
×
1200
                                TaskList:                    "queue1",
×
1201
                                WorkflowTypeName:            "workflow_type_test",
×
1202
                                WorkflowTimeout:             20,
×
1203
                                DecisionStartToCloseTimeout: 13,
×
1204
                                ExecutionContext:            nil,
×
1205
                                State:                       p.WorkflowStateRunning,
×
1206
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1207
                                LastFirstEventID:            common.FirstEventID,
×
1208
                                NextEventID:                 int64(3),
×
1209
                                LastProcessedEvent:          0,
×
1210
                                DecisionScheduleID:          decisionScheduleID,
×
1211
                                DecisionStartedID:           common.EmptyEventID,
×
1212
                                DecisionTimeout:             1,
×
1213
                        },
×
1214
                        ExecutionStats: &p.ExecutionStats{},
×
1215
                        TransferTasks: []p.Task{
×
1216
                                &p.DecisionTask{
×
1217
                                        TaskID:     s.GetNextSequenceNumber(),
×
1218
                                        DomainID:   domainID,
×
1219
                                        TaskList:   "queue1",
×
1220
                                        ScheduleID: int64(2),
×
1221
                                },
×
1222
                        },
×
1223
                        TimerTasks:       nil,
×
1224
                        VersionHistories: versionHistories,
×
1225
                },
×
1226
                RangeID: s.ShardInfo.RangeID - 1,
×
1227
        })
×
1228

×
1229
        s.Error(err2, "Expected workflow creation to fail.")
×
1230
        s.Nil(response)
×
1231
        log.Infof("Unable to start workflow execution: %v", err2)
×
1232
        s.IsType(&p.ShardOwnershipLostError{}, err2)
×
1233
}
×
1234

1235
// TestGetWorkflow test
1236
func (s *ExecutionManagerSuite) TestGetWorkflow() {
×
1237
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1238
        defer cancel()
×
1239

×
1240
        now := time.Now()
×
1241
        testResetPoints := types.ResetPoints{
×
1242
                Points: []*types.ResetPointInfo{
×
1243
                        {
×
1244
                                BinaryChecksum:           "test-binary-checksum",
×
1245
                                RunID:                    "test-runID",
×
1246
                                FirstDecisionCompletedID: 123,
×
1247
                                CreatedTimeNano:          common.Int64Ptr(456),
×
1248
                                Resettable:               true,
×
1249
                                ExpiringTimeNano:         common.Int64Ptr(789),
×
1250
                        },
×
1251
                },
×
1252
        }
×
1253
        testSearchAttrKey := "env"
×
1254
        testSearchAttrVal, _ := json.Marshal("test")
×
1255
        testSearchAttr := map[string][]byte{
×
1256
                testSearchAttrKey: testSearchAttrVal,
×
1257
        }
×
1258

×
1259
        testMemoKey := "memoKey"
×
1260
        testMemoVal, _ := json.Marshal("memoVal")
×
1261
        testMemo := map[string][]byte{
×
1262
                testMemoKey: testMemoVal,
×
1263
        }
×
1264

×
1265
        testPartitionConfig := map[string]string{
×
1266
                "zone": "dca1",
×
1267
        }
×
1268

×
1269
        csum := s.newRandomChecksum()
×
1270
        decisionScheduleID := int64(rand.Int31())
×
1271
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1272
                {
×
1273
                        EventID: decisionScheduleID,
×
1274
                        Version: common.EmptyVersion,
×
1275
                },
×
1276
        })
×
1277
        versionHistories := p.NewVersionHistories(versionHistory)
×
1278
        createReq := &p.CreateWorkflowExecutionRequest{
×
1279
                NewWorkflowSnapshot: p.WorkflowSnapshot{
×
1280
                        ExecutionInfo: &p.WorkflowExecutionInfo{
×
1281
                                CreateRequestID:             uuid.New(),
×
1282
                                DomainID:                    uuid.New(),
×
1283
                                WorkflowID:                  "get-workflow-test",
×
1284
                                RunID:                       uuid.New(),
×
1285
                                ParentDomainID:              uuid.New(),
×
1286
                                ParentWorkflowID:            "get-workflow-test-parent",
×
1287
                                ParentRunID:                 uuid.New(),
×
1288
                                InitiatedID:                 rand.Int63(),
×
1289
                                TaskList:                    "get-wf-test-tasklist",
×
1290
                                WorkflowTypeName:            "code.uber.internal/test/workflow",
×
1291
                                WorkflowTimeout:             rand.Int31(),
×
1292
                                DecisionStartToCloseTimeout: rand.Int31(),
×
1293
                                ExecutionContext:            []byte("test-execution-context"),
×
1294
                                State:                       p.WorkflowStateRunning,
×
1295
                                CloseStatus:                 p.WorkflowCloseStatusNone,
×
1296
                                LastFirstEventID:            common.FirstEventID,
×
1297
                                NextEventID:                 rand.Int63(),
×
1298
                                LastProcessedEvent:          int64(rand.Int31()),
×
1299
                                LastUpdatedTimestamp:        now,
×
1300
                                StartTimestamp:              now,
×
1301
                                SignalCount:                 rand.Int31(),
×
1302
                                DecisionVersion:             int64(rand.Int31()),
×
1303
                                DecisionScheduleID:          decisionScheduleID,
×
1304
                                DecisionStartedID:           int64(rand.Int31()),
×
1305
                                DecisionTimeout:             rand.Int31(),
×
1306
                                Attempt:                     rand.Int31(),
×
1307
                                HasRetryPolicy:              true,
×
1308
                                InitialInterval:             rand.Int31(),
×
1309
                                BackoffCoefficient:          7.78,
×
1310
                                MaximumInterval:             rand.Int31(),
×
1311
                                ExpirationTime:              time.Now(),
×
1312
                                MaximumAttempts:             rand.Int31(),
×
1313
                                NonRetriableErrors:          []string{"badRequestError", "accessDeniedError"},
×
1314
                                CronSchedule:                "* * * * *",
×
1315
                                ExpirationSeconds:           rand.Int31(),
×
1316
                                AutoResetPoints:             &testResetPoints,
×
1317
                                SearchAttributes:            testSearchAttr,
×
1318
                                Memo:                        testMemo,
×
1319
                                PartitionConfig:             testPartitionConfig,
×
1320
                        },
×
1321
                        ExecutionStats: &p.ExecutionStats{
×
1322
                                HistorySize: int64(rand.Int31()),
×
1323
                        },
×
1324
                        Checksum:         csum,
×
1325
                        VersionHistories: versionHistories,
×
1326
                },
×
1327
                Mode: p.CreateWorkflowModeBrandNew,
×
1328
        }
×
1329
        createReq.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID = createReq.NewWorkflowSnapshot.ExecutionInfo.RunID
×
1330

×
1331
        createResp, err := s.ExecutionManager.CreateWorkflowExecution(ctx, createReq)
×
1332
        s.NoError(err)
×
1333
        s.NotNil(createResp, "Expected non empty task identifier.")
×
1334

×
1335
        state, err := s.GetWorkflowExecutionInfo(ctx, createReq.NewWorkflowSnapshot.ExecutionInfo.DomainID,
×
1336
                types.WorkflowExecution{
×
1337
                        WorkflowID: createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowID,
×
1338
                        RunID:      createReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
1339
                })
×
1340
        s.NoError(err)
×
1341
        info := state.ExecutionInfo
×
1342
        s.NotNil(info, "Valid Workflow response expected.")
×
1343
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.CreateRequestID, info.CreateRequestID)
×
1344
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DomainID, info.DomainID)
×
1345
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowID, info.WorkflowID)
×
1346
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.RunID, info.RunID)
×
1347
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.FirstExecutionRunID, info.FirstExecutionRunID)
×
1348
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ParentDomainID, info.ParentDomainID)
×
1349
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ParentWorkflowID, info.ParentWorkflowID)
×
1350
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ParentRunID, info.ParentRunID)
×
1351
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.InitiatedID, info.InitiatedID)
×
1352
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.TaskList, info.TaskList)
×
1353
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowTypeName, info.WorkflowTypeName)
×
1354
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.WorkflowTimeout, info.WorkflowTimeout)
×
1355
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionStartToCloseTimeout, info.DecisionStartToCloseTimeout)
×
1356
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ExecutionContext, info.ExecutionContext)
×
1357
        s.Equal(p.WorkflowStateRunning, info.State)
×
1358
        s.Equal(p.WorkflowCloseStatusNone, info.CloseStatus)
×
1359
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.NextEventID, info.NextEventID)
×
1360
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.LastProcessedEvent, info.LastProcessedEvent)
×
1361
        s.Equal(true, s.validateTimeRange(info.LastUpdatedTimestamp, time.Hour))
×
1362
        s.Equal(true, s.validateTimeRange(info.StartTimestamp, time.Hour))
×
1363
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionVersion, info.DecisionVersion)
×
1364
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionScheduleID, info.DecisionScheduleID)
×
1365
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionStartedID, info.DecisionStartedID)
×
1366
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.DecisionTimeout, info.DecisionTimeout)
×
1367
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.SignalCount, info.SignalCount)
×
1368
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.Attempt, info.Attempt)
×
1369
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.HasRetryPolicy, info.HasRetryPolicy)
×
1370
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.InitialInterval, info.InitialInterval)
×
1371
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.BackoffCoefficient, info.BackoffCoefficient)
×
1372
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.MaximumAttempts, info.MaximumAttempts)
×
1373
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.MaximumInterval, info.MaximumInterval)
×
1374
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationSeconds, info.ExpirationSeconds)
×
1375
        s.EqualTimes(createReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime, info.ExpirationTime)
×
1376
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.CronSchedule, info.CronSchedule)
×
1377
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionInfo.NonRetriableErrors, info.NonRetriableErrors)
×
1378
        s.Equal(testResetPoints, *info.AutoResetPoints)
×
1379
        s.Equal(createReq.NewWorkflowSnapshot.ExecutionStats.HistorySize, state.ExecutionStats.HistorySize)
×
1380
        val, ok := info.SearchAttributes[testSearchAttrKey]
×
1381
        s.True(ok)
×
1382
        s.Equal(testSearchAttrVal, val)
×
1383
        val, ok = info.Memo[testMemoKey]
×
1384
        s.True(ok)
×
1385
        s.Equal(testMemoVal, val)
×
1386
        s.Equal(testPartitionConfig, info.PartitionConfig)
×
1387

×
1388
        s.assertChecksumsEqual(csum, state.Checksum)
×
1389
}
×
1390

1391
// TestUpdateWorkflow test
1392
func (s *ExecutionManagerSuite) TestUpdateWorkflow() {
×
1393
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1394
        defer cancel()
×
1395

×
1396
        domainID := "b0a8571c-0257-40ea-afcd-3a14eae181c0"
×
1397
        workflowExecution := types.WorkflowExecution{
×
1398
                WorkflowID: "update-workflow-test",
×
1399
                RunID:      "5ba5e531-e46b-48d9-b4b3-859919839553",
×
1400
        }
×
1401
        partitionConfig0 := map[string]string{
×
1402
                "userID": uuid.New(),
×
1403
        }
×
1404
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, partitionConfig0)
×
1405
        s.NoError(err0)
×
1406
        s.NotNil(task0, "Expected non empty task identifier.")
×
1407

×
1408
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1409
        s.NoError(err1)
×
1410
        info0 := state0.ExecutionInfo
×
1411
        s.NotNil(info0, "Valid Workflow info expected.")
×
1412
        s.Equal(domainID, info0.DomainID)
×
1413
        s.Equal("update-workflow-test", info0.WorkflowID)
×
1414
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info0.RunID)
×
1415
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info0.FirstExecutionRunID)
×
1416
        s.Equal("queue1", info0.TaskList)
×
1417
        s.Equal("wType", info0.WorkflowTypeName)
×
1418
        s.Equal(int32(20), info0.WorkflowTimeout)
×
1419
        s.Equal(int32(13), info0.DecisionStartToCloseTimeout)
×
1420
        s.Equal([]byte(nil), info0.ExecutionContext)
×
1421
        s.Equal(p.WorkflowStateRunning, info0.State)
×
1422
        s.Equal(p.WorkflowCloseStatusNone, info0.CloseStatus)
×
1423
        s.Equal(int64(1), info0.LastFirstEventID)
×
1424
        s.Equal(int64(3), info0.NextEventID)
×
1425
        s.Equal(int64(0), info0.LastProcessedEvent)
×
1426
        s.Equal(true, s.validateTimeRange(info0.LastUpdatedTimestamp, time.Minute))
×
1427
        s.Equal(true, s.validateTimeRange(info0.StartTimestamp, time.Minute))
×
1428
        s.Equal(int64(0), info0.DecisionVersion)
×
1429
        s.Equal(int64(2), info0.DecisionScheduleID)
×
1430
        s.Equal(common.EmptyEventID, info0.DecisionStartedID)
×
1431
        s.Equal(int32(1), info0.DecisionTimeout)
×
1432
        s.Equal(int64(0), info0.DecisionAttempt)
×
1433
        s.Equal(int64(0), info0.DecisionStartedTimestamp)
×
1434
        s.Equal(int64(0), info0.DecisionScheduledTimestamp)
×
1435
        s.Equal(int64(0), info0.DecisionOriginalScheduledTimestamp)
×
1436
        s.Empty(info0.StickyTaskList)
×
1437
        s.Equal(int32(0), info0.StickyScheduleToStartTimeout)
×
1438
        s.Empty(info0.ClientLibraryVersion)
×
1439
        s.Empty(info0.ClientFeatureVersion)
×
1440
        s.Empty(info0.ClientImpl)
×
1441
        s.Equal(int32(0), info0.SignalCount)
×
1442
        s.Equal(info0.AutoResetPoints, &types.ResetPoints{})
×
1443
        s.True(len(info0.SearchAttributes) == 0)
×
1444
        s.True(len(info0.Memo) == 0)
×
1445
        s.Equal(partitionConfig0, info0.PartitionConfig)
×
1446
        s.assertChecksumsEqual(testWorkflowChecksum, state0.Checksum)
×
1447

×
1448
        log.Infof("Workflow execution last updated: %v", info0.LastUpdatedTimestamp)
×
1449

×
1450
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
1451
        updatedStats := state0.ExecutionStats
×
1452
        updatedInfo.LastFirstEventID = int64(3)
×
1453
        updatedInfo.NextEventID = int64(5)
×
1454
        updatedInfo.LastProcessedEvent = int64(2)
×
1455
        updatedInfo.DecisionVersion = int64(666)
×
1456
        updatedInfo.DecisionAttempt = int64(123)
×
1457
        updatedInfo.DecisionStartedTimestamp = int64(321)
×
1458
        updatedInfo.DecisionScheduledTimestamp = int64(654)
×
1459
        updatedInfo.DecisionOriginalScheduledTimestamp = int64(655)
×
1460
        updatedInfo.StickyTaskList = "random sticky tasklist"
×
1461
        updatedInfo.StickyScheduleToStartTimeout = 876
×
1462
        updatedInfo.ClientLibraryVersion = "random client library version"
×
1463
        updatedInfo.ClientFeatureVersion = "random client feature version"
×
1464
        updatedInfo.ClientImpl = "random client impl"
×
1465
        updatedInfo.SignalCount = 9
×
1466
        updatedInfo.InitialInterval = math.MaxInt32
×
1467
        updatedInfo.BackoffCoefficient = 4.45
×
1468
        updatedInfo.MaximumInterval = math.MaxInt32
×
1469
        updatedInfo.MaximumAttempts = math.MaxInt32
×
1470
        updatedInfo.ExpirationSeconds = math.MaxInt32
×
1471
        updatedInfo.ExpirationTime = time.Now()
×
1472
        updatedInfo.NonRetriableErrors = []string{"accessDenied", "badRequest"}
×
1473
        searchAttrKey := "env"
×
1474
        searchAttrVal := []byte("test")
×
1475
        updatedInfo.SearchAttributes = map[string][]byte{searchAttrKey: searchAttrVal}
×
1476
        memoKey := "memoKey"
×
1477
        memoVal := []byte("memoVal")
×
1478
        updatedInfo.Memo = map[string][]byte{memoKey: memoVal}
×
1479
        partitionConfig := map[string]string{"zone": "dca2"}
×
1480
        updatedInfo.PartitionConfig = partitionConfig
×
1481
        updatedStats.HistorySize = math.MaxInt64
×
1482
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1483
                {
×
1484
                        EventID: updatedInfo.NextEventID,
×
1485
                        Version: common.EmptyVersion,
×
1486
                },
×
1487
        })
×
1488
        versionHistories := p.NewVersionHistories(versionHistory)
×
1489

×
1490
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, nil, nil, nil, nil)
×
1491
        s.NoError(err2)
×
1492

×
1493
        state1, err3 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1494
        s.NoError(err3)
×
1495
        info1 := state1.ExecutionInfo
×
1496
        s.NotNil(info1, "Valid Workflow info expected.")
×
1497
        s.Equal(domainID, info1.DomainID)
×
1498
        s.Equal("update-workflow-test", info1.WorkflowID)
×
1499
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info1.RunID)
×
1500
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info1.FirstExecutionRunID)
×
1501
        s.Equal("queue1", info1.TaskList)
×
1502
        s.Equal("wType", info1.WorkflowTypeName)
×
1503
        s.Equal(int32(20), info1.WorkflowTimeout)
×
1504
        s.Equal(int32(13), info1.DecisionStartToCloseTimeout)
×
1505
        s.Equal([]byte(nil), info1.ExecutionContext)
×
1506
        s.Equal(p.WorkflowStateRunning, info1.State)
×
1507
        s.Equal(p.WorkflowCloseStatusNone, info1.CloseStatus)
×
1508
        s.Equal(int64(3), info1.LastFirstEventID)
×
1509
        s.Equal(int64(5), info1.NextEventID)
×
1510
        s.Equal(int64(2), info1.LastProcessedEvent)
×
1511
        s.Equal(true, s.validateTimeRange(info1.LastUpdatedTimestamp, time.Hour))
×
1512
        s.Equal(info0.StartTimestamp.UnixNano(), info1.StartTimestamp.UnixNano())
×
1513
        s.Equal(int64(666), info1.DecisionVersion)
×
1514
        s.Equal(int64(2), info1.DecisionScheduleID)
×
1515
        s.Equal(common.EmptyEventID, info1.DecisionStartedID)
×
1516
        s.Equal(int32(1), info1.DecisionTimeout)
×
1517
        s.Equal(int64(123), info1.DecisionAttempt)
×
1518
        s.Equal(int64(321), info1.DecisionStartedTimestamp)
×
1519
        s.Equal(int64(654), info1.DecisionScheduledTimestamp)
×
1520
        s.Equal(int64(655), info1.DecisionOriginalScheduledTimestamp)
×
1521
        s.Equal(updatedInfo.StickyTaskList, info1.StickyTaskList)
×
1522
        s.Equal(updatedInfo.StickyScheduleToStartTimeout, info1.StickyScheduleToStartTimeout)
×
1523
        s.Equal(updatedInfo.ClientLibraryVersion, info1.ClientLibraryVersion)
×
1524
        s.Equal(updatedInfo.ClientFeatureVersion, info1.ClientFeatureVersion)
×
1525
        s.Equal(updatedInfo.ClientImpl, info1.ClientImpl)
×
1526
        s.Equal(updatedInfo.SignalCount, info1.SignalCount)
×
1527
        s.EqualValues(updatedStats.HistorySize, state1.ExecutionStats.HistorySize)
×
1528
        s.Equal(updatedInfo.InitialInterval, info1.InitialInterval)
×
1529
        s.Equal(updatedInfo.BackoffCoefficient, info1.BackoffCoefficient)
×
1530
        s.Equal(updatedInfo.MaximumInterval, info1.MaximumInterval)
×
1531
        s.Equal(updatedInfo.MaximumAttempts, info1.MaximumAttempts)
×
1532
        s.Equal(updatedInfo.ExpirationSeconds, info1.ExpirationSeconds)
×
1533
        s.EqualTimes(updatedInfo.ExpirationTime, info1.ExpirationTime)
×
1534
        s.Equal(updatedInfo.NonRetriableErrors, info1.NonRetriableErrors)
×
1535
        searchAttrVal1, ok := info1.SearchAttributes[searchAttrKey]
×
1536
        s.True(ok)
×
1537
        s.Equal(searchAttrVal, searchAttrVal1)
×
1538
        memoVal1, ok := info1.Memo[memoKey]
×
1539
        s.True(ok)
×
1540
        s.Equal(memoVal, memoVal1)
×
1541
        s.Equal(partitionConfig, info1.PartitionConfig)
×
1542
        s.assertChecksumsEqual(testWorkflowChecksum, state1.Checksum)
×
1543

×
1544
        log.Infof("Workflow execution last updated: %v", info1.LastUpdatedTimestamp)
×
1545

×
1546
        failedUpdateInfo := copyWorkflowExecutionInfo(updatedInfo)
×
1547
        failedUpdateStats := copyExecutionStats(updatedStats)
×
1548
        err4 := s.UpdateWorkflowExecution(ctx, failedUpdateInfo, failedUpdateStats, versionHistories, []int64{int64(5)}, nil, int64(3), nil, nil, nil, nil, nil)
×
1549
        s.Error(err4, "expected non nil error.")
×
1550
        s.IsType(&p.ConditionFailedError{}, err4)
×
1551
        log.Errorf("Conditional update failed with error: %v", err4)
×
1552

×
1553
        state2, err4 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1554
        s.NoError(err4)
×
1555
        info2 := state2.ExecutionInfo
×
1556
        s.NotNil(info2, "Valid Workflow info expected.")
×
1557
        s.Equal(domainID, info2.DomainID)
×
1558
        s.Equal("update-workflow-test", info2.WorkflowID)
×
1559
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info2.RunID)
×
1560
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info2.FirstExecutionRunID)
×
1561
        s.Equal("queue1", info2.TaskList)
×
1562
        s.Equal("wType", info2.WorkflowTypeName)
×
1563
        s.Equal(int32(20), info2.WorkflowTimeout)
×
1564
        s.Equal(int32(13), info2.DecisionStartToCloseTimeout)
×
1565
        s.Equal([]byte(nil), info2.ExecutionContext)
×
1566
        s.Equal(p.WorkflowStateRunning, info2.State)
×
1567
        s.Equal(p.WorkflowCloseStatusNone, info2.CloseStatus)
×
1568
        s.Equal(int64(5), info2.NextEventID)
×
1569
        s.Equal(int64(2), info2.LastProcessedEvent)
×
1570
        s.Equal(true, s.validateTimeRange(info2.LastUpdatedTimestamp, time.Hour))
×
1571
        s.Equal(int64(666), info2.DecisionVersion)
×
1572
        s.Equal(int64(2), info2.DecisionScheduleID)
×
1573
        s.Equal(common.EmptyEventID, info2.DecisionStartedID)
×
1574
        s.Equal(int32(1), info2.DecisionTimeout)
×
1575
        s.Equal(int64(123), info2.DecisionAttempt)
×
1576
        s.Equal(int64(321), info2.DecisionStartedTimestamp)
×
1577
        s.Equal(int64(654), info2.DecisionScheduledTimestamp)
×
1578
        s.Equal(int64(655), info2.DecisionOriginalScheduledTimestamp)
×
1579
        s.Equal(updatedInfo.SignalCount, info2.SignalCount)
×
1580
        s.EqualValues(updatedStats.HistorySize, state2.ExecutionStats.HistorySize)
×
1581
        s.Equal(updatedInfo.InitialInterval, info2.InitialInterval)
×
1582
        s.Equal(updatedInfo.BackoffCoefficient, info2.BackoffCoefficient)
×
1583
        s.Equal(updatedInfo.MaximumInterval, info2.MaximumInterval)
×
1584
        s.Equal(updatedInfo.MaximumAttempts, info2.MaximumAttempts)
×
1585
        s.Equal(updatedInfo.ExpirationSeconds, info2.ExpirationSeconds)
×
1586
        s.EqualTimes(updatedInfo.ExpirationTime, info2.ExpirationTime)
×
1587
        s.Equal(updatedInfo.NonRetriableErrors, info2.NonRetriableErrors)
×
1588
        searchAttrVal2, ok := info2.SearchAttributes[searchAttrKey]
×
1589
        s.True(ok)
×
1590
        s.Equal(searchAttrVal, searchAttrVal2)
×
1591
        memoVal2, ok := info1.Memo[memoKey]
×
1592
        s.True(ok)
×
1593
        s.Equal(memoVal, memoVal2)
×
1594
        s.Equal(partitionConfig, info2.PartitionConfig)
×
1595
        s.assertChecksumsEqual(testWorkflowChecksum, state2.Checksum)
×
1596
        log.Infof("Workflow execution last updated: %v", info2.LastUpdatedTimestamp)
×
1597

×
1598
        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)
×
1599
        s.Error(err5, "expected non nil error.")
×
1600
        s.IsType(&p.ShardOwnershipLostError{}, err5)
×
1601
        log.Errorf("Conditional update failed with error: %v", err5)
×
1602

×
1603
        state3, err6 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1604
        s.NoError(err6)
×
1605
        info3 := state3.ExecutionInfo
×
1606
        s.NotNil(info3, "Valid Workflow info expected.")
×
1607
        s.Equal(domainID, info3.DomainID)
×
1608
        s.Equal("update-workflow-test", info3.WorkflowID)
×
1609
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info3.RunID)
×
1610
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info3.FirstExecutionRunID)
×
1611
        s.Equal("queue1", info3.TaskList)
×
1612
        s.Equal("wType", info3.WorkflowTypeName)
×
1613
        s.Equal(int32(20), info3.WorkflowTimeout)
×
1614
        s.Equal(int32(13), info3.DecisionStartToCloseTimeout)
×
1615
        s.Equal([]byte(nil), info3.ExecutionContext)
×
1616
        s.Equal(p.WorkflowStateRunning, info3.State)
×
1617
        s.Equal(p.WorkflowCloseStatusNone, info3.CloseStatus)
×
1618
        s.Equal(int64(5), info3.NextEventID)
×
1619
        s.Equal(int64(2), info3.LastProcessedEvent)
×
1620
        s.Equal(true, s.validateTimeRange(info3.LastUpdatedTimestamp, time.Hour))
×
1621
        s.Equal(int64(666), info3.DecisionVersion)
×
1622
        s.Equal(int64(2), info3.DecisionScheduleID)
×
1623
        s.Equal(common.EmptyEventID, info3.DecisionStartedID)
×
1624
        s.Equal(int32(1), info3.DecisionTimeout)
×
1625
        s.Equal(int64(123), info3.DecisionAttempt)
×
1626
        s.Equal(int64(321), info3.DecisionStartedTimestamp)
×
1627
        s.Equal(int64(654), info3.DecisionScheduledTimestamp)
×
1628
        s.Equal(int64(655), info3.DecisionOriginalScheduledTimestamp)
×
1629
        s.Equal(updatedInfo.SignalCount, info3.SignalCount)
×
1630
        s.EqualValues(updatedStats.HistorySize, state3.ExecutionStats.HistorySize)
×
1631
        s.Equal(updatedInfo.InitialInterval, info3.InitialInterval)
×
1632
        s.Equal(updatedInfo.BackoffCoefficient, info3.BackoffCoefficient)
×
1633
        s.Equal(updatedInfo.MaximumInterval, info3.MaximumInterval)
×
1634
        s.Equal(updatedInfo.MaximumAttempts, info3.MaximumAttempts)
×
1635
        s.Equal(updatedInfo.ExpirationSeconds, info3.ExpirationSeconds)
×
1636
        s.EqualTimes(updatedInfo.ExpirationTime, info3.ExpirationTime)
×
1637
        s.Equal(updatedInfo.NonRetriableErrors, info3.NonRetriableErrors)
×
1638
        searchAttrVal3, ok := info3.SearchAttributes[searchAttrKey]
×
1639
        s.True(ok)
×
1640
        s.Equal(searchAttrVal, searchAttrVal3)
×
1641
        memoVal3, ok := info1.Memo[memoKey]
×
1642
        s.True(ok)
×
1643
        s.Equal(memoVal, memoVal3)
×
1644
        s.Equal(partitionConfig, info3.PartitionConfig)
×
1645
        s.assertChecksumsEqual(testWorkflowChecksum, state3.Checksum)
×
1646

×
1647
        log.Infof("Workflow execution last updated: %v", info3.LastUpdatedTimestamp)
×
1648

×
1649
        //update with incorrect rangeID and condition(next_event_id)
×
1650
        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)
×
1651
        s.Error(err7, "expected non nil error.")
×
1652
        s.IsType(&p.ShardOwnershipLostError{}, err7)
×
1653
        log.Errorf("Conditional update failed with error: %v", err7)
×
1654

×
1655
        state4, err8 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1656
        s.NoError(err8)
×
1657
        info4 := state4.ExecutionInfo
×
1658
        s.NotNil(info4, "Valid Workflow info expected.")
×
1659
        s.Equal(domainID, info4.DomainID)
×
1660
        s.Equal("update-workflow-test", info4.WorkflowID)
×
1661
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info4.RunID)
×
1662
        s.Equal("5ba5e531-e46b-48d9-b4b3-859919839553", info4.FirstExecutionRunID)
×
1663
        s.Equal("queue1", info4.TaskList)
×
1664
        s.Equal("wType", info4.WorkflowTypeName)
×
1665
        s.Equal(int32(20), info4.WorkflowTimeout)
×
1666
        s.Equal(int32(13), info4.DecisionStartToCloseTimeout)
×
1667
        s.Equal([]byte(nil), info4.ExecutionContext)
×
1668
        s.Equal(p.WorkflowStateRunning, info4.State)
×
1669
        s.Equal(p.WorkflowCloseStatusNone, info4.CloseStatus)
×
1670
        s.Equal(int64(5), info4.NextEventID)
×
1671
        s.Equal(int64(2), info4.LastProcessedEvent)
×
1672
        s.Equal(true, s.validateTimeRange(info4.LastUpdatedTimestamp, time.Hour))
×
1673
        s.Equal(int64(666), info4.DecisionVersion)
×
1674
        s.Equal(int64(2), info4.DecisionScheduleID)
×
1675
        s.Equal(common.EmptyEventID, info4.DecisionStartedID)
×
1676
        s.Equal(int32(1), info4.DecisionTimeout)
×
1677
        s.Equal(int64(123), info4.DecisionAttempt)
×
1678
        s.Equal(int64(321), info4.DecisionStartedTimestamp)
×
1679
        s.Equal(updatedInfo.SignalCount, info4.SignalCount)
×
1680
        s.EqualValues(updatedStats.HistorySize, state4.ExecutionStats.HistorySize)
×
1681
        s.Equal(updatedInfo.InitialInterval, info4.InitialInterval)
×
1682
        s.Equal(updatedInfo.BackoffCoefficient, info4.BackoffCoefficient)
×
1683
        s.Equal(updatedInfo.MaximumInterval, info4.MaximumInterval)
×
1684
        s.Equal(updatedInfo.MaximumAttempts, info4.MaximumAttempts)
×
1685
        s.Equal(updatedInfo.ExpirationSeconds, info4.ExpirationSeconds)
×
1686
        s.EqualTimes(updatedInfo.ExpirationTime, info4.ExpirationTime)
×
1687
        s.Equal(updatedInfo.NonRetriableErrors, info4.NonRetriableErrors)
×
1688
        searchAttrVal4, ok := info4.SearchAttributes[searchAttrKey]
×
1689
        s.True(ok)
×
1690
        s.Equal(searchAttrVal, searchAttrVal4)
×
1691
        memoVal4, ok := info1.Memo[memoKey]
×
1692
        s.True(ok)
×
1693
        s.Equal(memoVal, memoVal4)
×
1694
        s.Equal(partitionConfig, info4.PartitionConfig)
×
1695
        s.assertChecksumsEqual(testWorkflowChecksum, state4.Checksum)
×
1696

×
1697
        log.Infof("Workflow execution last updated: %v", info4.LastUpdatedTimestamp)
×
1698
}
×
1699

1700
// TestDeleteWorkflow test
1701
func (s *ExecutionManagerSuite) TestDeleteWorkflow() {
×
1702
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1703
        defer cancel()
×
1704

×
1705
        domainID := "1d4abb23-b87b-457b-96ef-43aba0b9c44f"
×
1706
        workflowExecution := types.WorkflowExecution{
×
1707
                WorkflowID: "delete-workflow-test",
×
1708
                RunID:      "4e0917f2-9361-4a14-b16f-1fafe09b287a",
×
1709
        }
×
1710
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1711
        s.NoError(err0)
×
1712
        s.NotNil(task0, "Expected non empty task identifier.")
×
1713

×
1714
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1715
        s.NoError(err1)
×
1716
        info0 := state0.ExecutionInfo
×
1717
        s.NotNil(info0, "Valid Workflow info expected.")
×
1718
        s.Equal(domainID, info0.DomainID)
×
1719
        s.Equal("delete-workflow-test", info0.WorkflowID)
×
1720
        s.Equal("4e0917f2-9361-4a14-b16f-1fafe09b287a", info0.RunID)
×
1721
        s.Equal("4e0917f2-9361-4a14-b16f-1fafe09b287a", info0.FirstExecutionRunID)
×
1722
        s.Equal("queue1", info0.TaskList)
×
1723
        s.Equal("wType", info0.WorkflowTypeName)
×
1724
        s.Equal(int32(20), info0.WorkflowTimeout)
×
1725
        s.Equal(int32(13), info0.DecisionStartToCloseTimeout)
×
1726
        s.Equal([]byte(nil), info0.ExecutionContext)
×
1727
        s.Equal(p.WorkflowStateRunning, info0.State)
×
1728
        s.Equal(p.WorkflowCloseStatusNone, info0.CloseStatus)
×
1729
        s.Equal(int64(3), info0.NextEventID)
×
1730
        s.Equal(int64(0), info0.LastProcessedEvent)
×
1731
        s.Equal(true, s.validateTimeRange(info0.LastUpdatedTimestamp, time.Hour))
×
1732
        s.Equal(int64(2), info0.DecisionScheduleID)
×
1733
        s.Equal(common.EmptyEventID, info0.DecisionStartedID)
×
1734
        s.Equal(int32(1), info0.DecisionTimeout)
×
1735

×
1736
        log.Infof("Workflow execution last updated: %v", info0.LastUpdatedTimestamp)
×
1737

×
1738
        err4 := s.DeleteWorkflowExecution(ctx, info0)
×
1739
        s.NoError(err4)
×
1740

×
1741
        _, err3 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1742
        s.Error(err3, "expected non nil error.")
×
1743
        s.IsType(&types.EntityNotExistsError{}, err3)
×
1744

×
1745
        err5 := s.DeleteWorkflowExecution(ctx, info0)
×
1746
        s.NoError(err5)
×
1747
}
×
1748

1749
// TestDeleteCurrentWorkflow test
1750
func (s *ExecutionManagerSuite) TestDeleteCurrentWorkflow() {
×
1751
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1752
        defer cancel()
×
1753

×
1754
        if s.ExecutionManager.GetName() != "cassandra" {
×
1755
                //"this test is only applicable for cassandra (uses TTL based deletes)"
×
1756
                return
×
1757
        }
×
1758
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
1759
        workflowExecution := types.WorkflowExecution{
×
1760
                WorkflowID: "delete-current-workflow-test",
×
1761
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
1762
        }
×
1763

×
1764
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1765
        s.NoError(err0)
×
1766
        s.NotNil(task0, "Expected non empty task identifier.")
×
1767

×
1768
        runID0, err1 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1769
        s.NoError(err1)
×
1770
        s.Equal(workflowExecution.GetRunID(), runID0)
×
1771

×
1772
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1773
        s.NoError(err2)
×
1774

×
1775
        updatedInfo1 := copyWorkflowExecutionInfo(info0.ExecutionInfo)
×
1776
        updatedStats1 := copyExecutionStats(info0.ExecutionStats)
×
1777
        updatedInfo1.NextEventID = int64(6)
×
1778
        updatedInfo1.LastProcessedEvent = int64(2)
×
1779
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1780
                {
×
1781
                        EventID: updatedInfo1.LastProcessedEvent,
×
1782
                        Version: common.EmptyVersion,
×
1783
                },
×
1784
        })
×
1785
        versionHistories := p.NewVersionHistories(versionHistory)
×
1786
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(3), versionHistories)
×
1787
        s.NoError(err3)
×
1788

×
1789
        runID4, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1790
        s.NoError(err4)
×
1791
        s.Equal(workflowExecution.GetRunID(), runID4)
×
1792

×
1793
        fakeInfo := &p.WorkflowExecutionInfo{
×
1794
                DomainID:   info0.ExecutionInfo.DomainID,
×
1795
                WorkflowID: info0.ExecutionInfo.WorkflowID,
×
1796
                RunID:      uuid.New(),
×
1797
        }
×
1798

×
1799
        // test wrong run id with conditional delete
×
1800
        s.NoError(s.DeleteCurrentWorkflowExecution(ctx, fakeInfo))
×
1801

×
1802
        runID5, err5 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1803
        s.NoError(err5)
×
1804
        s.Equal(workflowExecution.GetRunID(), runID5)
×
1805

×
1806
        // simulate a timer_task deleting execution after retention
×
1807
        s.NoError(s.DeleteCurrentWorkflowExecution(ctx, info0.ExecutionInfo))
×
1808

×
1809
        runID0, err1 = s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1810
        s.Error(err1)
×
1811
        s.Empty(runID0)
×
1812
        _, ok := err1.(*types.EntityNotExistsError)
×
1813
        s.True(ok)
×
1814

×
1815
        // execution record should still be there
×
1816
        _, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1817
        s.NoError(err2)
×
1818
}
1819

1820
// TestUpdateDeleteWorkflow mocks the timer behavior to clean up workflow.
1821
func (s *ExecutionManagerSuite) TestUpdateDeleteWorkflow() {
×
1822
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1823
        defer cancel()
×
1824

×
1825
        finishedCurrentExecutionRetentionTTL := int32(2)
×
1826
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
1827
        workflowExecution := types.WorkflowExecution{
×
1828
                WorkflowID: "update-delete-workflow-test",
×
1829
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
1830
        }
×
1831

×
1832
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1833
        s.NoError(err0)
×
1834
        s.NotNil(task0, "Expected non empty task identifier.")
×
1835

×
1836
        runID0, err1 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1837
        s.NoError(err1)
×
1838
        s.Equal(workflowExecution.GetRunID(), runID0)
×
1839

×
1840
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1841
        s.NoError(err2)
×
1842

×
1843
        updatedInfo1 := copyWorkflowExecutionInfo(info0.ExecutionInfo)
×
1844
        updatedStats1 := copyExecutionStats(info0.ExecutionStats)
×
1845
        updatedInfo1.NextEventID = int64(6)
×
1846
        updatedInfo1.LastProcessedEvent = int64(2)
×
1847
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1848
                {
×
1849
                        EventID: updatedInfo1.LastProcessedEvent,
×
1850
                        Version: common.EmptyVersion,
×
1851
                },
×
1852
        })
×
1853
        versionHistories := p.NewVersionHistories(versionHistory)
×
1854
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(3), versionHistories)
×
1855
        s.NoError(err3)
×
1856

×
1857
        runID4, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1858
        s.NoError(err4)
×
1859
        s.Equal(workflowExecution.GetRunID(), runID4)
×
1860

×
1861
        // simulate a timer_task deleting execution after retention
×
1862
        err5 := s.DeleteCurrentWorkflowExecution(ctx, info0.ExecutionInfo)
×
1863
        s.NoError(err5)
×
1864
        err6 := s.DeleteWorkflowExecution(ctx, info0.ExecutionInfo)
×
1865
        s.NoError(err6)
×
1866

×
1867
        time.Sleep(time.Duration(finishedCurrentExecutionRetentionTTL*2) * time.Second)
×
1868

×
1869
        runID0, err1 = s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1870
        s.Error(err1)
×
1871
        s.Empty(runID0)
×
1872
        _, ok := err1.(*types.EntityNotExistsError)
×
1873
        s.True(ok)
×
1874

×
1875
        // execution record should still be there
×
1876
        _, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1877
        s.Error(err2)
×
1878
        _, ok = err2.(*types.EntityNotExistsError)
×
1879
        s.True(ok)
×
1880
}
×
1881

1882
// TestCleanupCorruptedWorkflow test
1883
func (s *ExecutionManagerSuite) TestCleanupCorruptedWorkflow() {
×
1884
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1885
        defer cancel()
×
1886

×
1887
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
1888
        workflowExecution := types.WorkflowExecution{
×
1889
                WorkflowID: "cleanup-corrupted-workflow-test",
×
1890
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
1891
        }
×
1892

×
1893
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1894
        s.NoError(err0)
×
1895
        s.NotNil(task0, "Expected non empty task identifier.")
×
1896

×
1897
        runID0, err1 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1898
        s.NoError(err1)
×
1899
        s.Equal(workflowExecution.GetRunID(), runID0)
×
1900

×
1901
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1902
        s.NoError(err2)
×
1903

×
1904
        // deleting current record and verify
×
1905
        err3 := s.DeleteCurrentWorkflowExecution(ctx, info0.ExecutionInfo)
×
1906
        s.NoError(err3)
×
1907
        runID0, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1908
        s.Error(err4)
×
1909
        s.Empty(runID0)
×
1910
        _, ok := err4.(*types.EntityNotExistsError)
×
1911
        s.True(ok)
×
1912

×
1913
        // we should still be able to load with runID
×
1914
        info1, err5 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1915
        s.NoError(err5)
×
1916
        s.Equal(info0, info1)
×
1917

×
1918
        // mark it as corrupted
×
1919
        info0.ExecutionInfo.State = p.WorkflowStateCorrupted
×
1920
        _, err6 := s.ExecutionManager.UpdateWorkflowExecution(ctx, &p.UpdateWorkflowExecutionRequest{
×
1921
                UpdateWorkflowMutation: p.WorkflowMutation{
×
1922
                        ExecutionInfo:    info0.ExecutionInfo,
×
1923
                        ExecutionStats:   info0.ExecutionStats,
×
1924
                        Condition:        info0.ExecutionInfo.NextEventID,
×
1925
                        Checksum:         testWorkflowChecksum,
×
1926
                        VersionHistories: info0.VersionHistories,
×
1927
                },
×
1928
                RangeID: s.ShardInfo.RangeID,
×
1929
                Mode:    p.UpdateWorkflowModeBypassCurrent,
×
1930
        })
×
1931
        s.NoError(err6)
×
1932

×
1933
        // we should still be able to load with runID
×
1934
        info2, err7 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1935
        s.NoError(err7)
×
1936
        s.Equal(p.WorkflowStateCorrupted, info2.ExecutionInfo.State)
×
1937
        info2.ExecutionInfo.State = info1.ExecutionInfo.State
×
1938
        info2.ExecutionInfo.LastUpdatedTimestamp = info1.ExecutionInfo.LastUpdatedTimestamp
×
1939
        s.Equal(info2, info1)
×
1940

×
1941
        //delete the run
×
1942
        err8 := s.DeleteWorkflowExecution(ctx, info0.ExecutionInfo)
×
1943
        s.NoError(err8)
×
1944

×
1945
        // execution record should be gone
×
1946
        _, err9 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1947
        s.Error(err9)
×
1948
        _, ok = err9.(*types.EntityNotExistsError)
×
1949
        s.True(ok)
×
1950
}
×
1951

1952
// TestGetCurrentWorkflow test
1953
func (s *ExecutionManagerSuite) TestGetCurrentWorkflow() {
×
1954
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
1955
        defer cancel()
×
1956

×
1957
        domainID := "54d15308-e20e-4b91-a00f-a518a3892790"
×
1958
        workflowExecution := types.WorkflowExecution{
×
1959
                WorkflowID: "get-current-workflow-test",
×
1960
                RunID:      "6cae4054-6ba7-46d3-8755-e3c2db6f74ea",
×
1961
        }
×
1962

×
1963
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
1964
        s.NoError(err0)
×
1965
        s.NotNil(task0, "Expected non empty task identifier.")
×
1966

×
1967
        response, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
1968
                DomainID:   domainID,
×
1969
                WorkflowID: workflowExecution.GetWorkflowID(),
×
1970
        })
×
1971
        s.NoError(err)
×
1972
        s.Equal(workflowExecution.GetRunID(), response.RunID)
×
1973
        s.Equal(common.EmptyVersion, response.LastWriteVersion)
×
1974

×
1975
        info0, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
1976
        s.NoError(err2)
×
1977

×
1978
        updatedInfo1 := copyWorkflowExecutionInfo(info0.ExecutionInfo)
×
1979
        updatedStats1 := copyExecutionStats(info0.ExecutionStats)
×
1980
        updatedInfo1.NextEventID = int64(6)
×
1981
        updatedInfo1.LastProcessedEvent = int64(2)
×
1982
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
1983
                {
×
1984
                        EventID: updatedInfo1.LastProcessedEvent,
×
1985
                        Version: common.EmptyVersion,
×
1986
                },
×
1987
        })
×
1988
        versionHistories := p.NewVersionHistories(versionHistory)
×
1989
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(3), versionHistories)
×
1990
        s.NoError(err3)
×
1991

×
1992
        runID4, err4 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
1993
        s.NoError(err4)
×
1994
        s.Equal(workflowExecution.GetRunID(), runID4)
×
1995

×
1996
        workflowExecution2 := types.WorkflowExecution{
×
1997
                WorkflowID: "get-current-workflow-test",
×
1998
                RunID:      "c3ff4bc6-de18-4643-83b2-037a33f45322",
×
1999
        }
×
2000

×
2001
        task1, err5 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution2, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2002
        s.Error(err5, "Error expected.")
×
2003
        s.Empty(task1, "Expected empty task identifier.")
×
2004
}
×
2005

2006
// TestTransferTasksThroughUpdate test
2007
func (s *ExecutionManagerSuite) TestTransferTasksThroughUpdate() {
×
2008
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2009
        defer cancel()
×
2010

×
2011
        domainID := "b785a8ba-bd7d-4760-bb05-41b115f3e10a"
×
2012
        workflowExecution := types.WorkflowExecution{
×
2013
                WorkflowID: "get-transfer-tasks-through-update-test",
×
2014
                RunID:      "30a9fa1f-0db1-4d7a-8c34-aa82c5dad3aa",
×
2015
        }
×
2016

×
2017
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2018
        s.NoError(err0)
×
2019
        s.NotNil(task0, "Expected non empty task identifier.")
×
2020

×
2021
        tasks1, err1 := s.GetTransferTasks(ctx, 1, false)
×
2022
        s.NoError(err1)
×
2023
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2024
        s.Equal(1, len(tasks1), "Expected 1 decision task.")
×
2025
        task1 := tasks1[0]
×
2026
        s.Equal(domainID, task1.DomainID)
×
2027
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2028
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2029
        s.Equal("queue1", task1.TaskList)
×
2030
        s.Equal(p.TransferTaskTypeDecisionTask, task1.TaskType)
×
2031
        s.Equal(int64(2), task1.ScheduleID)
×
2032
        s.Equal("", task1.TargetRunID)
×
2033

×
2034
        err3 := s.CompleteTransferTask(ctx, task1.TaskID)
×
2035
        s.NoError(err3)
×
2036

×
2037
        state0, err11 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2038
        s.NoError(err11)
×
2039
        info0 := state0.ExecutionInfo
×
2040
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2041
        updatedStats0 := copyExecutionStats(state0.ExecutionStats)
×
2042
        updatedInfo.NextEventID = int64(5)
×
2043
        updatedInfo.LastProcessedEvent = int64(2)
×
2044
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2045
                {
×
2046
                        EventID: updatedInfo.LastProcessedEvent,
×
2047
                        Version: common.EmptyVersion,
×
2048
                },
×
2049
        })
×
2050
        versionHistories := p.NewVersionHistories(versionHistory)
×
2051
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats0, versionHistories, nil, []int64{int64(4)}, int64(3), nil, nil, nil, nil, nil)
×
2052
        s.NoError(err2)
×
2053

×
2054
        tasks2, err1 := s.GetTransferTasks(ctx, 1, false)
×
2055
        s.NoError(err1)
×
2056
        s.NotNil(tasks2, "expected valid list of tasks.")
×
2057
        s.Equal(1, len(tasks2), "Expected 1 decision task.")
×
2058
        task2 := tasks2[0]
×
2059
        s.Equal(domainID, task2.DomainID)
×
2060
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
2061
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
2062
        s.Equal("queue1", task2.TaskList)
×
2063
        s.Equal(p.TransferTaskTypeActivityTask, task2.TaskType)
×
2064
        s.Equal(int64(4), task2.ScheduleID)
×
2065
        s.Equal("", task2.TargetRunID)
×
2066

×
2067
        err4 := s.CompleteTransferTask(ctx, task2.TaskID)
×
2068
        s.NoError(err4)
×
2069

×
2070
        state1, _ := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2071
        info1 := state1.ExecutionInfo
×
2072
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2073
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2074
        updatedInfo1.NextEventID = int64(6)
×
2075
        updatedInfo1.LastProcessedEvent = int64(2)
×
2076
        err5 := s.UpdateWorkflowExecutionAndFinish(ctx, updatedInfo1, updatedStats1, int64(5), versionHistories)
×
2077
        s.NoError(err5)
×
2078

×
2079
        newExecution := types.WorkflowExecution{
×
2080
                WorkflowID: workflowExecution.GetWorkflowID(),
×
2081
                RunID:      "2a038c8f-b575-4151-8d2c-d443e999ab5a",
×
2082
        }
×
2083
        runID6, err6 := s.GetCurrentWorkflowRunID(ctx, domainID, newExecution.GetWorkflowID())
×
2084
        s.NoError(err6)
×
2085
        s.Equal(workflowExecution.GetRunID(), runID6)
×
2086

×
2087
        tasks3, err7 := s.GetTransferTasks(ctx, 1, false)
×
2088
        s.NoError(err7)
×
2089
        s.NotNil(tasks3, "expected valid list of tasks.")
×
2090
        s.Equal(1, len(tasks3), "Expected 1 decision task.")
×
2091
        task3 := tasks3[0]
×
2092
        s.Equal(domainID, task3.DomainID)
×
2093
        s.Equal(workflowExecution.GetWorkflowID(), task3.WorkflowID)
×
2094
        s.Equal(workflowExecution.GetRunID(), task3.RunID)
×
2095
        s.Equal(p.TransferTaskTypeCloseExecution, task3.TaskType)
×
2096
        s.Equal("", task3.TargetRunID)
×
2097

×
2098
        err8 := s.CompleteTransferTask(ctx, task3.TaskID)
×
2099
        s.NoError(err8)
×
2100

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

×
2104
        err10 := s.DeleteWorkflowExecution(ctx, info1)
×
2105
        s.NoError(err10)
×
2106
}
×
2107

2108
// TestCancelTransferTaskTasks test
2109
func (s *ExecutionManagerSuite) TestCancelTransferTaskTasks() {
×
2110
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2111
        defer cancel()
×
2112

×
2113
        domainID := "aeac8287-527b-4b35-80a9-667cb47e7c6d"
×
2114
        workflowExecution := types.WorkflowExecution{
×
2115
                WorkflowID: "cancel-workflow-test",
×
2116
                RunID:      "db20f7e2-1a1e-40d9-9278-d8b886738e05",
×
2117
        }
×
2118

×
2119
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2120
        s.NoError(err)
×
2121
        s.NotNil(task0, "Expected non empty task identifier.")
×
2122

×
2123
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
2124
        s.NoError(err)
×
2125
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
2126
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
2127
        s.NoError(err)
×
2128

×
2129
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2130
        s.NoError(err)
×
2131
        info1 := state1.ExecutionInfo
×
2132
        s.NotNil(info1, "Valid Workflow info expected.")
×
2133
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2134
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2135

×
2136
        targetDomainID := "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2137
        targetWorkflowID := "target-workflow-cancellation-id-1"
×
2138
        targetRunID := "0d00698f-08e1-4d36-a3e2-3bf109f5d2d6"
×
2139
        targetChildWorkflowOnly := false
×
2140
        transferTasks := []p.Task{&p.CancelExecutionTask{
×
2141
                TaskID:                  s.GetNextSequenceNumber(),
×
2142
                TargetDomainID:          targetDomainID,
×
2143
                TargetWorkflowID:        targetWorkflowID,
×
2144
                TargetRunID:             targetRunID,
×
2145
                TargetChildWorkflowOnly: targetChildWorkflowOnly,
×
2146
                InitiatedID:             1,
×
2147
        }}
×
2148
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2149
                {
×
2150
                        EventID: 1,
×
2151
                        Version: common.EmptyVersion,
×
2152
                },
×
2153
        })
×
2154
        versionHistories := p.NewVersionHistories(versionHistory)
×
2155
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo1, updatedStats1, int64(3), transferTasks, nil, versionHistories)
×
2156
        s.NoError(err)
×
2157

×
2158
        tasks1, err := s.GetTransferTasks(ctx, 1, false)
×
2159
        s.NoError(err)
×
2160
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2161
        s.Equal(1, len(tasks1), "Expected 1 cancel task.")
×
2162
        task1 := tasks1[0]
×
2163
        s.Equal(p.TransferTaskTypeCancelExecution, task1.TaskType)
×
2164
        s.Equal(domainID, task1.DomainID)
×
2165
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2166
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2167
        s.Equal(targetDomainID, task1.TargetDomainID)
×
2168
        s.Equal(targetWorkflowID, task1.TargetWorkflowID)
×
2169
        s.Equal(targetRunID, task1.TargetRunID)
×
2170
        s.Equal(false, task1.TargetChildWorkflowOnly)
×
2171

×
2172
        err = s.CompleteTransferTask(ctx, task1.TaskID)
×
2173
        s.NoError(err)
×
2174

×
2175
        targetDomainID = "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2176
        targetWorkflowID = "target-workflow-cancellation-id-2"
×
2177
        targetRunID = ""
×
2178
        targetChildWorkflowOnly = true
×
2179
        transferTasks = []p.Task{&p.CancelExecutionTask{
×
2180
                TaskID:                  s.GetNextSequenceNumber(),
×
2181
                TargetDomainID:          targetDomainID,
×
2182
                TargetWorkflowID:        targetWorkflowID,
×
2183
                TargetRunID:             targetRunID,
×
2184
                TargetChildWorkflowOnly: targetChildWorkflowOnly,
×
2185
                InitiatedID:             3,
×
2186
        }}
×
2187

×
2188
        state2, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2189
        s.NoError(err)
×
2190
        info2 := state2.ExecutionInfo
×
2191
        s.NotNil(info2, "Valid Workflow info expected.")
×
2192
        updatedInfo2 := copyWorkflowExecutionInfo(info2)
×
2193
        updatedStats2 := copyExecutionStats(state2.ExecutionStats)
×
2194

×
2195
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo2, updatedStats2, int64(3), transferTasks, nil, versionHistories)
×
2196
        s.NoError(err)
×
2197

×
2198
        tasks2, err := s.GetTransferTasks(ctx, 1, false)
×
2199
        s.NoError(err)
×
2200
        s.NotNil(tasks2, "expected valid list of tasks.")
×
2201
        s.Equal(1, len(tasks2), "Expected 1 cancel task.")
×
2202
        task2 := tasks2[0]
×
2203
        s.Equal(p.TransferTaskTypeCancelExecution, task2.TaskType)
×
2204
        s.Equal(domainID, task2.DomainID)
×
2205
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
2206
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
2207
        s.Equal(targetDomainID, task2.TargetDomainID)
×
2208
        s.Equal(targetWorkflowID, task2.TargetWorkflowID)
×
2209
        s.Equal(targetRunID, task2.TargetRunID)
×
2210
        s.Equal(targetChildWorkflowOnly, task2.TargetChildWorkflowOnly)
×
2211

×
2212
        err = s.CompleteTransferTask(ctx, task2.TaskID)
×
2213
        s.NoError(err)
×
2214
}
×
2215

2216
// TestSignalTransferTaskTasks test
2217
func (s *ExecutionManagerSuite) TestSignalTransferTaskTasks() {
×
2218
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2219
        defer cancel()
×
2220

×
2221
        domainID := "aeac8287-527b-4b35-80a9-667cb47e7c6d"
×
2222
        workflowExecution := types.WorkflowExecution{
×
2223
                WorkflowID: "signal-workflow-test",
×
2224
                RunID:      "db20f7e2-1a1e-40d9-9278-d8b886738e05",
×
2225
        }
×
2226

×
2227
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2228
        s.NoError(err)
×
2229
        s.NotNil(task0, "Expected non empty task identifier.")
×
2230

×
2231
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
2232
        s.NoError(err)
×
2233
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
2234
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
2235
        s.NoError(err)
×
2236

×
2237
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2238
        s.NoError(err)
×
2239
        info1 := state1.ExecutionInfo
×
2240
        s.NotNil(info1, "Valid Workflow info expected.")
×
2241
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2242
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2243

×
2244
        targetDomainID := "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2245
        targetWorkflowID := "target-workflow-signal-id-1"
×
2246
        targetRunID := "0d00698f-08e1-4d36-a3e2-3bf109f5d2d6"
×
2247
        targetChildWorkflowOnly := false
×
2248
        transferTasks := []p.Task{&p.SignalExecutionTask{
×
2249
                TaskID:                  s.GetNextSequenceNumber(),
×
2250
                TargetDomainID:          targetDomainID,
×
2251
                TargetWorkflowID:        targetWorkflowID,
×
2252
                TargetRunID:             targetRunID,
×
2253
                TargetChildWorkflowOnly: false,
×
2254
                InitiatedID:             1,
×
2255
        }}
×
2256
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2257
                {
×
2258
                        EventID: 1,
×
2259
                        Version: common.EmptyVersion,
×
2260
                },
×
2261
        })
×
2262
        versionHistories := p.NewVersionHistories(versionHistory)
×
2263
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo1, updatedStats1, int64(3), transferTasks, nil, versionHistories)
×
2264
        s.NoError(err)
×
2265

×
2266
        tasks1, err := s.GetTransferTasks(ctx, 1, false)
×
2267
        s.NoError(err)
×
2268
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2269
        s.Equal(1, len(tasks1), "Expected 1 cancel task.")
×
2270
        task1 := tasks1[0]
×
2271
        s.Equal(p.TransferTaskTypeSignalExecution, task1.TaskType)
×
2272
        s.Equal(domainID, task1.DomainID)
×
2273
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2274
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2275
        s.Equal(targetDomainID, task1.TargetDomainID)
×
2276
        s.Equal(targetWorkflowID, task1.TargetWorkflowID)
×
2277
        s.Equal(targetRunID, task1.TargetRunID)
×
2278
        s.Equal(false, task1.TargetChildWorkflowOnly)
×
2279

×
2280
        err = s.CompleteTransferTask(ctx, task1.TaskID)
×
2281
        s.NoError(err)
×
2282

×
2283
        targetDomainID = "f2bfaab6-7e8b-4fac-9a62-17da8d37becb"
×
2284
        targetWorkflowID = "target-workflow-signal-id-2"
×
2285
        targetRunID = ""
×
2286
        targetChildWorkflowOnly = true
×
2287
        transferTasks = []p.Task{&p.SignalExecutionTask{
×
2288
                TaskID:                  s.GetNextSequenceNumber(),
×
2289
                TargetDomainID:          targetDomainID,
×
2290
                TargetWorkflowID:        targetWorkflowID,
×
2291
                TargetRunID:             targetRunID,
×
2292
                TargetChildWorkflowOnly: targetChildWorkflowOnly,
×
2293
                InitiatedID:             3,
×
2294
        }}
×
2295

×
2296
        state2, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2297
        s.NoError(err)
×
2298
        info2 := state2.ExecutionInfo
×
2299
        s.NotNil(info2, "Valid Workflow info expected.")
×
2300
        updatedInfo2 := copyWorkflowExecutionInfo(info2)
×
2301
        updatedStats2 := copyExecutionStats(state2.ExecutionStats)
×
2302

×
2303
        err = s.UpdateWorkflowExecutionWithTransferTasks(ctx, updatedInfo2, updatedStats2, int64(3), transferTasks, nil, versionHistories)
×
2304
        s.NoError(err)
×
2305

×
2306
        tasks2, err := s.GetTransferTasks(ctx, 1, false)
×
2307
        s.NoError(err)
×
2308
        s.NotNil(tasks2, "expected valid list of tasks.")
×
2309
        s.Equal(1, len(tasks2), "Expected 1 cancel task.")
×
2310
        task2 := tasks2[0]
×
2311
        s.Equal(p.TransferTaskTypeSignalExecution, task2.TaskType)
×
2312
        s.Equal(domainID, task2.DomainID)
×
2313
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
2314
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
2315
        s.Equal(targetDomainID, task2.TargetDomainID)
×
2316
        s.Equal(targetWorkflowID, task2.TargetWorkflowID)
×
2317
        s.Equal(targetRunID, task2.TargetRunID)
×
2318
        s.Equal(targetChildWorkflowOnly, task2.TargetChildWorkflowOnly)
×
2319

×
2320
        err = s.CompleteTransferTask(ctx, task2.TaskID)
×
2321
        s.NoError(err)
×
2322
}
×
2323

2324
// TestReplicationTasks test
2325
func (s *ExecutionManagerSuite) TestReplicationTasks() {
×
2326
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2327
        defer cancel()
×
2328

×
2329
        domainID := "2466d7de-6602-4ad8-b939-fb8f8c36c711"
×
2330
        workflowExecution := types.WorkflowExecution{
×
2331
                WorkflowID: "get-replication-tasks-test",
×
2332
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2333
        }
×
2334

×
2335
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2336
        s.NoError(err)
×
2337
        s.NotNil(task0, "Expected non empty task identifier.")
×
2338
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
2339
        s.NoError(err)
×
2340
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
2341
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
2342
        s.NoError(err)
×
2343

×
2344
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2345
        s.NoError(err)
×
2346
        info1 := state1.ExecutionInfo
×
2347
        s.NotNil(info1, "Valid Workflow info expected.")
×
2348
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2349
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2350

×
2351
        replicationTasks := []p.Task{
×
2352
                &p.HistoryReplicationTask{
×
2353
                        TaskID:       s.GetNextSequenceNumber(),
×
2354
                        FirstEventID: int64(1),
×
2355
                        NextEventID:  int64(3),
×
2356
                        Version:      123,
×
2357
                },
×
2358
                &p.HistoryReplicationTask{
×
2359
                        TaskID:       s.GetNextSequenceNumber(),
×
2360
                        FirstEventID: int64(1),
×
2361
                        NextEventID:  int64(3),
×
2362
                        Version:      456,
×
2363
                },
×
2364
                &p.SyncActivityTask{
×
2365
                        TaskID:      s.GetNextSequenceNumber(),
×
2366
                        Version:     789,
×
2367
                        ScheduledID: 99,
×
2368
                },
×
2369
        }
×
2370
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2371
                {
×
2372
                        EventID: 3,
×
2373
                        Version: common.EmptyVersion,
×
2374
                },
×
2375
        })
×
2376
        versionHistories := p.NewVersionHistories(versionHistory)
×
2377
        err = s.UpdateWorklowStateAndReplication(ctx, updatedInfo1, updatedStats1, versionHistories, int64(3), replicationTasks)
×
2378
        s.NoError(err)
×
2379

×
2380
        respTasks, err := s.GetReplicationTasks(ctx, 1, true)
×
2381
        s.NoError(err)
×
2382
        s.Equal(len(replicationTasks), len(respTasks))
×
2383

×
2384
        for index := range replicationTasks {
×
2385
                s.Equal(replicationTasks[index].GetTaskID(), respTasks[index].GetTaskID())
×
2386
                s.Equal(replicationTasks[index].GetType(), respTasks[index].GetTaskType())
×
2387
                s.Equal(replicationTasks[index].GetVersion(), respTasks[index].GetVersion())
×
2388
                switch replicationTasks[index].GetType() {
×
2389
                case p.ReplicationTaskTypeHistory:
×
2390
                        expected := replicationTasks[index].(*p.HistoryReplicationTask)
×
2391
                        s.Equal(expected.FirstEventID, respTasks[index].FirstEventID)
×
2392
                        s.Equal(expected.NextEventID, respTasks[index].NextEventID)
×
2393
                        s.Equal(expected.BranchToken, respTasks[index].BranchToken)
×
2394
                        s.Equal(expected.NewRunBranchToken, respTasks[index].NewRunBranchToken)
×
2395
                case p.ReplicationTaskTypeSyncActivity:
×
2396
                        expected := replicationTasks[index].(*p.SyncActivityTask)
×
2397
                        s.Equal(expected.ScheduledID, respTasks[index].ScheduledID)
×
2398
                }
2399
                err = s.CompleteReplicationTask(ctx, respTasks[index].GetTaskID())
×
2400
                s.NoError(err)
×
2401
        }
2402
}
2403

2404
// TestCrossClusterTasks test
2405
func (s *ExecutionManagerSuite) TestCrossClusterTasks() {
×
2406
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2407
        defer cancel()
×
2408

×
2409
        domainID := "5ab207b4-7422-4bc0-a6e4-e677b1b7d5d2"
×
2410
        workflowExecution := types.WorkflowExecution{
×
2411
                WorkflowID: "cross-cluster-tasks-test",
×
2412
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2413
        }
×
2414

×
2415
        resp, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2416
        s.NoError(err)
×
2417
        s.NotNil(resp, "Expected non empty task identifier.")
×
2418

×
2419
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2420
        s.NoError(err)
×
2421
        info1 := state1.ExecutionInfo
×
2422
        s.NotNil(info1, "Valid Workflow info expected.")
×
2423
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
2424
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
2425

×
2426
        remoteClusterName1 := "remote-cluster-1"
×
2427
        remoteClusterName2 := "remote-cluster-2"
×
2428
        now := time.Now()
×
2429
        crossClusterTasks1 := []p.Task{
×
2430
                &p.CrossClusterStartChildExecutionTask{
×
2431
                        TargetCluster: remoteClusterName1,
×
2432
                        StartChildExecutionTask: p.StartChildExecutionTask{
×
2433
                                VisibilityTimestamp: now,
×
2434
                                TaskID:              s.GetNextSequenceNumber(),
×
2435
                                TargetDomainID:      uuid.New(),
×
2436
                                TargetWorkflowID:    "target workflow 1",
×
2437
                                InitiatedID:         5,
×
2438
                                Version:             123,
×
2439
                        },
×
2440
                },
×
2441
                &p.CrossClusterSignalExecutionTask{
×
2442
                        TargetCluster: remoteClusterName1,
×
2443
                        SignalExecutionTask: p.SignalExecutionTask{
×
2444
                                VisibilityTimestamp:     now,
×
2445
                                TaskID:                  s.GetNextSequenceNumber(),
×
2446
                                TargetDomainID:          uuid.New(),
×
2447
                                TargetWorkflowID:        "target workflowID 2",
×
2448
                                TargetRunID:             uuid.New(),
×
2449
                                TargetChildWorkflowOnly: true,
×
2450
                                InitiatedID:             6,
×
2451
                                Version:                 123,
×
2452
                        },
×
2453
                },
×
2454
        }
×
2455
        crossClusterTasks2 := []p.Task{
×
2456
                &p.CrossClusterCancelExecutionTask{
×
2457
                        TargetCluster: remoteClusterName2,
×
2458
                        CancelExecutionTask: p.CancelExecutionTask{
×
2459
                                VisibilityTimestamp:     now,
×
2460
                                TaskID:                  s.GetNextSequenceNumber(),
×
2461
                                TargetDomainID:          uuid.New(),
×
2462
                                TargetWorkflowID:        "target workflowID 3",
×
2463
                                TargetRunID:             uuid.New(),
×
2464
                                TargetChildWorkflowOnly: true,
×
2465
                                InitiatedID:             6,
×
2466
                                Version:                 123,
×
2467
                        },
×
2468
                },
×
2469
                &p.CrossClusterRecordChildExecutionCompletedTask{
×
2470
                        TargetCluster: remoteClusterName2,
×
2471
                        RecordChildExecutionCompletedTask: p.RecordChildExecutionCompletedTask{
×
2472
                                VisibilityTimestamp: now,
×
2473
                                TaskID:              s.GetNextSequenceNumber(),
×
2474
                                TargetDomainID:      uuid.New(),
×
2475
                                TargetWorkflowID:    "target workflowID 4",
×
2476
                                TargetRunID:         uuid.New(),
×
2477
                                Version:             123,
×
2478
                        },
×
2479
                },
×
2480
                &p.CrossClusterApplyParentClosePolicyTask{
×
2481
                        TargetCluster: remoteClusterName2,
×
2482
                        ApplyParentClosePolicyTask: p.ApplyParentClosePolicyTask{
×
2483
                                VisibilityTimestamp: now,
×
2484
                                TaskID:              s.GetNextSequenceNumber(),
×
2485
                                TargetDomainIDs:     map[string]struct{}{uuid.New(): {}, uuid.New(): {}},
×
2486
                                Version:             123,
×
2487
                        },
×
2488
                },
×
2489
        }
×
2490
        crossClusterTasks := append(crossClusterTasks1, crossClusterTasks2...)
×
2491

×
2492
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2493
                {
×
2494
                        EventID: 3,
×
2495
                        Version: common.EmptyVersion,
×
2496
                },
×
2497
        })
×
2498
        versionHistories := p.NewVersionHistories(versionHistory)
×
2499
        err = s.UpdateWorklowStateAndReplication(ctx, updatedInfo1, updatedStats1, versionHistories, int64(3), crossClusterTasks)
×
2500
        s.NoError(err)
×
2501

×
2502
        // check created tasks for cluster 1
×
2503
        respTasks, err := s.GetCrossClusterTasks(ctx, remoteClusterName1, 0, 1, true)
×
2504
        s.NoError(err)
×
2505
        s.validateCrossClusterTasks(crossClusterTasks1, respTasks)
×
2506

×
2507
        // range delete tasks for cluster 1
×
2508
        err = s.RangeCompleteCrossClusterTask(ctx, remoteClusterName1, respTasks[0].TaskID-1, respTasks[len(respTasks)-1].TaskID)
×
2509
        s.NoError(err)
×
2510
        respTasks, err = s.GetCrossClusterTasks(ctx, remoteClusterName1, 0, 1, true)
×
2511
        s.NoError(err)
×
2512
        s.Empty(respTasks)
×
2513

×
2514
        // check created tasks for cluster 2
×
2515
        respTasks, err = s.GetCrossClusterTasks(ctx, remoteClusterName2, 0, 1, true)
×
2516
        s.NoError(err)
×
2517
        s.validateCrossClusterTasks(crossClusterTasks2, respTasks)
×
2518

×
2519
        // delete tasks for cluster 2
×
2520
        for idx := range respTasks {
×
2521
                err = s.CompleteCrossClusterTask(ctx, remoteClusterName2, respTasks[idx].TaskID)
×
2522
                s.NoError(err)
×
2523
        }
×
2524
        respTasks, err = s.GetCrossClusterTasks(ctx, remoteClusterName2, 0, 1, true)
×
2525
        s.NoError(err)
×
2526
        s.Empty(respTasks)
×
2527
}
2528

2529
func (s *ExecutionManagerSuite) validateCrossClusterTasks(
2530
        tasks []p.Task,
2531
        loadedTaskInfo []*p.CrossClusterTaskInfo,
2532
) {
×
2533
        s.Equal(len(tasks), len(loadedTaskInfo))
×
2534
        for index := range tasks {
×
2535
                s.Equal(tasks[index].GetTaskID(), loadedTaskInfo[index].GetTaskID())
×
2536
                s.Equal(tasks[index].GetType(), loadedTaskInfo[index].GetTaskType())
×
2537
                s.Equal(tasks[index].GetVersion(), loadedTaskInfo[index].GetVersion())
×
2538
                s.EqualTimesWithPrecision(tasks[index].GetVisibilityTimestamp(), loadedTaskInfo[index].GetVisibilityTimestamp(), time.Millisecond)
×
2539
                switch task := tasks[index].(type) {
×
2540
                case *p.CrossClusterStartChildExecutionTask:
×
2541
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2542
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2543
                        s.Equal(task.InitiatedID, loadedTaskInfo[index].ScheduleID)
×
2544
                case *p.CrossClusterSignalExecutionTask:
×
2545
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2546
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2547
                        s.Equal(task.TargetRunID, loadedTaskInfo[index].TargetRunID)
×
2548
                        s.Equal(task.TargetChildWorkflowOnly, loadedTaskInfo[index].TargetChildWorkflowOnly)
×
2549
                        s.Equal(task.InitiatedID, loadedTaskInfo[index].ScheduleID)
×
2550
                case *p.CrossClusterCancelExecutionTask:
×
2551
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2552
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2553
                        s.Equal(task.TargetRunID, loadedTaskInfo[index].TargetRunID)
×
2554
                        s.Equal(task.TargetChildWorkflowOnly, loadedTaskInfo[index].TargetChildWorkflowOnly)
×
2555
                        s.Equal(task.InitiatedID, loadedTaskInfo[index].ScheduleID)
×
2556
                case *p.CrossClusterRecordChildExecutionCompletedTask:
×
2557
                        s.Equal(task.TargetDomainID, loadedTaskInfo[index].TargetDomainID)
×
2558
                        s.Equal(task.TargetWorkflowID, loadedTaskInfo[index].TargetWorkflowID)
×
2559
                        s.Equal(task.TargetRunID, loadedTaskInfo[index].TargetRunID)
×
2560
                case *p.CrossClusterApplyParentClosePolicyTask:
×
2561
                        s.Equal(task.TargetDomainIDs, loadedTaskInfo[index].GetTargetDomainIDs())
×
2562
                default:
×
2563
                        s.FailNow("unknown cross cluster task type")
×
2564
                }
2565
        }
2566
}
2567

2568
// TestTransferTasksComplete test
2569
func (s *ExecutionManagerSuite) TestTransferTasksComplete() {
×
2570
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2571
        defer cancel()
×
2572

×
2573
        domainID := "8bfb47be-5b57-4d55-9109-5fb35e20b1d7"
×
2574
        workflowExecution := types.WorkflowExecution{
×
2575
                WorkflowID: "get-transfer-tasks-test-complete",
×
2576
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2577
        }
×
2578
        tasklist := "some random tasklist"
×
2579

×
2580
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist, "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2581
        s.NoError(err0)
×
2582
        s.NotNil(task0, "Expected non empty task identifier.")
×
2583

×
2584
        tasks1, err1 := s.GetTransferTasks(ctx, 1, false)
×
2585
        s.NoError(err1)
×
2586
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2587
        s.Equal(1, len(tasks1), "Expected 1 decision task.")
×
2588
        task1 := tasks1[0]
×
2589
        s.Equal(domainID, task1.DomainID)
×
2590
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2591
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2592
        s.Equal(tasklist, task1.TaskList)
×
2593
        s.Equal(p.TransferTaskTypeDecisionTask, task1.TaskType)
×
2594
        s.Equal(int64(2), task1.ScheduleID)
×
2595
        s.Equal(p.TransferTaskTransferTargetWorkflowID, task1.TargetWorkflowID)
×
2596
        s.Equal("", task1.TargetRunID)
×
2597
        err3 := s.CompleteTransferTask(ctx, task1.TaskID)
×
2598
        s.NoError(err3)
×
2599

×
2600
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2601
        s.NoError(err1)
×
2602
        info0 := state0.ExecutionInfo
×
2603
        s.NotNil(info0, "Valid Workflow info expected.")
×
2604

×
2605
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2606
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
2607
        updatedInfo.NextEventID = int64(6)
×
2608
        updatedInfo.LastProcessedEvent = int64(2)
×
2609
        scheduleID := int64(123)
×
2610
        targetDomainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d0"
×
2611
        targetWorkflowID := "some random target domain ID"
×
2612
        targetRunID := uuid.New()
×
2613
        currentTransferID := task1.TaskID
×
2614
        now := time.Now()
×
2615
        tasks := []p.Task{
×
2616
                &p.ActivityTask{now, currentTransferID + 10001, domainID, tasklist, scheduleID, 111},
×
2617
                &p.DecisionTask{now, currentTransferID + 10002, domainID, tasklist, scheduleID, 222, false},
×
2618
                &p.CloseExecutionTask{now, currentTransferID + 10003, 333},
×
2619
                &p.CancelExecutionTask{now, currentTransferID + 10004, targetDomainID, targetWorkflowID, targetRunID, true, scheduleID, 444},
×
2620
                &p.SignalExecutionTask{now, currentTransferID + 10005, targetDomainID, targetWorkflowID, targetRunID, true, scheduleID, 555},
×
2621
                &p.StartChildExecutionTask{now, currentTransferID + 10006, targetDomainID, targetWorkflowID, scheduleID, 666},
×
2622
                &p.RecordWorkflowClosedTask{now, currentTransferID + 10007, 777},
×
2623
                &p.RecordChildExecutionCompletedTask{now, currentTransferID + 10008, targetDomainID, targetWorkflowID, targetRunID, 888},
×
2624
                &p.ApplyParentClosePolicyTask{now, currentTransferID + 10009, map[string]struct{}{targetDomainID: {}}, 999},
×
2625
        }
×
2626
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2627
                {
×
2628
                        EventID: scheduleID,
×
2629
                        Version: common.EmptyVersion,
×
2630
                },
×
2631
        })
×
2632
        versionHistories := p.NewVersionHistories(versionHistory)
×
2633
        err2 := s.UpdateWorklowStateAndReplication(ctx, updatedInfo, updatedStats, versionHistories, int64(3), tasks)
×
2634
        s.NoError(err2)
×
2635

×
2636
        txTasks, err1 := s.GetTransferTasks(ctx, 1, true) // use page size one to force pagination
×
2637
        s.NoError(err1)
×
2638
        s.NotNil(txTasks, "expected valid list of tasks.")
×
2639
        s.Equal(len(tasks), len(txTasks))
×
2640
        for index := range tasks {
×
2641
                s.True(timeComparator(tasks[index].GetVisibilityTimestamp(), txTasks[index].VisibilityTimestamp, TimePrecision))
×
2642
        }
×
2643
        s.Equal(p.TransferTaskTypeActivityTask, txTasks[0].TaskType)
×
2644
        s.Equal(p.TransferTaskTypeDecisionTask, txTasks[1].TaskType)
×
2645
        s.Equal(p.TransferTaskTypeCloseExecution, txTasks[2].TaskType)
×
2646
        s.Equal(p.TransferTaskTypeCancelExecution, txTasks[3].TaskType)
×
2647
        s.Equal(p.TransferTaskTypeSignalExecution, txTasks[4].TaskType)
×
2648
        s.Equal(p.TransferTaskTypeStartChildExecution, txTasks[5].TaskType)
×
2649
        s.Equal(p.TransferTaskTypeRecordWorkflowClosed, txTasks[6].TaskType)
×
2650
        s.Equal(p.TransferTaskTypeRecordChildExecutionCompleted, txTasks[7].TaskType)
×
2651
        s.Equal(p.TransferTaskTypeApplyParentClosePolicy, txTasks[8].TaskType)
×
2652

×
2653
        for idx := range txTasks {
×
2654
                // TODO: add a check similar to validateCrossClusterTasks
×
2655
                s.Equal(int64(111*(idx+1)), txTasks[idx].Version)
×
2656
                err := s.CompleteTransferTask(ctx, txTasks[idx].TaskID)
×
2657
                s.NoError(err)
×
2658
        }
×
2659

2660
        txTasks, err2 = s.GetTransferTasks(ctx, 100, false)
×
2661
        s.NoError(err2)
×
2662
        s.Empty(txTasks, "expected empty task list.")
×
2663
}
2664

2665
// TestTransferTasksRangeComplete test
2666
func (s *ExecutionManagerSuite) TestTransferTasksRangeComplete() {
×
2667
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2668
        defer cancel()
×
2669

×
2670
        domainID := "8bfb47be-5b57-4d55-9109-5fb35e20b1d7"
×
2671
        workflowExecution := types.WorkflowExecution{
×
2672
                WorkflowID: "get-transfer-tasks-test-range-complete",
×
2673
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2674
        }
×
2675
        tasklist := "some random tasklist"
×
2676

×
2677
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, tasklist, "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2678
        s.NoError(err0)
×
2679
        s.NotNil(task0, "Expected non empty task identifier.")
×
2680

×
2681
        tasks1, err1 := s.GetTransferTasks(ctx, 1, false)
×
2682
        s.NoError(err1)
×
2683
        s.NotNil(tasks1, "expected valid list of tasks.")
×
2684
        s.Equal(1, len(tasks1), "Expected 1 decision task.")
×
2685
        task1 := tasks1[0]
×
2686
        s.Equal(domainID, task1.DomainID)
×
2687
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
2688
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
2689
        s.Equal(tasklist, task1.TaskList)
×
2690
        s.Equal(p.TransferTaskTypeDecisionTask, task1.TaskType)
×
2691
        s.Equal(int64(2), task1.ScheduleID)
×
2692
        s.Equal(p.TransferTaskTransferTargetWorkflowID, task1.TargetWorkflowID)
×
2693
        s.Equal("", task1.TargetRunID)
×
2694
        err3 := s.CompleteTransferTask(ctx, task1.TaskID)
×
2695
        s.NoError(err3)
×
2696

×
2697
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2698
        s.NoError(err1)
×
2699
        info0 := state0.ExecutionInfo
×
2700
        s.NotNil(info0, "Valid Workflow info expected.")
×
2701

×
2702
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2703
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
2704
        updatedInfo.NextEventID = int64(6)
×
2705
        updatedInfo.LastProcessedEvent = int64(2)
×
2706
        scheduleID := int64(123)
×
2707
        targetDomainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d0"
×
2708
        targetWorkflowID := "some random target domain ID"
×
2709
        targetRunID := uuid.New()
×
2710
        currentTransferID := task1.TaskID
×
2711
        now := time.Now()
×
2712
        tasks := []p.Task{
×
2713
                &p.ActivityTask{now, currentTransferID + 10001, domainID, tasklist, scheduleID, 111},
×
2714
                &p.DecisionTask{now, currentTransferID + 10002, domainID, tasklist, scheduleID, 222, false},
×
2715
                &p.CloseExecutionTask{now, currentTransferID + 10003, 333},
×
2716
                &p.CancelExecutionTask{now, currentTransferID + 10004, targetDomainID, targetWorkflowID, targetRunID, true, scheduleID, 444},
×
2717
                &p.SignalExecutionTask{now, currentTransferID + 10005, targetDomainID, targetWorkflowID, targetRunID, true, scheduleID, 555},
×
2718
                &p.StartChildExecutionTask{now, currentTransferID + 10006, targetDomainID, targetWorkflowID, scheduleID, 666},
×
2719
        }
×
2720
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2721
                {
×
2722
                        EventID: scheduleID,
×
2723
                        Version: common.EmptyVersion,
×
2724
                },
×
2725
        })
×
2726
        versionHistories := p.NewVersionHistories(versionHistory)
×
2727
        err2 := s.UpdateWorklowStateAndReplication(ctx, updatedInfo, updatedStats, versionHistories, int64(3), tasks)
×
2728
        s.NoError(err2)
×
2729

×
2730
        txTasks, err1 := s.GetTransferTasks(ctx, 2, true) // use page size one to force pagination
×
2731
        s.NoError(err1)
×
2732
        s.NotNil(txTasks, "expected valid list of tasks.")
×
2733
        s.Equal(len(tasks), len(txTasks))
×
2734
        for index := range tasks {
×
2735
                s.True(timeComparator(tasks[index].GetVisibilityTimestamp(), txTasks[index].VisibilityTimestamp, TimePrecision))
×
2736
        }
×
2737
        s.Equal(p.TransferTaskTypeActivityTask, txTasks[0].TaskType)
×
2738
        s.Equal(p.TransferTaskTypeDecisionTask, txTasks[1].TaskType)
×
2739
        s.Equal(p.TransferTaskTypeCloseExecution, txTasks[2].TaskType)
×
2740
        s.Equal(p.TransferTaskTypeCancelExecution, txTasks[3].TaskType)
×
2741
        s.Equal(p.TransferTaskTypeSignalExecution, txTasks[4].TaskType)
×
2742
        s.Equal(p.TransferTaskTypeStartChildExecution, txTasks[5].TaskType)
×
2743
        s.Equal(int64(111), txTasks[0].Version)
×
2744
        s.Equal(int64(222), txTasks[1].Version)
×
2745
        s.Equal(int64(333), txTasks[2].Version)
×
2746
        s.Equal(int64(444), txTasks[3].Version)
×
2747
        s.Equal(int64(555), txTasks[4].Version)
×
2748
        s.Equal(int64(666), txTasks[5].Version)
×
2749
        s.Equal(currentTransferID+10001, txTasks[0].TaskID)
×
2750
        s.Equal(currentTransferID+10002, txTasks[1].TaskID)
×
2751
        s.Equal(currentTransferID+10003, txTasks[2].TaskID)
×
2752
        s.Equal(currentTransferID+10004, txTasks[3].TaskID)
×
2753
        s.Equal(currentTransferID+10005, txTasks[4].TaskID)
×
2754
        s.Equal(currentTransferID+10006, txTasks[5].TaskID)
×
2755

×
2756
        err2 = s.RangeCompleteTransferTask(ctx, txTasks[0].TaskID-1, txTasks[5].TaskID)
×
2757
        s.NoError(err2)
×
2758

×
2759
        txTasks, err2 = s.GetTransferTasks(ctx, 100, false)
×
2760
        s.NoError(err2)
×
2761
        s.Empty(txTasks, "expected empty task list.")
×
2762
}
2763

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

×
2769
        domainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d7"
×
2770
        workflowExecution := types.WorkflowExecution{
×
2771
                WorkflowID: "get-timer-tasks-test-complete",
×
2772
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2773
        }
×
2774

×
2775
        now := time.Now()
×
2776
        initialTasks := []p.Task{&p.DecisionTimeoutTask{now.Add(1 * time.Second), 1, 2, 3, int(types.TimeoutTypeStartToClose), 11}}
×
2777

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

×
2782
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2783
        s.NoError(err1)
×
2784
        info0 := state0.ExecutionInfo
×
2785
        s.NotNil(info0, "Valid Workflow info expected.")
×
2786

×
2787
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2788
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
2789
        updatedInfo.NextEventID = int64(5)
×
2790
        updatedInfo.LastProcessedEvent = int64(2)
×
2791
        tasks := []p.Task{
×
2792
                &p.WorkflowTimeoutTask{now.Add(2 * time.Second), 2, 12},
×
2793
                &p.DeleteHistoryEventTask{now.Add(2 * time.Second), 3, 13},
×
2794
                &p.ActivityTimeoutTask{now.Add(3 * time.Second), 4, int(types.TimeoutTypeStartToClose), 7, 0, 14},
×
2795
                &p.UserTimerTask{now.Add(3 * time.Second), 5, 7, 15},
×
2796
        }
×
2797
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2798
                {
×
2799
                        EventID: updatedInfo.NextEventID,
×
2800
                        Version: common.EmptyVersion,
×
2801
                },
×
2802
        })
×
2803
        versionHistories := p.NewVersionHistories(versionHistory)
×
2804
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), tasks, nil, nil, nil, nil)
×
2805
        s.NoError(err2)
×
2806

×
2807
        timerTasks, err1 := s.GetTimerIndexTasks(ctx, 1, true) // use page size one to force pagination
×
2808
        s.NoError(err1)
×
2809
        s.NotNil(timerTasks, "expected valid list of tasks.")
×
2810
        s.Equal(len(tasks)+len(initialTasks), len(timerTasks))
×
2811
        s.Equal(p.TaskTypeDecisionTimeout, timerTasks[0].TaskType)
×
2812
        s.Equal(p.TaskTypeWorkflowTimeout, timerTasks[1].TaskType)
×
2813
        s.Equal(p.TaskTypeDeleteHistoryEvent, timerTasks[2].TaskType)
×
2814
        s.Equal(p.TaskTypeActivityTimeout, timerTasks[3].TaskType)
×
2815
        s.Equal(p.TaskTypeUserTimer, timerTasks[4].TaskType)
×
2816
        s.Equal(int64(11), timerTasks[0].Version)
×
2817
        s.Equal(int64(12), timerTasks[1].Version)
×
2818
        s.Equal(int64(13), timerTasks[2].Version)
×
2819
        s.Equal(int64(14), timerTasks[3].Version)
×
2820
        s.Equal(int64(15), timerTasks[4].Version)
×
2821

×
2822
        err2 = s.RangeCompleteTimerTask(ctx, timerTasks[0].VisibilityTimestamp, timerTasks[4].VisibilityTimestamp.Add(1*time.Second))
×
2823
        s.NoError(err2)
×
2824

×
2825
        timerTasks2, err2 := s.GetTimerIndexTasks(ctx, 100, false)
×
2826
        s.NoError(err2)
×
2827
        s.Empty(timerTasks2, "expected empty task list.")
×
2828
}
×
2829

2830
// TestTimerTasksRangeComplete test
2831
func (s *ExecutionManagerSuite) TestTimerTasksRangeComplete() {
×
2832
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2833
        defer cancel()
×
2834

×
2835
        domainID := "8bfb47be-5b57-4d66-9109-5fb35e20b1d7"
×
2836
        workflowExecution := types.WorkflowExecution{
×
2837
                WorkflowID: "get-timer-tasks-test-range-complete",
×
2838
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2839
        }
×
2840

×
2841
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2842
        s.NoError(err0)
×
2843
        s.NotNil(task0, "Expected non empty task identifier.")
×
2844

×
2845
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2846
        s.NoError(err1)
×
2847
        info0 := state0.ExecutionInfo
×
2848
        s.NotNil(info0, "Valid Workflow info expected.")
×
2849

×
2850
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2851
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
2852
        updatedInfo.NextEventID = int64(5)
×
2853
        updatedInfo.LastProcessedEvent = int64(2)
×
2854
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2855
                {
×
2856
                        EventID: updatedInfo.NextEventID,
×
2857
                        Version: common.EmptyVersion,
×
2858
                },
×
2859
        })
×
2860
        versionHistories := p.NewVersionHistories(versionHistory)
×
2861
        tasks := []p.Task{
×
2862
                &p.DecisionTimeoutTask{time.Now(), 1, 2, 3, int(types.TimeoutTypeStartToClose), 11},
×
2863
                &p.WorkflowTimeoutTask{time.Now(), 2, 12},
×
2864
                &p.DeleteHistoryEventTask{time.Now(), 3, 13},
×
2865
                &p.ActivityTimeoutTask{time.Now(), 4, int(types.TimeoutTypeStartToClose), 7, 0, 14},
×
2866
                &p.UserTimerTask{time.Now(), 5, 7, 15},
×
2867
        }
×
2868
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), tasks, nil, nil, nil, nil)
×
2869
        s.NoError(err2)
×
2870

×
2871
        timerTasks, err1 := s.GetTimerIndexTasks(ctx, 1, true) // use page size one to force pagination
×
2872
        s.NoError(err1)
×
2873
        s.NotNil(timerTasks, "expected valid list of tasks.")
×
2874
        s.Equal(len(tasks), len(timerTasks))
×
2875
        s.Equal(p.TaskTypeDecisionTimeout, timerTasks[0].TaskType)
×
2876
        s.Equal(p.TaskTypeWorkflowTimeout, timerTasks[1].TaskType)
×
2877
        s.Equal(p.TaskTypeDeleteHistoryEvent, timerTasks[2].TaskType)
×
2878
        s.Equal(p.TaskTypeActivityTimeout, timerTasks[3].TaskType)
×
2879
        s.Equal(p.TaskTypeUserTimer, timerTasks[4].TaskType)
×
2880
        s.Equal(int64(11), timerTasks[0].Version)
×
2881
        s.Equal(int64(12), timerTasks[1].Version)
×
2882
        s.Equal(int64(13), timerTasks[2].Version)
×
2883
        s.Equal(int64(14), timerTasks[3].Version)
×
2884
        s.Equal(int64(15), timerTasks[4].Version)
×
2885

×
2886
        err2 = s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, nil, nil, int64(5), nil, nil, nil, nil, nil)
×
2887
        s.NoError(err2)
×
2888

×
2889
        err2 = s.CompleteTimerTask(ctx, timerTasks[0].VisibilityTimestamp, timerTasks[0].TaskID)
×
2890
        s.NoError(err2)
×
2891

×
2892
        err2 = s.CompleteTimerTask(ctx, timerTasks[1].VisibilityTimestamp, timerTasks[1].TaskID)
×
2893
        s.NoError(err2)
×
2894

×
2895
        err2 = s.CompleteTimerTask(ctx, timerTasks[2].VisibilityTimestamp, timerTasks[2].TaskID)
×
2896
        s.NoError(err2)
×
2897

×
2898
        err2 = s.CompleteTimerTask(ctx, timerTasks[3].VisibilityTimestamp, timerTasks[3].TaskID)
×
2899
        s.NoError(err2)
×
2900

×
2901
        err2 = s.CompleteTimerTask(ctx, timerTasks[4].VisibilityTimestamp, timerTasks[4].TaskID)
×
2902
        s.NoError(err2)
×
2903

×
2904
        timerTasks2, err2 := s.GetTimerIndexTasks(ctx, 100, false)
×
2905
        s.NoError(err2)
×
2906
        s.Empty(timerTasks2, "expected empty task list.")
×
2907
}
×
2908

2909
// TestWorkflowMutableStateActivities test
2910
func (s *ExecutionManagerSuite) TestWorkflowMutableStateActivities() {
×
2911
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
2912
        defer cancel()
×
2913

×
2914
        domainID := "7fcf0aa9-e121-4292-bdad-0a75181b4aa3"
×
2915
        workflowExecution := types.WorkflowExecution{
×
2916
                WorkflowID: "test-workflow-mutable-test",
×
2917
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
2918
        }
×
2919

×
2920
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
2921
        s.NoError(err0)
×
2922
        s.NotNil(task0, "Expected non empty task identifier.")
×
2923

×
2924
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2925
        s.NoError(err1)
×
2926
        info0 := state0.ExecutionInfo
×
2927
        s.NotNil(info0, "Valid Workflow info expected.")
×
2928

×
2929
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
2930
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
2931
        updatedInfo.NextEventID = int64(5)
×
2932
        updatedInfo.LastProcessedEvent = int64(2)
×
2933
        currentTime := time.Now()
×
2934
        activityInfos := []*p.ActivityInfo{{
×
2935
                Version:                  7789,
×
2936
                ScheduleID:               1,
×
2937
                ScheduledEventBatchID:    1,
×
2938
                ScheduledEvent:           &types.HistoryEvent{ID: 1},
×
2939
                ScheduledTime:            currentTime,
×
2940
                ActivityID:               uuid.New(),
×
2941
                RequestID:                uuid.New(),
×
2942
                Details:                  []byte(uuid.New()),
×
2943
                StartedID:                2,
×
2944
                StartedEvent:             &types.HistoryEvent{ID: 2},
×
2945
                StartedTime:              currentTime,
×
2946
                ScheduleToCloseTimeout:   1,
×
2947
                ScheduleToStartTimeout:   2,
×
2948
                StartToCloseTimeout:      3,
×
2949
                HeartbeatTimeout:         4,
×
2950
                LastHeartBeatUpdatedTime: currentTime,
×
2951
                TimerTaskStatus:          1,
×
2952
                CancelRequested:          true,
×
2953
                CancelRequestID:          math.MaxInt64,
×
2954
                Attempt:                  math.MaxInt32,
×
2955
                DomainID:                 domainID,
×
2956
                StartedIdentity:          uuid.New(),
×
2957
                TaskList:                 uuid.New(),
×
2958
                HasRetryPolicy:           true,
×
2959
                InitialInterval:          math.MaxInt32,
×
2960
                MaximumInterval:          math.MaxInt32,
×
2961
                MaximumAttempts:          math.MaxInt32,
×
2962
                BackoffCoefficient:       5.55,
×
2963
                ExpirationTime:           currentTime,
×
2964
                NonRetriableErrors:       []string{"accessDenied", "badRequest"},
×
2965
                LastFailureReason:        "some random error",
×
2966
                LastWorkerIdentity:       uuid.New(),
×
2967
                LastFailureDetails:       []byte(uuid.New()),
×
2968
        }}
×
2969
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
2970
                {
×
2971
                        EventID: updatedInfo.NextEventID,
×
2972
                        Version: common.EmptyVersion,
×
2973
                },
×
2974
        })
×
2975
        versionHistories := p.NewVersionHistories(versionHistory)
×
2976
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, activityInfos, nil, nil, nil)
×
2977
        s.NoError(err2)
×
2978

×
2979
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
2980
        s.NoError(err1)
×
2981
        s.NotNil(state, "expected valid state.")
×
2982
        s.Equal(1, len(state.ActivityInfos))
×
2983
        log.Printf("%+v", state.ActivityInfos)
×
2984
        ai, ok := state.ActivityInfos[1]
×
2985
        s.True(ok)
×
2986
        s.NotNil(ai)
×
2987
        s.Equal(int64(7789), ai.Version)
×
2988
        s.Equal(int64(1), ai.ScheduleID)
×
2989
        s.Equal(int64(1), ai.ScheduledEventBatchID)
×
2990
        s.Equal(int64(1), ai.ScheduledEvent.ID)
×
2991
        s.EqualTimes(currentTime, ai.ScheduledTime)
×
2992
        s.Equal(activityInfos[0].ActivityID, ai.ActivityID)
×
2993
        s.Equal(activityInfos[0].RequestID, ai.RequestID)
×
2994
        s.Equal(activityInfos[0].Details, ai.Details)
×
2995
        s.Equal(int64(2), ai.StartedID)
×
2996
        s.Equal(int64(2), ai.StartedEvent.ID)
×
2997
        s.EqualTimes(currentTime, ai.StartedTime)
×
2998
        s.Equal(int32(1), ai.ScheduleToCloseTimeout)
×
2999
        s.Equal(int32(2), ai.ScheduleToStartTimeout)
×
3000
        s.Equal(int32(3), ai.StartToCloseTimeout)
×
3001
        s.Equal(int32(4), ai.HeartbeatTimeout)
×
3002
        s.EqualTimes(currentTime, ai.LastHeartBeatUpdatedTime)
×
3003
        s.Equal(int32(1), ai.TimerTaskStatus)
×
3004
        s.Equal(activityInfos[0].CancelRequested, ai.CancelRequested)
×
3005
        s.Equal(activityInfos[0].CancelRequestID, ai.CancelRequestID)
×
3006
        s.Equal(activityInfos[0].Attempt, ai.Attempt)
×
3007
        s.Equal(activityInfos[0].DomainID, ai.DomainID)
×
3008
        s.Equal(activityInfos[0].StartedIdentity, ai.StartedIdentity)
×
3009
        s.Equal(activityInfos[0].TaskList, ai.TaskList)
×
3010
        s.Equal(activityInfos[0].HasRetryPolicy, ai.HasRetryPolicy)
×
3011
        s.Equal(activityInfos[0].InitialInterval, ai.InitialInterval)
×
3012
        s.Equal(activityInfos[0].MaximumInterval, ai.MaximumInterval)
×
3013
        s.Equal(activityInfos[0].MaximumAttempts, ai.MaximumAttempts)
×
3014
        s.Equal(activityInfos[0].BackoffCoefficient, ai.BackoffCoefficient)
×
3015
        s.EqualTimes(activityInfos[0].ExpirationTime, ai.ExpirationTime)
×
3016
        s.Equal(activityInfos[0].NonRetriableErrors, ai.NonRetriableErrors)
×
3017
        s.Equal(activityInfos[0].LastFailureReason, ai.LastFailureReason)
×
3018
        s.Equal(activityInfos[0].LastWorkerIdentity, ai.LastWorkerIdentity)
×
3019
        s.Equal(activityInfos[0].LastFailureDetails, ai.LastFailureDetails)
×
3020

×
3021
        err2 = s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, nil, nil, int64(5), nil, nil, []int64{1}, nil, nil)
×
3022
        s.NoError(err2)
×
3023

×
3024
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3025
        s.NoError(err2)
×
3026
        s.NotNil(state, "expected valid state.")
×
3027
        s.Equal(0, len(state.ActivityInfos))
×
3028
}
×
3029

3030
// TestWorkflowMutableStateTimers test
3031
func (s *ExecutionManagerSuite) TestWorkflowMutableStateTimers() {
×
3032
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3033
        defer cancel()
×
3034

×
3035
        domainID := "025d178a-709b-4c07-8dd7-86dbf9bd2e06"
×
3036
        workflowExecution := types.WorkflowExecution{
×
3037
                WorkflowID: "test-workflow-mutable-timers-test",
×
3038
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3039
        }
×
3040

×
3041
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3042
        s.NoError(err0)
×
3043
        s.NotNil(task0, "Expected non empty task identifier.")
×
3044

×
3045
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3046
        s.NoError(err1)
×
3047
        info0 := state0.ExecutionInfo
×
3048
        s.NotNil(info0, "Valid Workflow info expected.")
×
3049

×
3050
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3051
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3052
        updatedInfo.NextEventID = int64(5)
×
3053
        updatedInfo.LastProcessedEvent = int64(2)
×
3054
        currentTime := time.Now().UTC()
×
3055
        timerID := "id_1"
×
3056
        timerInfos := []*p.TimerInfo{{
×
3057
                Version:    3345,
×
3058
                TimerID:    timerID,
×
3059
                ExpiryTime: currentTime,
×
3060
                TaskStatus: 2,
×
3061
                StartedID:  5,
×
3062
        }}
×
3063
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3064
                {
×
3065
                        EventID: updatedInfo.NextEventID,
×
3066
                        Version: common.EmptyVersion,
×
3067
                },
×
3068
        })
×
3069
        versionHistories := p.NewVersionHistories(versionHistory)
×
3070
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, nil, nil, timerInfos, nil)
×
3071
        s.NoError(err2)
×
3072

×
3073
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3074
        s.NoError(err1)
×
3075
        s.NotNil(state, "expected valid state.")
×
3076
        s.Equal(1, len(state.TimerInfos))
×
3077
        s.Equal(int64(3345), state.TimerInfos[timerID].Version)
×
3078
        s.Equal(timerID, state.TimerInfos[timerID].TimerID)
×
3079
        s.EqualTimesWithPrecision(currentTime, state.TimerInfos[timerID].ExpiryTime, time.Millisecond*500)
×
3080
        s.Equal(int64(2), state.TimerInfos[timerID].TaskStatus)
×
3081
        s.Equal(int64(5), state.TimerInfos[timerID].StartedID)
×
3082

×
3083
        err2 = s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, nil, nil, int64(5), nil, nil, nil, nil, []string{timerID})
×
3084
        s.NoError(err2)
×
3085

×
3086
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3087
        s.NoError(err2)
×
3088
        s.NotNil(state, "expected valid state.")
×
3089
        s.Equal(0, len(state.TimerInfos))
×
3090
}
×
3091

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

×
3097
        domainID := "88236cd2-c439-4cec-9957-2748ce3be074"
×
3098
        workflowExecution := types.WorkflowExecution{
×
3099
                WorkflowID: "test-workflow-mutable-child-executions-parent-test",
×
3100
                RunID:      "c63dba1e-929c-4fbf-8ec5-4533b16269a9",
×
3101
        }
×
3102

×
3103
        parentDomainID := "6036ded3-e541-42c9-8f69-3d9354dad081"
×
3104
        parentExecution := types.WorkflowExecution{
×
3105
                WorkflowID: "test-workflow-mutable-child-executions-child-test",
×
3106
                RunID:      "73e89362-25ec-4305-bcb8-d9448b90856c",
×
3107
        }
×
3108

×
3109
        partitionConfig := map[string]string{
×
3110
                "userID": uuid.New(),
×
3111
        }
×
3112
        task0, err0 := s.CreateChildWorkflowExecution(ctx, domainID, workflowExecution, parentDomainID, parentExecution, 1, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, partitionConfig)
×
3113
        s.NoError(err0)
×
3114
        s.NotNil(task0, "Expected non empty task identifier.")
×
3115

×
3116
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3117
        s.NoError(err1)
×
3118
        info0 := state0.ExecutionInfo
×
3119
        s.NotNil(info0, "Valid Workflow info expected.")
×
3120
        s.Equal(parentDomainID, info0.ParentDomainID)
×
3121
        s.Equal(parentExecution.GetWorkflowID(), info0.ParentWorkflowID)
×
3122
        s.Equal(parentExecution.GetRunID(), info0.ParentRunID)
×
3123
        s.Equal(int64(1), info0.InitiatedID)
×
3124
        s.Equal(partitionConfig, info0.PartitionConfig)
×
3125

×
3126
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3127
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3128
        updatedInfo.NextEventID = int64(5)
×
3129
        updatedInfo.LastProcessedEvent = int64(2)
×
3130
        childExecutionInfos := []*p.ChildExecutionInfo{{
×
3131
                Version:           1234,
×
3132
                InitiatedID:       1,
×
3133
                InitiatedEvent:    &types.HistoryEvent{ID: 1},
×
3134
                StartedID:         2,
×
3135
                StartedRunID:      uuid.New(),
×
3136
                StartedEvent:      &types.HistoryEvent{ID: 2},
×
3137
                CreateRequestID:   uuid.New(),
×
3138
                DomainID:          uuid.New(),
×
3139
                ParentClosePolicy: types.ParentClosePolicyTerminate,
×
3140
        }}
×
3141
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3142
                {
×
3143
                        EventID: updatedInfo.LastProcessedEvent,
×
3144
                        Version: common.EmptyVersion,
×
3145
                },
×
3146
        })
×
3147
        versionHistories := p.NewVersionHistories(versionHistory)
×
3148
        err2 := s.UpsertChildExecutionsState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), childExecutionInfos)
×
3149
        s.NoError(err2)
×
3150

×
3151
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3152
        s.NoError(err1)
×
3153
        s.NotNil(state, "expected valid state.")
×
3154
        s.Equal(1, len(state.ChildExecutionInfos))
×
3155
        ci, ok := state.ChildExecutionInfos[1]
×
3156
        s.True(ok)
×
3157
        s.NotNil(ci)
×
3158
        s.Equal(childExecutionInfos[0], ci)
×
3159

×
3160
        err2 = s.DeleteChildExecutionsState(ctx, updatedInfo, updatedStats, versionHistories, int64(5), int64(1))
×
3161
        s.NoError(err2)
×
3162

×
3163
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3164
        s.NoError(err2)
×
3165
        s.NotNil(state, "expected valid state.")
×
3166
        s.Equal(0, len(state.ChildExecutionInfos))
×
3167
}
×
3168

3169
// TestWorkflowMutableStateRequestCancel test
3170
func (s *ExecutionManagerSuite) TestWorkflowMutableStateRequestCancel() {
×
3171
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3172
        defer cancel()
×
3173

×
3174
        domainID := "568b8d19-cf64-4aac-be1b-f8a3edbc1fa9"
×
3175
        workflowExecution := types.WorkflowExecution{
×
3176
                WorkflowID: "test-workflow-mutable-request-cancel-test",
×
3177
                RunID:      "87f96253-b925-426e-90db-aa4ee89b5aca",
×
3178
        }
×
3179

×
3180
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3181
        s.NoError(err0)
×
3182
        s.NotNil(task0, "Expected non empty task identifier.")
×
3183

×
3184
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3185
        s.NoError(err1)
×
3186
        info0 := state0.ExecutionInfo
×
3187
        s.NotNil(info0, "Valid Workflow info expected.")
×
3188

×
3189
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3190
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3191
        updatedInfo.NextEventID = int64(5)
×
3192
        updatedInfo.LastProcessedEvent = int64(2)
×
3193
        requestCancelInfo := &p.RequestCancelInfo{
×
3194
                Version:               456,
×
3195
                InitiatedID:           2,
×
3196
                InitiatedEventBatchID: 1,
×
3197
                CancelRequestID:       uuid.New(),
×
3198
        }
×
3199
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3200
                {
×
3201
                        EventID: updatedInfo.LastProcessedEvent,
×
3202
                        Version: common.EmptyVersion,
×
3203
                },
×
3204
        })
×
3205
        versionHistories := p.NewVersionHistories(versionHistory)
×
3206
        err2 := s.UpsertRequestCancelState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), []*p.RequestCancelInfo{requestCancelInfo})
×
3207
        s.NoError(err2)
×
3208

×
3209
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3210
        s.NoError(err1)
×
3211
        s.NotNil(state, "expected valid state.")
×
3212
        s.Equal(1, len(state.RequestCancelInfos))
×
3213
        ri, ok := state.RequestCancelInfos[requestCancelInfo.InitiatedID]
×
3214
        s.True(ok)
×
3215
        s.NotNil(ri)
×
3216
        s.Equal(requestCancelInfo, ri)
×
3217

×
3218
        err2 = s.DeleteCancelState(ctx, updatedInfo, updatedStats, versionHistories, int64(5), requestCancelInfo.InitiatedID)
×
3219
        s.NoError(err2)
×
3220

×
3221
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3222
        s.NoError(err2)
×
3223
        s.NotNil(state, "expected valid state.")
×
3224
        s.Equal(0, len(state.RequestCancelInfos))
×
3225
}
×
3226

3227
// TestWorkflowMutableStateSignalInfo test
3228
func (s *ExecutionManagerSuite) TestWorkflowMutableStateSignalInfo() {
×
3229
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3230
        defer cancel()
×
3231

×
3232
        domainID := uuid.New()
×
3233
        runID := uuid.New()
×
3234
        workflowExecution := types.WorkflowExecution{
×
3235
                WorkflowID: "test-workflow-mutable-signal-info-test",
×
3236
                RunID:      runID,
×
3237
        }
×
3238

×
3239
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3240
        s.NoError(err0)
×
3241
        s.NotNil(task0, "Expected non empty task identifier.")
×
3242

×
3243
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3244
        s.NoError(err1)
×
3245
        info0 := state0.ExecutionInfo
×
3246
        s.NotNil(info0, "Valid Workflow info expected.")
×
3247

×
3248
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3249
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3250
        updatedInfo.NextEventID = int64(5)
×
3251
        updatedInfo.LastProcessedEvent = int64(2)
×
3252
        signalInfo := &p.SignalInfo{
×
3253
                Version:               123,
×
3254
                InitiatedID:           2,
×
3255
                InitiatedEventBatchID: 1,
×
3256
                SignalRequestID:       uuid.New(),
×
3257
                SignalName:            "my signal",
×
3258
                Input:                 []byte("test signal input"),
×
3259
                Control:               []byte(uuid.New()),
×
3260
        }
×
3261
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3262
                {
×
3263
                        EventID: updatedInfo.LastProcessedEvent,
×
3264
                        Version: common.EmptyVersion,
×
3265
                },
×
3266
        })
×
3267
        versionHistories := p.NewVersionHistories(versionHistory)
×
3268
        err2 := s.UpsertSignalInfoState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), []*p.SignalInfo{signalInfo})
×
3269
        s.NoError(err2)
×
3270

×
3271
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3272
        s.NoError(err1)
×
3273
        s.NotNil(state, "expected valid state.")
×
3274
        s.Equal(1, len(state.SignalInfos))
×
3275
        si, ok := state.SignalInfos[signalInfo.InitiatedID]
×
3276
        s.True(ok)
×
3277
        s.NotNil(si)
×
3278
        s.Equal(signalInfo, si)
×
3279

×
3280
        err2 = s.DeleteSignalState(ctx, updatedInfo, updatedStats, versionHistories, int64(5), signalInfo.InitiatedID)
×
3281
        s.NoError(err2)
×
3282

×
3283
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3284
        s.NoError(err2)
×
3285
        s.NotNil(state, "expected valid state.")
×
3286
        s.Equal(0, len(state.SignalInfos))
×
3287
}
×
3288

3289
// TestWorkflowMutableStateSignalRequested test
3290
func (s *ExecutionManagerSuite) TestWorkflowMutableStateSignalRequested() {
×
3291
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3292
        defer cancel()
×
3293

×
3294
        domainID := uuid.New()
×
3295
        runID := uuid.New()
×
3296
        workflowExecution := types.WorkflowExecution{
×
3297
                WorkflowID: "test-workflow-mutable-signal-requested-test",
×
3298
                RunID:      runID,
×
3299
        }
×
3300

×
3301
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3302
        s.NoError(err0)
×
3303
        s.NotNil(task0, "Expected non empty task identifier.")
×
3304

×
3305
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3306
        s.NoError(err1)
×
3307
        info0 := state0.ExecutionInfo
×
3308
        s.NotNil(info0, "Valid Workflow info expected.")
×
3309

×
3310
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3311
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3312
        updatedInfo.NextEventID = int64(5)
×
3313
        updatedInfo.LastProcessedEvent = int64(2)
×
3314
        signalRequestedID := uuid.New()
×
3315
        signalsRequested := []string{signalRequestedID}
×
3316
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3317
                {
×
3318
                        EventID: updatedInfo.LastProcessedEvent,
×
3319
                        Version: common.EmptyVersion,
×
3320
                },
×
3321
        })
×
3322
        versionHistories := p.NewVersionHistories(versionHistory)
×
3323
        err2 := s.UpsertSignalsRequestedState(ctx, updatedInfo, updatedStats, versionHistories, int64(3), signalsRequested)
×
3324
        s.NoError(err2)
×
3325

×
3326
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3327
        s.NoError(err1)
×
3328
        s.NotNil(state, "expected valid state.")
×
3329
        s.Equal(1, len(state.SignalRequestedIDs))
×
3330
        ri, ok := state.SignalRequestedIDs[signalRequestedID]
×
3331
        s.True(ok)
×
3332
        s.NotNil(ri)
×
3333

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

×
3337
        state, err2 = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3338
        s.NoError(err2)
×
3339
        s.NotNil(state, "expected valid state.")
×
3340
        s.Equal(0, len(state.SignalRequestedIDs))
×
3341
}
×
3342

3343
// TestWorkflowMutableStateInfo test
3344
func (s *ExecutionManagerSuite) TestWorkflowMutableStateInfo() {
×
3345
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3346
        defer cancel()
×
3347

×
3348
        domainID := "9ed8818b-3090-4160-9f21-c6b70e64d2dd"
×
3349
        workflowExecution := types.WorkflowExecution{
×
3350
                WorkflowID: "test-workflow-mutable-state-test",
×
3351
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3352
        }
×
3353

×
3354
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3355
        s.NoError(err0)
×
3356
        s.NotNil(task0, "Expected non empty task identifier.")
×
3357

×
3358
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3359
        s.NoError(err1)
×
3360
        info0 := state0.ExecutionInfo
×
3361
        s.NotNil(info0, "Valid Workflow info expected.")
×
3362

×
3363
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3364
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3365
        updatedInfo.NextEventID = int64(5)
×
3366
        updatedInfo.LastProcessedEvent = int64(2)
×
3367
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3368
                {
×
3369
                        EventID: updatedInfo.LastProcessedEvent,
×
3370
                        Version: common.EmptyVersion,
×
3371
                },
×
3372
        })
×
3373
        versionHistories := p.NewVersionHistories(versionHistory)
×
3374
        err2 := s.UpdateWorkflowExecution(ctx, updatedInfo, updatedStats, versionHistories, []int64{int64(4)}, nil, int64(3), nil, nil, nil, nil, nil)
×
3375
        s.NoError(err2)
×
3376

×
3377
        state, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3378
        s.NoError(err1)
×
3379
        s.NotNil(state, "expected valid state.")
×
3380
        s.NotNil(state.ExecutionInfo, "expected valid MS Info state.")
×
3381
        s.Equal(updatedInfo.NextEventID, state.ExecutionInfo.NextEventID)
×
3382
        s.Equal(updatedInfo.State, state.ExecutionInfo.State)
×
3383
}
×
3384

3385
// TestContinueAsNew test
3386
func (s *ExecutionManagerSuite) TestContinueAsNew() {
×
3387
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3388
        defer cancel()
×
3389

×
3390
        domainID := "c1c0bb55-04e6-4a9c-89d0-1be7b96459f8"
×
3391
        workflowExecution := types.WorkflowExecution{
×
3392
                WorkflowID: "continue-as-new-workflow-test",
×
3393
                RunID:      "551c88d2-d9e6-404f-8131-9eec14f36643",
×
3394
        }
×
3395

×
3396
        partitionConfig := map[string]string{
×
3397
                "userID": uuid.New(),
×
3398
        }
×
3399
        _, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, partitionConfig)
×
3400
        s.NoError(err0)
×
3401

×
3402
        state0, err1 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3403
        s.NoError(err1)
×
3404
        info0 := state0.ExecutionInfo
×
3405
        continueAsNewInfo := copyWorkflowExecutionInfo(info0)
×
3406
        continueAsNewStats := copyExecutionStats(state0.ExecutionStats)
×
3407
        continueAsNewInfo.State = p.WorkflowStateCreated
×
3408
        continueAsNewInfo.CloseStatus = p.WorkflowCloseStatusNone
×
3409
        continueAsNewInfo.NextEventID = int64(5)
×
3410
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
3411

×
3412
        newWorkflowExecution := types.WorkflowExecution{
×
3413
                WorkflowID: "continue-as-new-workflow-test",
×
3414
                RunID:      "64c7e15a-3fd7-4182-9c6f-6f25a4fa2614",
×
3415
        }
×
3416

×
3417
        testResetPoints := types.ResetPoints{
×
3418
                Points: []*types.ResetPointInfo{
×
3419
                        {
×
3420
                                BinaryChecksum:           "test-binary-checksum",
×
3421
                                RunID:                    "test-runID",
×
3422
                                FirstDecisionCompletedID: 123,
×
3423
                                CreatedTimeNano:          common.Int64Ptr(456),
×
3424
                                Resettable:               true,
×
3425
                                ExpiringTimeNano:         common.Int64Ptr(789),
×
3426
                        },
×
3427
                },
×
3428
        }
×
3429

×
3430
        err2 := s.ContinueAsNewExecution(ctx, continueAsNewInfo, continueAsNewStats, info0.NextEventID, newWorkflowExecution, int64(3), int64(2), &testResetPoints)
×
3431
        s.NoError(err2)
×
3432

×
3433
        prevExecutionState, err3 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3434
        s.NoError(err3)
×
3435
        prevExecutionInfo := prevExecutionState.ExecutionInfo
×
3436
        s.Equal("551c88d2-d9e6-404f-8131-9eec14f36643", prevExecutionInfo.FirstExecutionRunID)
×
3437
        s.Equal(p.WorkflowStateCompleted, prevExecutionInfo.State)
×
3438
        s.Equal(p.WorkflowCloseStatusContinuedAsNew, prevExecutionInfo.CloseStatus)
×
3439
        s.Equal(int64(5), prevExecutionInfo.NextEventID)
×
3440
        s.Equal(int64(2), prevExecutionInfo.LastProcessedEvent)
×
3441
        s.Equal(prevExecutionInfo.AutoResetPoints, &types.ResetPoints{})
×
3442
        s.Equal(partitionConfig, prevExecutionInfo.PartitionConfig)
×
3443

×
3444
        newExecutionState, err4 := s.GetWorkflowExecutionInfo(ctx, domainID, newWorkflowExecution)
×
3445
        s.NoError(err4)
×
3446
        newExecutionInfo := newExecutionState.ExecutionInfo
×
3447
        s.Equal("551c88d2-d9e6-404f-8131-9eec14f36643", newExecutionInfo.FirstExecutionRunID)
×
3448
        s.Equal(p.WorkflowStateCreated, newExecutionInfo.State)
×
3449
        s.Equal(p.WorkflowCloseStatusNone, newExecutionInfo.CloseStatus)
×
3450
        s.Equal(int64(3), newExecutionInfo.NextEventID)
×
3451
        s.Equal(common.EmptyEventID, newExecutionInfo.LastProcessedEvent)
×
3452
        s.Equal(int64(2), newExecutionInfo.DecisionScheduleID)
×
3453
        s.Equal(testResetPoints, *newExecutionInfo.AutoResetPoints)
×
3454
        s.Equal(partitionConfig, newExecutionInfo.PartitionConfig)
×
3455

×
3456
        newRunID, err5 := s.GetCurrentWorkflowRunID(ctx, domainID, workflowExecution.GetWorkflowID())
×
3457
        s.NoError(err5)
×
3458
        s.Equal(newWorkflowExecution.GetRunID(), newRunID)
×
3459
}
×
3460

3461
// TestReplicationTransferTaskTasks test
3462
func (s *ExecutionManagerSuite) TestReplicationTransferTaskTasks() {
×
3463
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3464
        defer cancel()
×
3465

×
3466
        domainID := "2466d7de-6602-4ad8-b939-fb8f8c36c711"
×
3467
        workflowExecution := types.WorkflowExecution{
×
3468
                WorkflowID: "replication-transfer-task-test",
×
3469
                RunID:      "dcde9d85-5d7a-43c7-8b18-cb2cae0e29e0",
×
3470
        }
×
3471

×
3472
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3473
        s.NoError(err)
×
3474
        s.NotNil(task0, "Expected non empty task identifier.")
×
3475

×
3476
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
3477
        s.NoError(err)
×
3478
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
3479
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
3480
        s.NoError(err)
×
3481

×
3482
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3483
        s.NoError(err)
×
3484
        info1 := state1.ExecutionInfo
×
3485
        s.NotNil(info1, "Valid Workflow info expected.")
×
3486
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
3487
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
3488

×
3489
        replicationTasks := []p.Task{&p.HistoryReplicationTask{
×
3490
                TaskID:       s.GetNextSequenceNumber(),
×
3491
                FirstEventID: int64(1),
×
3492
                NextEventID:  int64(3),
×
3493
                Version:      int64(9),
×
3494
        }}
×
3495
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3496
                {
×
3497
                        EventID: 3,
×
3498
                        Version: common.EmptyVersion,
×
3499
                },
×
3500
        })
×
3501
        versionHistories := p.NewVersionHistories(versionHistory)
×
3502
        err = s.UpdateWorklowStateAndReplication(ctx, updatedInfo1, updatedStats1, versionHistories, int64(3), replicationTasks)
×
3503
        s.NoError(err)
×
3504

×
3505
        tasks1, err := s.GetReplicationTasks(ctx, 1, false)
×
3506
        s.NoError(err)
×
3507
        s.NotNil(tasks1, "expected valid list of tasks.")
×
3508
        s.Equal(1, len(tasks1), "Expected 1 replication task.")
×
3509
        task1 := tasks1[0]
×
3510
        s.Equal(p.ReplicationTaskTypeHistory, task1.TaskType)
×
3511
        s.Equal(domainID, task1.DomainID)
×
3512
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
3513
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
3514
        s.Equal(int64(1), task1.FirstEventID)
×
3515
        s.Equal(int64(3), task1.NextEventID)
×
3516
        s.Equal(int64(9), task1.Version)
×
3517

×
3518
        err = s.CompleteReplicationTask(ctx, task1.TaskID)
×
3519
        s.NoError(err)
×
3520
        tasks2, err := s.GetReplicationTasks(ctx, 1, false)
×
3521
        s.NoError(err)
×
3522
        s.Equal(0, len(tasks2))
×
3523
}
×
3524

3525
// TestReplicationTransferTaskRangeComplete test
3526
func (s *ExecutionManagerSuite) TestReplicationTransferTaskRangeComplete() {
×
3527
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3528
        defer cancel()
×
3529

×
3530
        domainID := uuid.New()
×
3531
        workflowExecution := types.WorkflowExecution{
×
3532
                WorkflowID: "replication-transfer-task--range-complete-test",
×
3533
                RunID:      uuid.New(),
×
3534
        }
×
3535

×
3536
        task0, err := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "queue1", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3537
        s.NoError(err)
×
3538
        s.NotNil(task0, "Expected non empty task identifier.")
×
3539

×
3540
        taskD, err := s.GetTransferTasks(ctx, 1, false)
×
3541
        s.NoError(err)
×
3542
        s.Equal(1, len(taskD), "Expected 1 decision task.")
×
3543
        err = s.CompleteTransferTask(ctx, taskD[0].TaskID)
×
3544
        s.NoError(err)
×
3545

×
3546
        state1, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3547
        s.NoError(err)
×
3548
        info1 := state1.ExecutionInfo
×
3549
        s.NotNil(info1, "Valid Workflow info expected.")
×
3550
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
3551
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
3552

×
3553
        replicationTasks := []p.Task{
×
3554
                &p.HistoryReplicationTask{
×
3555
                        TaskID:       s.GetNextSequenceNumber(),
×
3556
                        FirstEventID: int64(1),
×
3557
                        NextEventID:  int64(3),
×
3558
                        Version:      int64(9),
×
3559
                },
×
3560
                &p.HistoryReplicationTask{
×
3561
                        TaskID:       s.GetNextSequenceNumber(),
×
3562
                        FirstEventID: int64(4),
×
3563
                        NextEventID:  int64(5),
×
3564
                        Version:      int64(9),
×
3565
                },
×
3566
        }
×
3567
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3568
                {
×
3569
                        EventID: 3,
×
3570
                        Version: common.EmptyVersion,
×
3571
                },
×
3572
        })
×
3573
        versionHistories := p.NewVersionHistories(versionHistory)
×
3574
        err = s.UpdateWorklowStateAndReplication(ctx,
×
3575
                updatedInfo1,
×
3576
                updatedStats1,
×
3577
                versionHistories,
×
3578
                int64(3),
×
3579
                replicationTasks,
×
3580
        )
×
3581
        s.NoError(err)
×
3582

×
3583
        tasks1, err := s.GetReplicationTasks(ctx, 2, false)
×
3584
        s.NoError(err)
×
3585
        s.NotNil(tasks1, "expected valid list of tasks.")
×
3586
        s.Equal(2, len(tasks1), "Expected 2 replication tasks.")
×
3587
        task1 := tasks1[0]
×
3588
        s.Equal(p.ReplicationTaskTypeHistory, task1.TaskType)
×
3589
        s.Equal(domainID, task1.DomainID)
×
3590
        s.Equal(workflowExecution.GetWorkflowID(), task1.WorkflowID)
×
3591
        s.Equal(workflowExecution.GetRunID(), task1.RunID)
×
3592
        s.Equal(int64(1), task1.FirstEventID)
×
3593
        s.Equal(int64(3), task1.NextEventID)
×
3594
        s.Equal(int64(9), task1.Version)
×
3595

×
3596
        task2 := tasks1[1]
×
3597
        s.Equal(p.ReplicationTaskTypeHistory, task2.TaskType)
×
3598
        s.Equal(domainID, task2.DomainID)
×
3599
        s.Equal(workflowExecution.GetWorkflowID(), task2.WorkflowID)
×
3600
        s.Equal(workflowExecution.GetRunID(), task2.RunID)
×
3601
        s.Equal(int64(4), task2.FirstEventID)
×
3602
        s.Equal(int64(5), task2.NextEventID)
×
3603
        s.Equal(int64(9), task2.Version)
×
3604
        err = s.RangeCompleteReplicationTask(ctx, task2.TaskID)
×
3605
        s.NoError(err)
×
3606
        tasks2, err := s.GetReplicationTasks(ctx, 1, false)
×
3607
        s.NoError(err)
×
3608
        s.Equal(0, len(tasks2))
×
3609
}
×
3610

3611
// TestUpdateAndClearBufferedEvents test
3612
func (s *ExecutionManagerSuite) TestUpdateAndClearBufferedEvents() {
×
3613
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3614
        defer cancel()
×
3615

×
3616
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
3617
        workflowExecution := types.WorkflowExecution{
×
3618
                WorkflowID: "test-update-and-clear-buffered-events",
×
3619
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3620
        }
×
3621

×
3622
        task0, err0 := s.CreateWorkflowExecution(ctx, domainID, workflowExecution, "taskList", "wType", 20, 13, nil, 3, 0, 2, nil, nil)
×
3623
        s.NoError(err0)
×
3624
        s.NotNil(task0, "Expected non empty task identifier.")
×
3625

×
3626
        stats0, state0, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
3627
        s.NoError(err1)
×
3628
        info0 := state0.ExecutionInfo
×
3629
        s.NotNil(info0, "Valid Workflow info expected.")
×
3630
        s.Equal(0, stats0.BufferedEventsCount)
×
3631
        s.Equal(0, stats0.BufferedEventsSize)
×
3632

×
3633
        eventsBatch1 := []*types.HistoryEvent{
×
3634
                {
×
3635
                        ID:        5,
×
3636
                        EventType: types.EventTypeDecisionTaskCompleted.Ptr(),
×
3637
                        Version:   11,
×
3638
                        DecisionTaskCompletedEventAttributes: &types.DecisionTaskCompletedEventAttributes{
×
3639
                                ScheduledEventID: 2,
×
3640
                                StartedEventID:   3,
×
3641
                                Identity:         "test_worker",
×
3642
                        },
×
3643
                },
×
3644
                {
×
3645
                        ID:        6,
×
3646
                        EventType: types.EventTypeTimerStarted.Ptr(),
×
3647
                        Version:   11,
×
3648
                        TimerStartedEventAttributes: &types.TimerStartedEventAttributes{
×
3649
                                TimerID:                      "ID1",
×
3650
                                StartToFireTimeoutSeconds:    common.Int64Ptr(101),
×
3651
                                DecisionTaskCompletedEventID: 5,
×
3652
                        },
×
3653
                },
×
3654
        }
×
3655

×
3656
        eventsBatch2 := []*types.HistoryEvent{
×
3657
                {
×
3658
                        ID:        21,
×
3659
                        EventType: types.EventTypeTimerFired.Ptr(),
×
3660
                        Version:   12,
×
3661
                        TimerFiredEventAttributes: &types.TimerFiredEventAttributes{
×
3662
                                TimerID:        "2",
×
3663
                                StartedEventID: 3,
×
3664
                        },
×
3665
                },
×
3666
        }
×
3667
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3668
                {
×
3669
                        EventID: eventsBatch2[0].ID,
×
3670
                        Version: common.EmptyVersion,
×
3671
                },
×
3672
        })
×
3673
        versionHistories := p.NewVersionHistories(versionHistory)
×
3674
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3675
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3676
        updatedState := &p.WorkflowMutableState{
×
3677
                ExecutionInfo:    updatedInfo,
×
3678
                ExecutionStats:   updatedStats,
×
3679
                VersionHistories: versionHistories,
×
3680
        }
×
3681

×
3682
        err2 := s.UpdateAllMutableState(ctx, updatedState, int64(3))
×
3683
        s.NoError(err2)
×
3684

×
3685
        partialState, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3686
        s.NoError(err2)
×
3687
        s.NotNil(partialState, "expected valid state.")
×
3688
        partialInfo := partialState.ExecutionInfo
×
3689
        s.NotNil(partialInfo, "Valid Workflow info expected.")
×
3690

×
3691
        bufferUpdateInfo := copyWorkflowExecutionInfo(partialInfo)
×
3692
        bufferedUpdatedStats := copyExecutionStats(state0.ExecutionStats)
×
3693
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
3694
        s.NoError(err2)
×
3695
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
3696
        s.NoError(err2)
×
3697
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch1, false, versionHistories)
×
3698
        s.NoError(err2)
×
3699
        stats0, state0, err2 = s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
3700
        s.NoError(err2)
×
3701
        s.Equal(1, stats0.BufferedEventsCount)
×
3702
        s.True(stats0.BufferedEventsSize > 0)
×
3703
        testHistory := &types.History{Events: make([]*types.HistoryEvent, 0)}
×
3704
        testHistory.Events = append(testHistory.Events, eventsBatch1...)
×
3705
        history0 := &types.History{Events: state0.BufferedEvents}
×
3706
        s.Equal(testHistory, history0)
×
3707
        testHistory.Events = append(testHistory.Events, eventsBatch2...)
×
3708

×
3709
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch2, false, versionHistories)
×
3710
        s.NoError(err2)
×
3711

×
3712
        stats1, state1, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
3713
        s.NoError(err1)
×
3714
        s.NotNil(state1, "expected valid state.")
×
3715
        info1 := state1.ExecutionInfo
×
3716
        s.NotNil(info1, "Valid Workflow info expected.")
×
3717
        s.Equal(2, stats1.BufferedEventsCount)
×
3718
        s.True(stats1.BufferedEventsSize > 0)
×
3719
        history1 := &types.History{Events: state1.BufferedEvents}
×
3720
        s.Equal(testHistory, history1)
×
3721

×
3722
        err3 := s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, nil, true, versionHistories)
×
3723
        s.NoError(err3)
×
3724

×
3725
        stats3, state3, err3 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
3726
        s.NoError(err3)
×
3727
        s.NotNil(state3, "expected valid state.")
×
3728
        info3 := state3.ExecutionInfo
×
3729
        s.NotNil(info3, "Valid Workflow info expected.")
×
3730
        s.Equal(0, stats3.BufferedEventsCount)
×
3731
        s.Equal(0, stats3.BufferedEventsSize)
×
3732
}
×
3733

3734
// TestConflictResolveWorkflowExecutionCurrentIsSelf test
3735
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionCurrentIsSelf() {
×
3736
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
3737
        defer cancel()
×
3738

×
3739
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
3740
        workflowExecution := types.WorkflowExecution{
×
3741
                WorkflowID: "test-reset-mutable-state-test-current-is-self",
×
3742
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3743
        }
×
3744
        partitionConfig := map[string]string{
×
3745
                "userid": uuid.New(),
×
3746
        }
×
3747
        task0, err0 := s.CreateWorkflowExecution(
×
3748
                ctx,
×
3749
                domainID,
×
3750
                workflowExecution,
×
3751
                "taskList",
×
3752
                "wType",
×
3753
                20,
×
3754
                13,
×
3755
                nil,
×
3756
                3,
×
3757
                0,
×
3758
                2,
×
3759
                nil,
×
3760
                partitionConfig,
×
3761
        )
×
3762
        s.NoError(err0)
×
3763
        s.NotNil(task0, "Expected non empty task identifier.")
×
3764

×
3765
        stats0, state0, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
3766
        s.NoError(err1)
×
3767
        info0 := state0.ExecutionInfo
×
3768
        s.NotNil(info0, "Valid Workflow info expected.")
×
3769
        s.Equal(0, stats0.BufferedEventsCount)
×
3770
        s.Equal(0, stats0.BufferedEventsSize)
×
3771

×
3772
        updatedInfo := copyWorkflowExecutionInfo(info0)
×
3773
        updatedStats := copyExecutionStats(state0.ExecutionStats)
×
3774
        updatedInfo.NextEventID = int64(5)
×
3775
        updatedInfo.LastProcessedEvent = int64(2)
×
3776
        currentTime := time.Now().UTC()
×
3777
        expiryTime := currentTime.Add(10 * time.Second)
×
3778
        eventsBatch1 := []*types.HistoryEvent{
×
3779
                {
×
3780
                        ID:        5,
×
3781
                        EventType: types.EventTypeDecisionTaskCompleted.Ptr(),
×
3782
                        Version:   11,
×
3783
                        DecisionTaskCompletedEventAttributes: &types.DecisionTaskCompletedEventAttributes{
×
3784
                                ScheduledEventID: 2,
×
3785
                                StartedEventID:   3,
×
3786
                                Identity:         "test_worker",
×
3787
                        },
×
3788
                },
×
3789
                {
×
3790
                        ID:        6,
×
3791
                        EventType: types.EventTypeTimerStarted.Ptr(),
×
3792
                        Version:   11,
×
3793
                        TimerStartedEventAttributes: &types.TimerStartedEventAttributes{
×
3794
                                TimerID:                      "ID1",
×
3795
                                StartToFireTimeoutSeconds:    common.Int64Ptr(101),
×
3796
                                DecisionTaskCompletedEventID: 5,
×
3797
                        },
×
3798
                },
×
3799
        }
×
3800

×
3801
        eventsBatch2 := []*types.HistoryEvent{
×
3802
                {
×
3803
                        ID:        21,
×
3804
                        EventType: types.EventTypeTimerFired.Ptr(),
×
3805
                        Version:   12,
×
3806
                        TimerFiredEventAttributes: &types.TimerFiredEventAttributes{
×
3807
                                TimerID:        "2",
×
3808
                                StartedEventID: 3,
×
3809
                        },
×
3810
                },
×
3811
        }
×
3812

×
3813
        csum := s.newRandomChecksum()
×
3814

×
3815
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
3816
                {
×
3817
                        EventID: updatedInfo.LastProcessedEvent,
×
3818
                        Version: common.EmptyVersion,
×
3819
                },
×
3820
        })
×
3821
        versionHistories := p.NewVersionHistories(versionHistory)
×
3822
        updatedState := &p.WorkflowMutableState{
×
3823
                ExecutionInfo:  updatedInfo,
×
3824
                ExecutionStats: updatedStats,
×
3825
                ActivityInfos: map[int64]*p.ActivityInfo{
×
3826
                        4: {
×
3827
                                Version:                  7789,
×
3828
                                ScheduleID:               4,
×
3829
                                ScheduledEventBatchID:    3,
×
3830
                                ScheduledEvent:           &types.HistoryEvent{ID: 40},
×
3831
                                ScheduledTime:            currentTime,
×
3832
                                StartedID:                6,
×
3833
                                StartedEvent:             &types.HistoryEvent{ID: 60},
×
3834
                                StartedTime:              currentTime,
×
3835
                                ScheduleToCloseTimeout:   1,
×
3836
                                ScheduleToStartTimeout:   2,
×
3837
                                StartToCloseTimeout:      3,
×
3838
                                HeartbeatTimeout:         4,
×
3839
                                LastHeartBeatUpdatedTime: currentTime,
×
3840
                                TimerTaskStatus:          1,
×
3841
                        },
×
3842
                        5: {
×
3843
                                Version:                  7789,
×
3844
                                ScheduleID:               5,
×
3845
                                ScheduledEventBatchID:    3,
×
3846
                                ScheduledEvent:           &types.HistoryEvent{ID: 50},
×
3847
                                ScheduledTime:            currentTime,
×
3848
                                StartedID:                7,
×
3849
                                StartedEvent:             &types.HistoryEvent{ID: 70},
×
3850
                                StartedTime:              currentTime,
×
3851
                                ScheduleToCloseTimeout:   1,
×
3852
                                ScheduleToStartTimeout:   2,
×
3853
                                StartToCloseTimeout:      3,
×
3854
                                HeartbeatTimeout:         4,
×
3855
                                LastHeartBeatUpdatedTime: currentTime,
×
3856
                                TimerTaskStatus:          1,
×
3857
                        }},
×
3858

×
3859
                TimerInfos: map[string]*p.TimerInfo{
×
3860
                        "t1": {
×
3861
                                Version:    2333,
×
3862
                                TimerID:    "t1",
×
3863
                                StartedID:  1,
×
3864
                                ExpiryTime: expiryTime,
×
3865
                                TaskStatus: 500,
×
3866
                        },
×
3867
                        "t2": {
×
3868
                                Version:    2333,
×
3869
                                TimerID:    "t2",
×
3870
                                StartedID:  2,
×
3871
                                ExpiryTime: expiryTime,
×
3872
                                TaskStatus: 501,
×
3873
                        },
×
3874
                        "t3": {
×
3875
                                Version:    2333,
×
3876
                                TimerID:    "t3",
×
3877
                                StartedID:  3,
×
3878
                                ExpiryTime: expiryTime,
×
3879
                                TaskStatus: 502,
×
3880
                        },
×
3881
                },
×
3882

×
3883
                ChildExecutionInfos: map[int64]*p.ChildExecutionInfo{
×
3884
                        9: {
×
3885
                                Version:         2334,
×
3886
                                InitiatedID:     9,
×
3887
                                InitiatedEvent:  &types.HistoryEvent{ID: 123},
×
3888
                                StartedID:       11,
×
3889
                                StartedRunID:    uuid.New(),
×
3890
                                StartedEvent:    nil,
×
3891
                                CreateRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3892
                                DomainID:        uuid.New(),
×
3893
                        },
×
3894
                },
×
3895

×
3896
                RequestCancelInfos: map[int64]*p.RequestCancelInfo{
×
3897
                        19: {
×
3898
                                Version:               2335,
×
3899
                                InitiatedID:           19,
×
3900
                                InitiatedEventBatchID: 17,
×
3901
                                CancelRequestID:       "cancel_requested_id",
×
3902
                        },
×
3903
                },
×
3904

×
3905
                SignalInfos: map[int64]*p.SignalInfo{
×
3906
                        39: {
×
3907
                                Version:               2336,
×
3908
                                InitiatedID:           39,
×
3909
                                InitiatedEventBatchID: 38,
×
3910
                                SignalRequestID:       "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
3911
                                SignalName:            "signalA",
×
3912
                                Input:                 []byte("signal_input_A"),
×
3913
                                Control:               []byte("signal_control_A"),
×
3914
                        },
×
3915
                },
×
3916

×
3917
                SignalRequestedIDs: map[string]struct{}{
×
3918
                        "00000000-0000-0000-0000-000000000001": {},
×
3919
                        "00000000-0000-0000-0000-000000000002": {},
×
3920
                        "00000000-0000-0000-0000-000000000003": {},
×
3921
                },
×
3922
                Checksum:         csum,
×
3923
                VersionHistories: versionHistories,
×
3924
        }
×
3925

×
3926
        err2 := s.UpdateAllMutableState(ctx, updatedState, int64(3))
×
3927
        s.NoError(err2)
×
3928

×
3929
        partialState, err2 := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecution)
×
3930
        s.NoError(err2)
×
3931
        s.NotNil(partialState, "expected valid state.")
×
3932
        partialInfo := partialState.ExecutionInfo
×
3933
        s.NotNil(partialInfo, "Valid Workflow info expected.")
×
3934
        s.assertChecksumsEqual(csum, partialState.Checksum)
×
3935

×
3936
        bufferUpdateInfo := copyWorkflowExecutionInfo(partialInfo)
×
3937
        bufferedUpdatedStats := copyExecutionStats(partialState.ExecutionStats)
×
3938
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
3939
        s.NoError(err2)
×
3940
        err2 = s.UpdateWorklowStateAndReplication(ctx, bufferUpdateInfo, bufferedUpdatedStats, versionHistories, bufferUpdateInfo.NextEventID, nil)
×
3941
        s.NoError(err2)
×
3942
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch1, false, versionHistories)
×
3943
        s.NoError(err2)
×
3944
        stats0, state0, err2 = s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
3945
        s.NoError(err2)
×
3946
        s.Equal(1, stats0.BufferedEventsCount)
×
3947
        s.True(stats0.BufferedEventsSize > 0)
×
3948
        s.assertChecksumsEqual(testWorkflowChecksum, state0.Checksum)
×
3949
        testHistory := &types.History{Events: make([]*types.HistoryEvent, 0)}
×
3950
        testHistory.Events = append(testHistory.Events, eventsBatch1...)
×
3951
        history0 := &types.History{Events: state0.BufferedEvents}
×
3952
        s.Equal(testHistory, history0)
×
3953
        testHistory.Events = append(testHistory.Events, eventsBatch2...)
×
3954

×
3955
        err2 = s.UpdateWorkflowExecutionForBufferEvents(ctx, bufferUpdateInfo, bufferedUpdatedStats, bufferUpdateInfo.NextEventID, eventsBatch2, false, versionHistories)
×
3956
        s.NoError(err2)
×
3957

×
3958
        stats1, state1, err1 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
3959
        s.NoError(err1)
×
3960
        s.NotNil(state1, "expected valid state.")
×
3961
        info1 := state1.ExecutionInfo
×
3962
        s.NotNil(info1, "Valid Workflow info expected.")
×
3963
        s.Equal(2, stats1.BufferedEventsCount)
×
3964
        s.True(stats1.BufferedEventsSize > 0)
×
3965
        s.assertChecksumsEqual(testWorkflowChecksum, state1.Checksum)
×
3966
        history1 := &types.History{Events: state1.BufferedEvents}
×
3967
        s.Equal(testHistory, history1)
×
3968

×
3969
        s.Equal(2, len(state1.ActivityInfos))
×
3970
        ai, ok := state1.ActivityInfos[4]
×
3971
        s.True(ok)
×
3972
        s.NotNil(ai)
×
3973
        s.Equal(int64(7789), ai.Version)
×
3974
        s.Equal(int64(4), ai.ScheduleID)
×
3975
        s.Equal(int64(3), ai.ScheduledEventBatchID)
×
3976
        s.Equal(int64(40), ai.ScheduledEvent.ID)
×
3977
        s.EqualTimes(currentTime, ai.ScheduledTime)
×
3978
        s.Equal(int64(6), ai.StartedID)
×
3979
        s.Equal(int64(60), ai.StartedEvent.ID)
×
3980
        s.EqualTimes(currentTime, ai.StartedTime)
×
3981
        s.Equal(int32(1), ai.ScheduleToCloseTimeout)
×
3982
        s.Equal(int32(2), ai.ScheduleToStartTimeout)
×
3983
        s.Equal(int32(3), ai.StartToCloseTimeout)
×
3984
        s.Equal(int32(4), ai.HeartbeatTimeout)
×
3985
        s.EqualTimes(currentTime, ai.LastHeartBeatUpdatedTime)
×
3986
        s.Equal(int32(1), ai.TimerTaskStatus)
×
3987

×
3988
        ai, ok = state1.ActivityInfos[5]
×
3989
        s.True(ok)
×
3990
        s.NotNil(ai)
×
3991
        s.Equal(int64(7789), ai.Version)
×
3992
        s.Equal(int64(5), ai.ScheduleID)
×
3993
        s.Equal(int64(3), ai.ScheduledEventBatchID)
×
3994
        s.Equal(int64(50), ai.ScheduledEvent.ID)
×
3995
        s.EqualTimes(currentTime, ai.ScheduledTime)
×
3996
        s.Equal(int64(7), ai.StartedID)
×
3997
        s.Equal(int64(70), ai.StartedEvent.ID)
×
3998
        s.EqualTimes(currentTime, ai.StartedTime)
×
3999
        s.Equal(int32(1), ai.ScheduleToCloseTimeout)
×
4000
        s.Equal(int32(2), ai.ScheduleToStartTimeout)
×
4001
        s.Equal(int32(3), ai.StartToCloseTimeout)
×
4002
        s.Equal(int32(4), ai.HeartbeatTimeout)
×
4003
        s.EqualTimes(currentTime, ai.LastHeartBeatUpdatedTime)
×
4004
        s.Equal(int32(1), ai.TimerTaskStatus)
×
4005

×
4006
        s.Equal(3, len(state1.TimerInfos))
×
4007
        ti, ok := state1.TimerInfos["t1"]
×
4008
        s.True(ok)
×
4009
        s.NotNil(ti)
×
4010
        s.Equal(int64(2333), ti.Version)
×
4011
        s.Equal("t1", ti.TimerID)
×
4012
        s.Equal(int64(1), ti.StartedID)
×
4013
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4014
        s.Equal(int64(500), ti.TaskStatus)
×
4015

×
4016
        ti, ok = state1.TimerInfos["t2"]
×
4017
        s.True(ok)
×
4018
        s.NotNil(ti)
×
4019
        s.Equal(int64(2333), ti.Version)
×
4020
        s.Equal("t2", ti.TimerID)
×
4021
        s.Equal(int64(2), ti.StartedID)
×
4022
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4023
        s.Equal(int64(501), ti.TaskStatus)
×
4024

×
4025
        ti, ok = state1.TimerInfos["t3"]
×
4026
        s.True(ok)
×
4027
        s.NotNil(ti)
×
4028
        s.Equal(int64(2333), ti.Version)
×
4029
        s.Equal("t3", ti.TimerID)
×
4030
        s.Equal(int64(3), ti.StartedID)
×
4031
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4032
        s.Equal(int64(502), ti.TaskStatus)
×
4033

×
4034
        s.Equal(1, len(state1.ChildExecutionInfos))
×
4035
        ci, ok := state1.ChildExecutionInfos[9]
×
4036
        s.True(ok)
×
4037
        s.NotNil(ci)
×
4038
        s.Equal(updatedState.ChildExecutionInfos[9], ci)
×
4039

×
4040
        s.Equal(1, len(state1.RequestCancelInfos))
×
4041
        rci, ok := state1.RequestCancelInfos[19]
×
4042
        s.True(ok)
×
4043
        s.NotNil(rci)
×
4044
        s.Equal(int64(2335), rci.Version)
×
4045

×
4046
        s.Equal(1, len(state1.SignalInfos))
×
4047
        si, ok := state1.SignalInfos[39]
×
4048
        s.True(ok)
×
4049
        s.NotNil(si)
×
4050
        s.Equal(int64(2336), si.Version)
×
4051

×
4052
        s.Equal(3, len(state1.SignalRequestedIDs))
×
4053
        _, contains := state1.SignalRequestedIDs["00000000-0000-0000-0000-000000000001"]
×
4054
        s.True(contains)
×
4055
        _, contains = state1.SignalRequestedIDs["00000000-0000-0000-0000-000000000002"]
×
4056
        s.True(contains)
×
4057
        _, contains = state1.SignalRequestedIDs["00000000-0000-0000-0000-000000000003"]
×
4058
        s.True(contains)
×
4059

×
4060
        s.Equal(3, len(state1.BufferedEvents))
×
4061

×
4062
        updatedInfo1 := copyWorkflowExecutionInfo(info1)
×
4063
        updatedStats1 := copyExecutionStats(state1.ExecutionStats)
×
4064
        updatedInfo1.NextEventID = int64(3)
×
4065
        resetActivityInfos := []*p.ActivityInfo{
×
4066
                {
×
4067
                        Version:                  8789,
×
4068
                        ScheduleID:               40,
×
4069
                        ScheduledEventBatchID:    30,
×
4070
                        ScheduledEvent:           &types.HistoryEvent{ID: 400},
×
4071
                        ScheduledTime:            currentTime,
×
4072
                        StartedID:                60,
×
4073
                        StartedEvent:             &types.HistoryEvent{ID: 600},
×
4074
                        StartedTime:              currentTime,
×
4075
                        ScheduleToCloseTimeout:   10,
×
4076
                        ScheduleToStartTimeout:   20,
×
4077
                        StartToCloseTimeout:      30,
×
4078
                        HeartbeatTimeout:         40,
×
4079
                        LastHeartBeatUpdatedTime: currentTime,
×
4080
                        TimerTaskStatus:          1,
×
4081
                }}
×
4082

×
4083
        resetTimerInfos := []*p.TimerInfo{
×
4084
                {
×
4085
                        Version:    3333,
×
4086
                        TimerID:    "t1_new",
×
4087
                        StartedID:  1,
×
4088
                        ExpiryTime: expiryTime,
×
4089
                        TaskStatus: 600,
×
4090
                },
×
4091
                {
×
4092
                        Version:    3333,
×
4093
                        TimerID:    "t2_new",
×
4094
                        StartedID:  2,
×
4095
                        ExpiryTime: expiryTime,
×
4096
                        TaskStatus: 601,
×
4097
                }}
×
4098

×
4099
        resetChildExecutionInfos := []*p.ChildExecutionInfo{
×
4100
                {
×
4101
                        Version:         3334,
×
4102
                        InitiatedID:     10,
×
4103
                        InitiatedEvent:  &types.HistoryEvent{ID: 10},
×
4104
                        StartedID:       15,
×
4105
                        StartedRunID:    uuid.New(),
×
4106
                        StartedEvent:    nil,
×
4107
                        CreateRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4108
                        DomainID:        uuid.New(),
×
4109
                }}
×
4110

×
4111
        resetRequestCancelInfos := []*p.RequestCancelInfo{
×
4112
                {
×
4113
                        Version:         3335,
×
4114
                        InitiatedID:     29,
×
4115
                        CancelRequestID: "new_cancel_requested_id",
×
4116
                }}
×
4117

×
4118
        resetSignalInfos := []*p.SignalInfo{
×
4119
                {
×
4120
                        Version:         3336,
×
4121
                        InitiatedID:     39,
×
4122
                        SignalRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4123
                        SignalName:      "signalB",
×
4124
                        Input:           []byte("signal_input_b"),
×
4125
                        Control:         []byte("signal_control_b"),
×
4126
                },
×
4127
                {
×
4128
                        Version:         3336,
×
4129
                        InitiatedID:     42,
×
4130
                        SignalRequestID: "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa",
×
4131
                        SignalName:      "signalC",
×
4132
                        Input:           []byte("signal_input_c"),
×
4133
                        Control:         []byte("signal_control_c"),
×
4134
                }}
×
4135
        err3 := s.ConflictResolveWorkflowExecution(
×
4136
                ctx,
×
4137
                updatedInfo1,
×
4138
                updatedStats1,
×
4139
                int64(5),
×
4140
                resetActivityInfos,
×
4141
                resetTimerInfos,
×
4142
                resetChildExecutionInfos,
×
4143
                resetRequestCancelInfos,
×
4144
                resetSignalInfos,
×
4145
                nil,
×
4146
                versionHistories,
×
4147
        )
×
4148
        s.NoError(err3)
×
4149

×
4150
        stats4, state4, err4 := s.GetWorkflowExecutionInfoWithStats(ctx, domainID, workflowExecution)
×
4151
        s.NoError(err4)
×
4152
        s.NotNil(state4, "expected valid state.")
×
4153
        s.Equal(0, stats4.BufferedEventsCount)
×
4154
        s.Equal(0, stats4.BufferedEventsSize)
×
4155

×
4156
        info4 := state4.ExecutionInfo
×
4157
        log.Printf("%+v", info4)
×
4158
        s.NotNil(info4, "Valid Workflow info expected.")
×
4159
        s.Equal(int64(3), info4.NextEventID)
×
4160
        s.Equal("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", info4.FirstExecutionRunID)
×
4161
        s.Equal(partitionConfig, info4.PartitionConfig)
×
4162

×
4163
        s.Equal(1, len(state4.ActivityInfos))
×
4164
        ai, ok = state4.ActivityInfos[40]
×
4165
        s.True(ok)
×
4166
        s.NotNil(ai)
×
4167
        s.Equal(int64(8789), ai.Version)
×
4168
        s.Equal(int64(40), ai.ScheduleID)
×
4169
        s.Equal(int64(30), ai.ScheduledEventBatchID)
×
4170
        s.Equal(int64(400), ai.ScheduledEvent.ID)
×
4171
        s.Equal(currentTime.Unix(), ai.ScheduledTime.Unix())
×
4172
        s.Equal(int64(60), ai.StartedID)
×
4173
        s.Equal(int64(600), ai.StartedEvent.ID)
×
4174
        s.Equal(currentTime.Unix(), ai.StartedTime.Unix())
×
4175
        s.Equal(int32(10), ai.ScheduleToCloseTimeout)
×
4176
        s.Equal(int32(20), ai.ScheduleToStartTimeout)
×
4177
        s.Equal(int32(30), ai.StartToCloseTimeout)
×
4178
        s.Equal(int32(40), ai.HeartbeatTimeout)
×
4179
        s.Equal(currentTime.Unix(), ai.LastHeartBeatUpdatedTime.Unix())
×
4180
        s.Equal(int32(1), ai.TimerTaskStatus)
×
4181

×
4182
        s.Equal(2, len(state4.TimerInfos))
×
4183
        ti, ok = state4.TimerInfos["t1_new"]
×
4184
        s.True(ok)
×
4185
        s.NotNil(ai)
×
4186
        s.Equal(int64(3333), ti.Version)
×
4187
        s.Equal("t1_new", ti.TimerID)
×
4188
        s.Equal(int64(1), ti.StartedID)
×
4189
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4190
        s.Equal(int64(600), ti.TaskStatus)
×
4191

×
4192
        ti, ok = state4.TimerInfos["t2_new"]
×
4193
        s.True(ok)
×
4194
        s.NotNil(ai)
×
4195
        s.Equal(int64(3333), ti.Version)
×
4196
        s.Equal("t2_new", ti.TimerID)
×
4197
        s.Equal(int64(2), ti.StartedID)
×
4198
        s.EqualTimes(expiryTime, ti.ExpiryTime)
×
4199
        s.Equal(int64(601), ti.TaskStatus)
×
4200

×
4201
        s.Equal(1, len(state4.ChildExecutionInfos))
×
4202
        ci, ok = state4.ChildExecutionInfos[10]
×
4203
        s.True(ok)
×
4204
        s.NotNil(ci)
×
4205
        s.Equal(resetChildExecutionInfos[0], ci)
×
4206

×
4207
        s.Equal(1, len(state4.RequestCancelInfos))
×
4208
        rci, ok = state4.RequestCancelInfos[29]
×
4209
        s.True(ok)
×
4210
        s.NotNil(rci)
×
4211
        s.Equal(int64(3335), rci.Version)
×
4212
        s.Equal(int64(29), rci.InitiatedID)
×
4213
        s.Equal("new_cancel_requested_id", rci.CancelRequestID)
×
4214

×
4215
        s.Equal(2, len(state4.SignalInfos))
×
4216
        si, ok = state4.SignalInfos[39]
×
4217
        s.True(ok)
×
4218
        s.NotNil(si)
×
4219
        s.Equal(int64(3336), si.Version)
×
4220
        s.Equal(int64(39), si.InitiatedID)
×
4221
        s.Equal("signalB", si.SignalName)
×
4222
        s.Equal([]byte("signal_input_b"), si.Input)
×
4223
        s.Equal([]byte("signal_control_b"), si.Control)
×
4224

×
4225
        si, ok = state4.SignalInfos[42]
×
4226
        s.True(ok)
×
4227
        s.NotNil(si)
×
4228
        s.Equal(int64(3336), si.Version)
×
4229
        s.Equal(int64(42), si.InitiatedID)
×
4230
        s.Equal("signalC", si.SignalName)
×
4231
        s.Equal([]byte("signal_input_c"), si.Input)
×
4232
        s.Equal([]byte("signal_control_c"), si.Control)
×
4233

×
4234
        s.Equal(0, len(state4.SignalRequestedIDs))
×
4235

×
4236
        s.Equal(0, len(state4.BufferedEvents))
×
4237
        s.assertChecksumsEqual(testWorkflowChecksum, state4.Checksum)
×
4238

×
4239
}
×
4240

4241
// TestConflictResolveWorkflowExecutionWithCASMismatch test
4242
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithCASMismatch() {
×
4243
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4244
        defer cancel()
×
4245

×
4246
        domainID := "4ca1faac-1a3a-47af-8e51-fdaa2b3d45b9"
×
4247
        workflowID := "test-reset-mutable-state-test-mismatch"
×
4248

×
4249
        // first create a workflow and continue as new it
×
4250
        workflowExecutionReset := types.WorkflowExecution{
×
4251
                WorkflowID: workflowID,
×
4252
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4253
        }
×
4254
        partitionConfig := map[string]string{
×
4255
                "userid": uuid.New(),
×
4256
        }
×
4257
        nextEventID := int64(3)
×
4258
        resp, err := s.CreateWorkflowExecution(
×
4259
                ctx,
×
4260
                domainID,
×
4261
                workflowExecutionReset,
×
4262
                "taskList",
×
4263
                "wType",
×
4264
                20,
×
4265
                13,
×
4266
                nil,
×
4267
                nextEventID,
×
4268
                0,
×
4269
                2,
×
4270
                nil,
×
4271
                partitionConfig,
×
4272
        )
×
4273
        s.NoError(err)
×
4274
        s.NotNil(resp)
×
4275

×
4276
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4277
        s.NoError(err)
×
4278

×
4279
        info := state.ExecutionInfo
×
4280
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
4281
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
4282
        continueAsNewInfo.State = p.WorkflowStateRunning
×
4283
        continueAsNewInfo.NextEventID = int64(5)
×
4284
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
4285

×
4286
        workflowExecutionCurrent := types.WorkflowExecution{
×
4287
                WorkflowID: workflowID,
×
4288
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
4289
        }
×
4290
        err = s.ContinueAsNewExecution(
×
4291
                ctx,
×
4292
                continueAsNewInfo,
×
4293
                continueAsNewStats,
×
4294
                info.NextEventID,
×
4295
                workflowExecutionCurrent,
×
4296
                int64(3),
×
4297
                int64(2),
×
4298
                nil,
×
4299
        )
×
4300
        s.NoError(err)
×
4301

×
4302
        runID1, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4303
        s.NoError(err)
×
4304
        s.Equal(workflowExecutionCurrent.GetRunID(), runID1)
×
4305
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4306
        s.NoError(err)
×
4307
        currentInfo := copyWorkflowExecutionInfo(state.ExecutionInfo)
×
4308
        currentStats := copyExecutionStats(state.ExecutionStats)
×
4309
        currentInfo.State = p.WorkflowStateCompleted
×
4310
        currentInfo.CloseStatus = p.WorkflowCloseStatusCompleted
×
4311
        currentInfo.NextEventID = int64(6)
×
4312
        currentInfo.LastProcessedEvent = int64(2)
×
4313
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4314
                {
×
4315
                        EventID: currentInfo.LastProcessedEvent,
×
4316
                        Version: common.EmptyVersion,
×
4317
                },
×
4318
        })
×
4319
        versionHistories := p.NewVersionHistories(versionHistory)
×
4320
        err3 := s.UpdateWorkflowExecutionAndFinish(ctx, currentInfo, currentStats, int64(3), versionHistories)
×
4321
        s.NoError(err3)
×
4322
        runID1, err = s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4323
        s.NoError(err)
×
4324
        s.Equal(workflowExecutionCurrent.GetRunID(), runID1)
×
4325

×
4326
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
4327
                DomainID:                    domainID,
×
4328
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
4329
                RunID:                       workflowExecutionReset.GetRunID(),
×
4330
                ParentDomainID:              uuid.New(),
×
4331
                ParentWorkflowID:            "some random parent workflow ID",
×
4332
                ParentRunID:                 uuid.New(),
×
4333
                InitiatedID:                 12345,
×
4334
                TaskList:                    "some random tasklist",
×
4335
                WorkflowTypeName:            "some random workflow type name",
×
4336
                WorkflowTimeout:             1112,
×
4337
                DecisionStartToCloseTimeout: 14,
×
4338
                State:                       p.WorkflowStateRunning,
×
4339
                LastFirstEventID:            common.FirstEventID,
×
4340
                NextEventID:                 123,
×
4341
                CreateRequestID:             uuid.New(),
×
4342
                DecisionVersion:             common.EmptyVersion,
×
4343
                DecisionScheduleID:          111,
×
4344
                DecisionStartedID:           222,
×
4345
                DecisionRequestID:           uuid.New(),
×
4346
                DecisionTimeout:             0,
×
4347
        }
×
4348
        resetStats := &p.ExecutionStats{}
×
4349
        resetActivityInfos := []*p.ActivityInfo{}
×
4350
        resetTimerInfos := []*p.TimerInfo{}
×
4351
        resetChildExecutionInfos := []*p.ChildExecutionInfo{}
×
4352
        resetRequestCancelInfos := []*p.RequestCancelInfo{}
×
4353
        resetSignalInfos := []*p.SignalInfo{}
×
4354

×
4355
        err = s.ConflictResolveWorkflowExecution(
×
4356
                ctx,
×
4357
                resetExecutionInfo,
×
4358
                resetStats,
×
4359
                continueAsNewInfo.NextEventID,
×
4360
                resetActivityInfos,
×
4361
                resetTimerInfos,
×
4362
                resetChildExecutionInfos,
×
4363
                resetRequestCancelInfos,
×
4364
                resetSignalInfos,
×
4365
                nil,
×
4366
                versionHistories,
×
4367
        )
×
4368
        s.NotNil(err)
×
4369

×
4370
        err = s.ConflictResolveWorkflowExecution(
×
4371
                ctx,
×
4372
                resetExecutionInfo,
×
4373
                resetStats,
×
4374
                continueAsNewInfo.NextEventID,
×
4375
                resetActivityInfos,
×
4376
                resetTimerInfos,
×
4377
                resetChildExecutionInfos,
×
4378
                resetRequestCancelInfos,
×
4379
                resetSignalInfos,
×
4380
                nil,
×
4381
                versionHistories,
×
4382
        )
×
4383
        s.NotNil(err)
×
4384

×
4385
        err = s.ConflictResolveWorkflowExecution(
×
4386
                ctx,
×
4387
                resetExecutionInfo,
×
4388
                resetStats,
×
4389
                continueAsNewInfo.NextEventID,
×
4390
                resetActivityInfos,
×
4391
                resetTimerInfos,
×
4392
                resetChildExecutionInfos,
×
4393
                resetRequestCancelInfos,
×
4394
                resetSignalInfos,
×
4395
                nil,
×
4396
                versionHistories,
×
4397
        )
×
4398
        s.NotNil(err)
×
4399

×
4400
        // this test only assert whether the current workflow execution record is reset
×
4401
        runID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4402
        s.NoError(err)
×
4403
        s.Equal(workflowExecutionCurrent.GetRunID(), runID)
×
4404
}
×
4405

4406
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelf test
4407
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelf() {
×
4408
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4409
        defer cancel()
×
4410

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

×
4414
        // first create a workflow and continue as new it
×
4415
        workflowExecutionReset := types.WorkflowExecution{
×
4416
                WorkflowID: workflowID,
×
4417
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4418
        }
×
4419
        nextEventID := int64(3)
×
4420
        partitionConfig := map[string]string{
×
4421
                "userid": uuid.New(),
×
4422
        }
×
4423
        resp, err := s.CreateWorkflowExecution(
×
4424
                ctx,
×
4425
                domainID,
×
4426
                workflowExecutionReset,
×
4427
                "taskList",
×
4428
                "wType",
×
4429
                20,
×
4430
                13,
×
4431
                nil,
×
4432
                nextEventID,
×
4433
                0,
×
4434
                2,
×
4435
                nil,
×
4436
                partitionConfig,
×
4437
        )
×
4438
        s.NoError(err)
×
4439
        s.NotNil(resp)
×
4440

×
4441
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4442
        s.NoError(err)
×
4443

×
4444
        info := state.ExecutionInfo
×
4445
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
4446
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
4447
        continueAsNewInfo.State = p.WorkflowStateRunning
×
4448
        continueAsNewInfo.NextEventID = int64(5)
×
4449
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
4450

×
4451
        workflowExecutionCurrent := types.WorkflowExecution{
×
4452
                WorkflowID: workflowID,
×
4453
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
4454
        }
×
4455
        err = s.ContinueAsNewExecution(
×
4456
                ctx,
×
4457
                continueAsNewInfo,
×
4458
                continueAsNewStats,
×
4459
                info.NextEventID,
×
4460
                workflowExecutionCurrent,
×
4461
                int64(3),
×
4462
                int64(2),
×
4463
                nil,
×
4464
        )
×
4465
        s.NoError(err)
×
4466

×
4467
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4468
        s.NoError(err)
×
4469
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
4470
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4471
        s.NoError(err)
×
4472
        currentInfo := copyWorkflowExecutionInfo(state.ExecutionInfo)
×
4473
        currentInfo.State = p.WorkflowStateCompleted
×
4474
        currentInfo.CloseStatus = p.WorkflowCloseStatusTerminated
×
4475

×
4476
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
4477
                DomainID:                    domainID,
×
4478
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
4479
                RunID:                       workflowExecutionReset.GetRunID(),
×
4480
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
4481
                ParentDomainID:              uuid.New(),
×
4482
                ParentWorkflowID:            "some random parent workflow ID",
×
4483
                ParentRunID:                 uuid.New(),
×
4484
                InitiatedID:                 12345,
×
4485
                TaskList:                    "some random tasklist",
×
4486
                WorkflowTypeName:            "some random workflow type name",
×
4487
                WorkflowTimeout:             1112,
×
4488
                DecisionStartToCloseTimeout: 14,
×
4489
                State:                       p.WorkflowStateCompleted,
×
4490
                CloseStatus:                 p.WorkflowCloseStatusCompleted,
×
4491
                LastFirstEventID:            common.FirstEventID,
×
4492
                NextEventID:                 123,
×
4493
                CreateRequestID:             uuid.New(),
×
4494
                DecisionVersion:             common.EmptyVersion,
×
4495
                DecisionScheduleID:          111,
×
4496
                DecisionStartedID:           222,
×
4497
                DecisionRequestID:           uuid.New(),
×
4498
                DecisionTimeout:             0,
×
4499
                AutoResetPoints:             &types.ResetPoints{},
×
4500
                PartitionConfig:             nil,
×
4501
        }
×
4502
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4503
                {
×
4504
                        EventID: resetExecutionInfo.DecisionScheduleID,
×
4505
                        Version: common.EmptyVersion,
×
4506
                },
×
4507
        })
×
4508
        versionHistories := p.NewVersionHistories(versionHistory)
×
4509

×
4510
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
4511
                RangeID: s.ShardInfo.RangeID,
×
4512
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
4513
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
4514
                        ExecutionInfo:  resetExecutionInfo,
×
4515
                        ExecutionStats: &p.ExecutionStats{},
×
4516
                        Condition:      int64(5),
×
4517

×
4518
                        ActivityInfos:       []*p.ActivityInfo{},
×
4519
                        TimerInfos:          []*p.TimerInfo{},
×
4520
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4521
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
4522
                        SignalInfos:         []*p.SignalInfo{},
×
4523
                        SignalRequestedIDs:  []string{},
×
4524
                        VersionHistories:    versionHistories,
×
4525
                },
×
4526
                NewWorkflowSnapshot: nil,
×
4527
                CurrentWorkflowMutation: &p.WorkflowMutation{
×
4528
                        ExecutionInfo:  currentInfo,
×
4529
                        ExecutionStats: &p.ExecutionStats{},
×
4530
                        Condition:      int64(3),
×
4531

×
4532
                        UpsertActivityInfos:       []*p.ActivityInfo{},
×
4533
                        UpsertTimerInfos:          []*p.TimerInfo{},
×
4534
                        UpsertChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4535
                        UpsertRequestCancelInfos:  []*p.RequestCancelInfo{},
×
4536
                        UpsertSignalInfos:         []*p.SignalInfo{},
×
4537
                        UpsertSignalRequestedIDs:  []string{},
×
4538
                        VersionHistories:          versionHistories,
×
4539
                },
×
4540
                Encoding: pickRandomEncoding(),
×
4541
        }
×
4542
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4543
        s.Error(err)
×
4544
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
4545
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4546
        s.NoError(err)
×
4547

×
4548
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
4549
                DomainID:   domainID,
×
4550
                WorkflowID: workflowID,
×
4551
        })
×
4552
        s.NoError(err)
×
4553
        s.Equal(resetExecutionInfo.RunID, currentRecord.RunID)
×
4554
        s.Equal(resetExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
4555
        s.Equal(resetExecutionInfo.State, currentRecord.State)
×
4556
        s.Equal(resetExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
4557
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
4558

×
4559
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4560
        s.NoError(err)
×
4561
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
4562
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
4563
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
4564
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
4565

×
4566
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4567
        s.NoError(err)
×
4568
        state.ExecutionInfo.StartTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.StartTimestamp
×
4569
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.LastUpdatedTimestamp
×
4570
        state.ExecutionInfo.ExpirationTime = resetReq.CurrentWorkflowMutation.ExecutionInfo.ExpirationTime
×
4571
        s.Equal(resetReq.CurrentWorkflowMutation.ExecutionInfo, state.ExecutionInfo)
×
4572
}
×
4573

4574
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelfWithContinueAsNew test
4575
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsNotSelfWithContinueAsNew() {
×
4576
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4577
        defer cancel()
×
4578

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

×
4582
        // first create a workflow and continue as new it
×
4583
        workflowExecutionReset := types.WorkflowExecution{
×
4584
                WorkflowID: workflowID,
×
4585
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4586
        }
×
4587
        nextEventID := int64(3)
×
4588
        partitionConfig := map[string]string{
×
4589
                "userid": uuid.New(),
×
4590
        }
×
4591
        resp, err := s.CreateWorkflowExecution(
×
4592
                ctx,
×
4593
                domainID,
×
4594
                workflowExecutionReset,
×
4595
                "taskList",
×
4596
                "wType",
×
4597
                20,
×
4598
                13,
×
4599
                nil,
×
4600
                nextEventID,
×
4601
                0,
×
4602
                2,
×
4603
                nil,
×
4604
                partitionConfig,
×
4605
        )
×
4606
        s.NoError(err)
×
4607
        s.NotNil(resp)
×
4608

×
4609
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4610
        s.NoError(err)
×
4611
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
4612

×
4613
        info := state.ExecutionInfo
×
4614
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
4615
        continueAsNewInfo.State = p.WorkflowStateRunning
×
4616
        continueAsNewInfo.NextEventID = int64(5)
×
4617
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
4618

×
4619
        workflowExecutionCurrent := types.WorkflowExecution{
×
4620
                WorkflowID: workflowID,
×
4621
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
4622
        }
×
4623
        err = s.ContinueAsNewExecution(
×
4624
                ctx,
×
4625
                continueAsNewInfo,
×
4626
                continueAsNewStats,
×
4627
                info.NextEventID,
×
4628
                workflowExecutionCurrent,
×
4629
                int64(3),
×
4630
                int64(2),
×
4631
                nil,
×
4632
        )
×
4633
        s.NoError(err)
×
4634

×
4635
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
4636
        s.NoError(err)
×
4637
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
4638
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4639
        s.NoError(err)
×
4640
        currentInfo := copyWorkflowExecutionInfo(state.ExecutionInfo)
×
4641
        currentStats := copyExecutionStats(state.ExecutionStats)
×
4642
        currentInfo.State = p.WorkflowStateCompleted
×
4643
        currentInfo.CloseStatus = p.WorkflowCloseStatusTerminated
×
4644
        decisionScheduleID := int64(111)
×
4645
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4646
                {
×
4647
                        EventID: decisionScheduleID,
×
4648
                        Version: common.EmptyVersion,
×
4649
                },
×
4650
        })
×
4651
        versionHistories := p.NewVersionHistories(versionHistory)
×
4652

×
4653
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
4654
                DomainID:                    domainID,
×
4655
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
4656
                RunID:                       workflowExecutionReset.GetRunID(),
×
4657
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
4658
                ParentDomainID:              uuid.New(),
×
4659
                ParentWorkflowID:            "some random parent workflow ID",
×
4660
                ParentRunID:                 uuid.New(),
×
4661
                InitiatedID:                 12345,
×
4662
                TaskList:                    "some random tasklist",
×
4663
                WorkflowTypeName:            "some random workflow type name",
×
4664
                WorkflowTimeout:             1112,
×
4665
                DecisionStartToCloseTimeout: 14,
×
4666
                State:                       p.WorkflowStateCompleted,
×
4667
                CloseStatus:                 p.WorkflowCloseStatusContinuedAsNew,
×
4668
                LastFirstEventID:            common.FirstEventID,
×
4669
                NextEventID:                 123,
×
4670
                CreateRequestID:             uuid.New(),
×
4671
                DecisionVersion:             common.EmptyVersion,
×
4672
                DecisionScheduleID:          decisionScheduleID,
×
4673
                DecisionStartedID:           222,
×
4674
                DecisionRequestID:           uuid.New(),
×
4675
                DecisionTimeout:             0,
×
4676
                AutoResetPoints:             &types.ResetPoints{},
×
4677
                PartitionConfig:             map[string]string{"zone": "dca1"},
×
4678
        }
×
4679
        newWorkflowExecutionInfo := copyWorkflowExecutionInfo(resetExecutionInfo)
×
4680
        newWorkflowExecutionStats := &p.ExecutionStats{}
×
4681
        newWorkflowExecutionInfo.CreateRequestID = uuid.New()
×
4682
        newWorkflowExecutionInfo.RunID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa2"
×
4683
        newWorkflowExecutionInfo.State = p.WorkflowStateRunning
×
4684
        newWorkflowExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
4685
        newWorkflowExecutionInfo.PartitionConfig = map[string]string{"user": uuid.New()}
×
4686

×
4687
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
4688
                RangeID: s.ShardInfo.RangeID,
×
4689
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
4690
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
4691
                        ExecutionInfo:  resetExecutionInfo,
×
4692
                        ExecutionStats: &p.ExecutionStats{},
×
4693
                        Condition:      int64(5),
×
4694

×
4695
                        ActivityInfos:       []*p.ActivityInfo{},
×
4696
                        TimerInfos:          []*p.TimerInfo{},
×
4697
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4698
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
4699
                        SignalInfos:         []*p.SignalInfo{},
×
4700
                        SignalRequestedIDs:  []string{},
×
4701
                        VersionHistories:    versionHistories,
×
4702
                },
×
4703
                NewWorkflowSnapshot: &p.WorkflowSnapshot{
×
4704
                        ExecutionInfo:  newWorkflowExecutionInfo,
×
4705
                        ExecutionStats: newWorkflowExecutionStats,
×
4706
                        Condition:      0,
×
4707

×
4708
                        ActivityInfos:       []*p.ActivityInfo{},
×
4709
                        TimerInfos:          []*p.TimerInfo{},
×
4710
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4711
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
4712
                        SignalInfos:         []*p.SignalInfo{},
×
4713
                        SignalRequestedIDs:  []string{},
×
4714
                        VersionHistories:    versionHistories,
×
4715
                },
×
4716
                CurrentWorkflowMutation: &p.WorkflowMutation{
×
4717
                        ExecutionInfo:  currentInfo,
×
4718
                        ExecutionStats: currentStats,
×
4719
                        Condition:      int64(3),
×
4720

×
4721
                        UpsertActivityInfos:       []*p.ActivityInfo{},
×
4722
                        UpsertTimerInfos:          []*p.TimerInfo{},
×
4723
                        UpsertChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4724
                        UpsertRequestCancelInfos:  []*p.RequestCancelInfo{},
×
4725
                        UpsertSignalInfos:         []*p.SignalInfo{},
×
4726
                        UpsertSignalRequestedIDs:  []string{},
×
4727
                        VersionHistories:          versionHistories,
×
4728
                },
×
4729
                Encoding: pickRandomEncoding(),
×
4730
        }
×
4731
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4732
        s.Error(err)
×
4733
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
4734
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4735
        s.NoError(err)
×
4736

×
4737
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
4738
                DomainID:   domainID,
×
4739
                WorkflowID: workflowID,
×
4740
        })
×
4741
        s.NoError(err)
×
4742
        s.Equal(newWorkflowExecutionInfo.RunID, currentRecord.RunID)
×
4743
        s.Equal(newWorkflowExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
4744
        s.Equal(newWorkflowExecutionInfo.State, currentRecord.State)
×
4745
        s.Equal(newWorkflowExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
4746
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
4747

×
4748
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4749
        s.NoError(err)
×
4750
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
4751
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
4752
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
4753
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
4754

×
4755
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionCurrent)
×
4756
        s.NoError(err)
×
4757
        state.ExecutionInfo.StartTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.StartTimestamp
×
4758
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.CurrentWorkflowMutation.ExecutionInfo.LastUpdatedTimestamp
×
4759
        state.ExecutionInfo.ExpirationTime = resetReq.CurrentWorkflowMutation.ExecutionInfo.ExpirationTime
×
4760
        s.Equal(resetReq.CurrentWorkflowMutation.ExecutionInfo, state.ExecutionInfo)
×
4761

×
4762
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, types.WorkflowExecution{
×
4763
                WorkflowID: workflowID,
×
4764
                RunID:      resetReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
4765
        })
×
4766
        s.NoError(err)
×
4767
        state.ExecutionInfo.StartTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
4768
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
4769
        state.ExecutionInfo.ExpirationTime = resetReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
4770
        s.Equal(resetReq.NewWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
4771
}
×
4772

4773
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelf test
4774
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelf() {
×
4775
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4776
        defer cancel()
×
4777

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

×
4781
        // first create a workflow and continue as new it
×
4782
        workflowExecutionReset := types.WorkflowExecution{
×
4783
                WorkflowID: workflowID,
×
4784
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4785
        }
×
4786
        partitionConfig := map[string]string{
×
4787
                "userid": uuid.New(),
×
4788
        }
×
4789
        nextEventID := int64(3)
×
4790
        resp, err := s.CreateWorkflowExecution(
×
4791
                ctx,
×
4792
                domainID,
×
4793
                workflowExecutionReset,
×
4794
                "taskList",
×
4795
                "wType",
×
4796
                20,
×
4797
                13,
×
4798
                nil,
×
4799
                nextEventID,
×
4800
                0,
×
4801
                2,
×
4802
                nil,
×
4803
                partitionConfig,
×
4804
        )
×
4805
        s.NoError(err)
×
4806
        s.NotNil(resp)
×
4807

×
4808
        _, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4809
        s.NoError(err)
×
4810

×
4811
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
4812
                DomainID:                    domainID,
×
4813
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
4814
                RunID:                       workflowExecutionReset.GetRunID(),
×
4815
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
4816
                ParentDomainID:              uuid.New(),
×
4817
                ParentWorkflowID:            "some random parent workflow ID",
×
4818
                ParentRunID:                 uuid.New(),
×
4819
                InitiatedID:                 12345,
×
4820
                TaskList:                    "some random tasklist",
×
4821
                WorkflowTypeName:            "some random workflow type name",
×
4822
                WorkflowTimeout:             1112,
×
4823
                DecisionStartToCloseTimeout: 14,
×
4824
                State:                       p.WorkflowStateRunning,
×
4825
                CloseStatus:                 p.WorkflowCloseStatusNone,
×
4826
                LastFirstEventID:            common.FirstEventID,
×
4827
                NextEventID:                 123,
×
4828
                CreateRequestID:             uuid.New(),
×
4829
                DecisionVersion:             common.EmptyVersion,
×
4830
                DecisionScheduleID:          111,
×
4831
                DecisionStartedID:           222,
×
4832
                DecisionRequestID:           uuid.New(),
×
4833
                DecisionTimeout:             0,
×
4834
                AutoResetPoints:             &types.ResetPoints{},
×
4835
                PartitionConfig:             nil,
×
4836
        }
×
4837
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4838
                {
×
4839
                        EventID: resetExecutionInfo.DecisionScheduleID,
×
4840
                        Version: common.EmptyVersion,
×
4841
                },
×
4842
        })
×
4843
        versionHistories := p.NewVersionHistories(versionHistory)
×
4844

×
4845
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
4846
                RangeID: s.ShardInfo.RangeID,
×
4847
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
4848
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
4849
                        ExecutionInfo:  resetExecutionInfo,
×
4850
                        ExecutionStats: &p.ExecutionStats{},
×
4851
                        Condition:      nextEventID,
×
4852

×
4853
                        ActivityInfos:       []*p.ActivityInfo{},
×
4854
                        TimerInfos:          []*p.TimerInfo{},
×
4855
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4856
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
4857
                        SignalInfos:         []*p.SignalInfo{},
×
4858
                        SignalRequestedIDs:  []string{},
×
4859
                        VersionHistories:    versionHistories,
×
4860
                },
×
4861
                NewWorkflowSnapshot:     nil,
×
4862
                CurrentWorkflowMutation: nil,
×
4863
                Encoding:                pickRandomEncoding(),
×
4864
        }
×
4865
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4866
        s.Error(err)
×
4867
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
4868
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
4869
        s.NoError(err)
×
4870

×
4871
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
4872
                DomainID:   domainID,
×
4873
                WorkflowID: workflowID,
×
4874
        })
×
4875
        s.NoError(err)
×
4876
        s.Equal(resetExecutionInfo.RunID, currentRecord.RunID)
×
4877
        s.Equal(resetExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
4878
        s.Equal(resetExecutionInfo.State, currentRecord.State)
×
4879
        s.Equal(resetExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
4880
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
4881

×
4882
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4883
        s.NoError(err)
×
4884
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
4885
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
4886
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
4887
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
4888
}
×
4889

4890
// TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelfWithContinueAsNew test
4891
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionCurrentIsSelfWithContinueAsNew() {
×
4892
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
4893
        defer cancel()
×
4894

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

×
4898
        // first create a workflow and continue as new it
×
4899
        workflowExecutionReset := types.WorkflowExecution{
×
4900
                WorkflowID: workflowID,
×
4901
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
4902
        }
×
4903
        partitionConfig := map[string]string{
×
4904
                "userid": uuid.New(),
×
4905
        }
×
4906
        nextEventID := int64(3)
×
4907
        resp, err := s.CreateWorkflowExecution(
×
4908
                ctx,
×
4909
                domainID,
×
4910
                workflowExecutionReset,
×
4911
                "taskList",
×
4912
                "wType",
×
4913
                20,
×
4914
                13,
×
4915
                nil,
×
4916
                nextEventID,
×
4917
                0,
×
4918
                2,
×
4919
                nil,
×
4920
                partitionConfig,
×
4921
        )
×
4922
        s.NoError(err)
×
4923
        s.NotNil(resp)
×
4924

×
4925
        _, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
4926
        s.NoError(err)
×
4927

×
4928
        decisionScheduleID := int64(111)
×
4929
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
4930
                {
×
4931
                        EventID: decisionScheduleID,
×
4932
                        Version: common.EmptyVersion,
×
4933
                },
×
4934
        })
×
4935
        versionHistories := p.NewVersionHistories(versionHistory)
×
4936
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
4937
                DomainID:                    domainID,
×
4938
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
4939
                RunID:                       workflowExecutionReset.GetRunID(),
×
4940
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
4941
                ParentDomainID:              uuid.New(),
×
4942
                ParentWorkflowID:            "some random parent workflow ID",
×
4943
                ParentRunID:                 uuid.New(),
×
4944
                InitiatedID:                 12345,
×
4945
                TaskList:                    "some random tasklist",
×
4946
                WorkflowTypeName:            "some random workflow type name",
×
4947
                WorkflowTimeout:             1112,
×
4948
                DecisionStartToCloseTimeout: 14,
×
4949
                State:                       p.WorkflowStateCompleted,
×
4950
                CloseStatus:                 p.WorkflowCloseStatusContinuedAsNew,
×
4951
                LastFirstEventID:            common.FirstEventID,
×
4952
                NextEventID:                 123,
×
4953
                CreateRequestID:             uuid.New(),
×
4954
                DecisionVersion:             common.EmptyVersion,
×
4955
                DecisionScheduleID:          decisionScheduleID,
×
4956
                DecisionStartedID:           222,
×
4957
                DecisionRequestID:           uuid.New(),
×
4958
                DecisionTimeout:             0,
×
4959
                AutoResetPoints:             &types.ResetPoints{},
×
4960
                PartitionConfig:             nil,
×
4961
        }
×
4962
        newWorkflowExecutionInfo := copyWorkflowExecutionInfo(resetExecutionInfo)
×
4963
        newWorkflowExecutionStats := &p.ExecutionStats{}
×
4964
        newWorkflowExecutionInfo.CreateRequestID = uuid.New()
×
4965
        newWorkflowExecutionInfo.RunID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa2"
×
4966
        newWorkflowExecutionInfo.State = p.WorkflowStateRunning
×
4967
        newWorkflowExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
4968
        newWorkflowExecutionInfo.PartitionConfig = map[string]string{"zone": "dca1"}
×
4969

×
4970
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
4971
                RangeID: s.ShardInfo.RangeID,
×
4972
                Mode:    p.ConflictResolveWorkflowModeBypassCurrent,
×
4973
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
4974
                        ExecutionInfo:  resetExecutionInfo,
×
4975
                        ExecutionStats: &p.ExecutionStats{},
×
4976
                        Condition:      nextEventID,
×
4977

×
4978
                        ActivityInfos:       []*p.ActivityInfo{},
×
4979
                        TimerInfos:          []*p.TimerInfo{},
×
4980
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4981
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
4982
                        SignalInfos:         []*p.SignalInfo{},
×
4983
                        SignalRequestedIDs:  []string{},
×
4984
                        VersionHistories:    versionHistories,
×
4985
                },
×
4986
                NewWorkflowSnapshot: &p.WorkflowSnapshot{
×
4987
                        ExecutionInfo:  newWorkflowExecutionInfo,
×
4988
                        ExecutionStats: newWorkflowExecutionStats,
×
4989
                        Condition:      0,
×
4990

×
4991
                        ActivityInfos:       []*p.ActivityInfo{},
×
4992
                        TimerInfos:          []*p.TimerInfo{},
×
4993
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
4994
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
4995
                        SignalInfos:         []*p.SignalInfo{},
×
4996
                        SignalRequestedIDs:  []string{},
×
4997
                        VersionHistories:    versionHistories,
×
4998
                },
×
4999
                CurrentWorkflowMutation: nil,
×
5000
                Encoding:                pickRandomEncoding(),
×
5001
        }
×
5002
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5003
        s.Error(err)
×
5004
        resetReq.Mode = p.ConflictResolveWorkflowModeUpdateCurrent
×
5005
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5006
        s.NoError(err)
×
5007

×
5008
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5009
                DomainID:   domainID,
×
5010
                WorkflowID: workflowID,
×
5011
        })
×
5012
        s.NoError(err)
×
5013
        s.Equal(newWorkflowExecutionInfo.RunID, currentRecord.RunID)
×
5014
        s.Equal(newWorkflowExecutionInfo.CreateRequestID, currentRecord.StartRequestID)
×
5015
        s.Equal(newWorkflowExecutionInfo.State, currentRecord.State)
×
5016
        s.Equal(newWorkflowExecutionInfo.CloseStatus, currentRecord.CloseStatus)
×
5017
        s.Equal(int64(-24), currentRecord.LastWriteVersion)
×
5018

×
5019
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5020
        s.NoError(err)
×
5021
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5022
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5023
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5024
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5025
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, types.WorkflowExecution{
×
5026
                WorkflowID: workflowID,
×
5027
                RunID:      resetReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
5028
        })
×
5029
        s.NoError(err)
×
5030
        state.ExecutionInfo.StartTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5031
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5032
        state.ExecutionInfo.ExpirationTime = resetReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5033
        s.Equal(resetReq.NewWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5034
}
×
5035

5036
// TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelf test
5037
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelf() {
×
5038
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5039
        defer cancel()
×
5040

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

×
5044
        // first create a workflow and continue as new it
×
5045
        workflowExecutionReset := types.WorkflowExecution{
×
5046
                WorkflowID: workflowID,
×
5047
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa0",
×
5048
        }
×
5049
        partitionConfig := map[string]string{
×
5050
                "userid": uuid.New(),
×
5051
        }
×
5052
        nextEventID := int64(3)
×
5053
        resp, err := s.CreateWorkflowExecution(
×
5054
                ctx,
×
5055
                domainID,
×
5056
                workflowExecutionReset,
×
5057
                "taskList",
×
5058
                "wType",
×
5059
                20,
×
5060
                13,
×
5061
                nil,
×
5062
                nextEventID,
×
5063
                0,
×
5064
                2,
×
5065
                nil,
×
5066
                partitionConfig,
×
5067
        )
×
5068
        s.NoError(err)
×
5069
        s.NotNil(resp)
×
5070

×
5071
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5072
        s.NoError(err)
×
5073

×
5074
        info := state.ExecutionInfo
×
5075
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
5076
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
5077
        continueAsNewInfo.State = p.WorkflowStateRunning
×
5078
        continueAsNewInfo.NextEventID = int64(5)
×
5079
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
5080

×
5081
        workflowExecutionCurrent := types.WorkflowExecution{
×
5082
                WorkflowID: workflowID,
×
5083
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
5084
        }
×
5085
        err = s.ContinueAsNewExecution(
×
5086
                ctx,
×
5087
                continueAsNewInfo,
×
5088
                continueAsNewStats,
×
5089
                info.NextEventID,
×
5090
                workflowExecutionCurrent,
×
5091
                int64(3),
×
5092
                int64(2),
×
5093
                nil,
×
5094
        )
×
5095
        s.NoError(err)
×
5096

×
5097
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
5098
        s.NoError(err)
×
5099
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
5100

×
5101
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
5102
                DomainID:                    domainID,
×
5103
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
5104
                RunID:                       workflowExecutionReset.GetRunID(),
×
5105
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
5106
                ParentDomainID:              uuid.New(),
×
5107
                ParentWorkflowID:            "some random parent workflow ID",
×
5108
                ParentRunID:                 uuid.New(),
×
5109
                InitiatedID:                 12345,
×
5110
                TaskList:                    "some random tasklist",
×
5111
                WorkflowTypeName:            "some random workflow type name",
×
5112
                WorkflowTimeout:             1112,
×
5113
                DecisionStartToCloseTimeout: 14,
×
5114
                State:                       p.WorkflowStateCompleted,
×
5115
                CloseStatus:                 p.WorkflowCloseStatusCompleted,
×
5116
                LastFirstEventID:            common.FirstEventID,
×
5117
                NextEventID:                 123,
×
5118
                CreateRequestID:             uuid.New(),
×
5119
                DecisionVersion:             common.EmptyVersion,
×
5120
                DecisionScheduleID:          111,
×
5121
                DecisionStartedID:           222,
×
5122
                DecisionRequestID:           uuid.New(),
×
5123
                DecisionTimeout:             0,
×
5124
                AutoResetPoints:             &types.ResetPoints{},
×
5125
                PartitionConfig:             nil,
×
5126
        }
×
5127
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
5128
                {
×
5129
                        EventID: resetExecutionInfo.DecisionScheduleID,
×
5130
                        Version: common.EmptyVersion,
×
5131
                },
×
5132
        })
×
5133
        versionHistories := p.NewVersionHistories(versionHistory)
×
5134

×
5135
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
5136
                RangeID: s.ShardInfo.RangeID,
×
5137
                Mode:    p.ConflictResolveWorkflowModeUpdateCurrent,
×
5138
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
5139
                        ExecutionInfo:  resetExecutionInfo,
×
5140
                        ExecutionStats: &p.ExecutionStats{},
×
5141
                        Condition:      int64(5),
×
5142

×
5143
                        ActivityInfos:       []*p.ActivityInfo{},
×
5144
                        TimerInfos:          []*p.TimerInfo{},
×
5145
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5146
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5147
                        SignalInfos:         []*p.SignalInfo{},
×
5148
                        SignalRequestedIDs:  []string{},
×
5149
                        VersionHistories:    versionHistories,
×
5150
                },
×
5151
                NewWorkflowSnapshot:     nil,
×
5152
                CurrentWorkflowMutation: nil,
×
5153
                Encoding:                pickRandomEncoding(),
×
5154
        }
×
5155
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5156
        s.Error(err)
×
5157
        resetReq.Mode = p.ConflictResolveWorkflowModeBypassCurrent
×
5158
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5159
        s.NoError(err)
×
5160

×
5161
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5162
                DomainID:   domainID,
×
5163
                WorkflowID: workflowID,
×
5164
        })
×
5165
        s.NoError(err)
×
5166
        s.Equal(currentRunID, currentRecord.RunID)
×
5167

×
5168
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5169
        s.NoError(err)
×
5170
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5171
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5172
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5173
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5174
}
×
5175

5176
// TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelfWithContinueAsNew test
5177
func (s *ExecutionManagerSuite) TestConflictResolveWorkflowExecutionWithTransactionZombieIsSelfWithContinueAsNew() {
×
5178
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5179
        defer cancel()
×
5180

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

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

×
5211
        state, err := s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5212
        s.NoError(err)
×
5213
        continueAsNewStats := copyExecutionStats(state.ExecutionStats)
×
5214

×
5215
        info := state.ExecutionInfo
×
5216
        continueAsNewInfo := copyWorkflowExecutionInfo(info)
×
5217
        continueAsNewInfo.State = p.WorkflowStateRunning
×
5218
        continueAsNewInfo.NextEventID = int64(5)
×
5219
        continueAsNewInfo.LastProcessedEvent = int64(2)
×
5220

×
5221
        workflowExecutionCurrent := types.WorkflowExecution{
×
5222
                WorkflowID: workflowID,
×
5223
                RunID:      "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa1",
×
5224
        }
×
5225
        err = s.ContinueAsNewExecution(
×
5226
                ctx,
×
5227
                continueAsNewInfo,
×
5228
                continueAsNewStats,
×
5229
                info.NextEventID,
×
5230
                workflowExecutionCurrent,
×
5231
                int64(3),
×
5232
                int64(2),
×
5233
                nil,
×
5234
        )
×
5235
        s.NoError(err)
×
5236

×
5237
        currentRunID, err := s.GetCurrentWorkflowRunID(ctx, domainID, workflowID)
×
5238
        s.NoError(err)
×
5239
        s.Equal(workflowExecutionCurrent.GetRunID(), currentRunID)
×
5240

×
5241
        decisionScheduleID := int64(111)
×
5242
        versionHistory := p.NewVersionHistory([]byte{}, []*p.VersionHistoryItem{
×
5243
                {
×
5244
                        EventID: decisionScheduleID,
×
5245
                        Version: common.EmptyVersion,
×
5246
                },
×
5247
        })
×
5248
        versionHistories := p.NewVersionHistories(versionHistory)
×
5249
        resetExecutionInfo := &p.WorkflowExecutionInfo{
×
5250
                DomainID:                    domainID,
×
5251
                WorkflowID:                  workflowExecutionReset.GetWorkflowID(),
×
5252
                RunID:                       workflowExecutionReset.GetRunID(),
×
5253
                FirstExecutionRunID:         workflowExecutionReset.GetRunID(),
×
5254
                ParentDomainID:              uuid.New(),
×
5255
                ParentWorkflowID:            "some random parent workflow ID",
×
5256
                ParentRunID:                 uuid.New(),
×
5257
                InitiatedID:                 12345,
×
5258
                TaskList:                    "some random tasklist",
×
5259
                WorkflowTypeName:            "some random workflow type name",
×
5260
                WorkflowTimeout:             1112,
×
5261
                DecisionStartToCloseTimeout: 14,
×
5262
                State:                       p.WorkflowStateCompleted,
×
5263
                CloseStatus:                 p.WorkflowCloseStatusContinuedAsNew,
×
5264
                LastFirstEventID:            common.FirstEventID,
×
5265
                NextEventID:                 123,
×
5266
                CreateRequestID:             uuid.New(),
×
5267
                DecisionVersion:             common.EmptyVersion,
×
5268
                DecisionScheduleID:          decisionScheduleID,
×
5269
                DecisionStartedID:           222,
×
5270
                DecisionRequestID:           uuid.New(),
×
5271
                DecisionTimeout:             0,
×
5272
                AutoResetPoints:             &types.ResetPoints{},
×
5273
                PartitionConfig:             nil,
×
5274
        }
×
5275
        newWorkflowExecutionInfo := copyWorkflowExecutionInfo(resetExecutionInfo)
×
5276
        newWorkflowExecutionStats := &p.ExecutionStats{}
×
5277
        newWorkflowExecutionInfo.CreateRequestID = uuid.New()
×
5278
        newWorkflowExecutionInfo.RunID = "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa2"
×
5279
        newWorkflowExecutionInfo.State = p.WorkflowStateZombie
×
5280
        newWorkflowExecutionInfo.CloseStatus = p.WorkflowCloseStatusNone
×
5281
        newWorkflowExecutionInfo.PartitionConfig = map[string]string{"zone": "dca1"}
×
5282
        resetReq := &p.ConflictResolveWorkflowExecutionRequest{
×
5283
                RangeID: s.ShardInfo.RangeID,
×
5284
                Mode:    p.ConflictResolveWorkflowModeUpdateCurrent,
×
5285
                ResetWorkflowSnapshot: p.WorkflowSnapshot{
×
5286
                        ExecutionInfo:  resetExecutionInfo,
×
5287
                        ExecutionStats: &p.ExecutionStats{},
×
5288
                        Condition:      int64(5),
×
5289

×
5290
                        ActivityInfos:       []*p.ActivityInfo{},
×
5291
                        TimerInfos:          []*p.TimerInfo{},
×
5292
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5293
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5294
                        SignalInfos:         []*p.SignalInfo{},
×
5295
                        SignalRequestedIDs:  []string{},
×
5296
                        VersionHistories:    versionHistories,
×
5297
                },
×
5298
                NewWorkflowSnapshot: &p.WorkflowSnapshot{
×
5299
                        ExecutionInfo:  newWorkflowExecutionInfo,
×
5300
                        ExecutionStats: newWorkflowExecutionStats,
×
5301
                        Condition:      0,
×
5302

×
5303
                        ActivityInfos:       []*p.ActivityInfo{},
×
5304
                        TimerInfos:          []*p.TimerInfo{},
×
5305
                        ChildExecutionInfos: []*p.ChildExecutionInfo{},
×
5306
                        RequestCancelInfos:  []*p.RequestCancelInfo{},
×
5307
                        SignalInfos:         []*p.SignalInfo{},
×
5308
                        SignalRequestedIDs:  []string{},
×
5309
                        VersionHistories:    versionHistories,
×
5310
                },
×
5311
                CurrentWorkflowMutation: nil,
×
5312
                Encoding:                pickRandomEncoding(),
×
5313
        }
×
5314
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5315
        s.Error(err)
×
5316
        resetReq.Mode = p.ConflictResolveWorkflowModeBypassCurrent
×
5317
        _, err = s.ExecutionManager.ConflictResolveWorkflowExecution(ctx, resetReq)
×
5318
        s.NoError(err)
×
5319

×
5320
        currentRecord, err := s.ExecutionManager.GetCurrentExecution(ctx, &p.GetCurrentExecutionRequest{
×
5321
                DomainID:   domainID,
×
5322
                WorkflowID: workflowID,
×
5323
        })
×
5324
        s.NoError(err)
×
5325
        s.Equal(currentRunID, currentRecord.RunID)
×
5326

×
5327
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, workflowExecutionReset)
×
5328
        s.NoError(err)
×
5329
        state.ExecutionInfo.StartTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5330
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.ResetWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5331
        state.ExecutionInfo.ExpirationTime = resetReq.ResetWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5332
        s.Equal(resetReq.ResetWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5333

×
5334
        state, err = s.GetWorkflowExecutionInfo(ctx, domainID, types.WorkflowExecution{
×
5335
                WorkflowID: workflowID,
×
5336
                RunID:      resetReq.NewWorkflowSnapshot.ExecutionInfo.RunID,
×
5337
        })
×
5338
        s.NoError(err)
×
5339
        state.ExecutionInfo.StartTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.StartTimestamp
×
5340
        state.ExecutionInfo.LastUpdatedTimestamp = resetReq.NewWorkflowSnapshot.ExecutionInfo.LastUpdatedTimestamp
×
5341
        state.ExecutionInfo.ExpirationTime = resetReq.NewWorkflowSnapshot.ExecutionInfo.ExpirationTime
×
5342
        s.Equal(resetReq.NewWorkflowSnapshot.ExecutionInfo, state.ExecutionInfo)
×
5343
}
×
5344

5345
// TestReplicationDLQ test
5346
func (s *ExecutionManagerSuite) TestReplicationDLQ() {
×
5347
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5348
        defer cancel()
×
5349

×
5350
        sourceCluster := "test"
×
5351
        taskInfo := &p.ReplicationTaskInfo{
×
5352
                DomainID:   uuid.New(),
×
5353
                WorkflowID: uuid.New(),
×
5354
                RunID:      uuid.New(),
×
5355
                TaskID:     0,
×
5356
                TaskType:   0,
×
5357
        }
×
5358
        err := s.PutReplicationTaskToDLQ(ctx, sourceCluster, taskInfo)
×
5359
        s.NoError(err)
×
5360
        resp, err := s.GetReplicationTasksFromDLQ(ctx, sourceCluster, -1, 0, 1, nil)
×
5361
        s.NoError(err)
×
5362
        s.Len(resp.Tasks, 1)
×
5363
        err = s.DeleteReplicationTaskFromDLQ(ctx, sourceCluster, 0)
×
5364
        s.NoError(err)
×
5365
        resp, err = s.GetReplicationTasksFromDLQ(ctx, sourceCluster, -1, 0, 1, nil)
×
5366
        s.NoError(err)
×
5367
        s.Len(resp.Tasks, 0)
×
5368

×
5369
        taskInfo1 := &p.ReplicationTaskInfo{
×
5370
                DomainID:   uuid.New(),
×
5371
                WorkflowID: uuid.New(),
×
5372
                RunID:      uuid.New(),
×
5373
                TaskID:     1,
×
5374
                TaskType:   0,
×
5375
        }
×
5376
        taskInfo2 := &p.ReplicationTaskInfo{
×
5377
                DomainID:   uuid.New(),
×
5378
                WorkflowID: uuid.New(),
×
5379
                RunID:      uuid.New(),
×
5380
                TaskID:     2,
×
5381
                TaskType:   0,
×
5382
        }
×
5383
        err = s.PutReplicationTaskToDLQ(ctx, sourceCluster, taskInfo1)
×
5384
        s.NoError(err)
×
5385
        err = s.PutReplicationTaskToDLQ(ctx, sourceCluster, taskInfo2)
×
5386
        s.NoError(err)
×
5387
        resp, err = s.GetReplicationTasksFromDLQ(ctx, sourceCluster, 0, 2, 2, nil)
×
5388
        s.NoError(err)
×
5389
        s.Len(resp.Tasks, 2)
×
5390
        sizeResp, err := s.GetReplicationDLQSize(ctx, sourceCluster)
×
5391
        s.NoError(err)
×
5392
        s.Equal(int64(2), sizeResp.Size)
×
5393
        err = s.RangeDeleteReplicationTaskFromDLQ(ctx, sourceCluster, 0, 2)
×
5394
        s.NoError(err)
×
5395
        resp, err = s.GetReplicationTasksFromDLQ(ctx, sourceCluster, 0, 2, 2, nil)
×
5396
        s.NoError(err)
×
5397
        s.Len(resp.Tasks, 0)
×
5398
}
×
5399

5400
// TestCreateFailoverMarkerTasks test
5401
func (s *ExecutionManagerSuite) TestCreateFailoverMarkerTasks() {
×
5402
        ctx, cancel := context.WithTimeout(context.Background(), testContextTimeout)
×
5403
        defer cancel()
×
5404

×
5405
        domainID := uuid.New()
×
5406
        markers := []*p.FailoverMarkerTask{
×
5407
                {
×
5408
                        TaskID:              1,
×
5409
                        VisibilityTimestamp: time.Now(),
×
5410
                        DomainID:            domainID,
×
5411
                        Version:             1,
×
5412
                },
×
5413
        }
×
5414
        err := s.CreateFailoverMarkers(ctx, markers)
×
5415
        s.NoError(err)
×
5416

×
5417
        tasks, err := s.GetReplicationTasks(ctx, 1, true)
×
5418
        s.NoError(err)
×
5419
        s.Equal(len(tasks), 1)
×
5420
        s.Equal(tasks[0].Version, int64(1))
×
5421
        s.Equal(tasks[0].TaskID, int64(1))
×
5422
        s.Equal(tasks[0].DomainID, domainID)
×
5423
        s.Equal(tasks[0].TaskType, p.ReplicationTaskTypeFailoverMarker)
×
5424
}
×
5425

5426
func copyWorkflowExecutionInfo(sourceInfo *p.WorkflowExecutionInfo) *p.WorkflowExecutionInfo {
×
5427
        return &p.WorkflowExecutionInfo{
×
5428
                DomainID:                    sourceInfo.DomainID,
×
5429
                WorkflowID:                  sourceInfo.WorkflowID,
×
5430
                RunID:                       sourceInfo.RunID,
×
5431
                FirstExecutionRunID:         sourceInfo.FirstExecutionRunID,
×
5432
                ParentDomainID:              sourceInfo.ParentDomainID,
×
5433
                ParentWorkflowID:            sourceInfo.ParentWorkflowID,
×
5434
                ParentRunID:                 sourceInfo.ParentRunID,
×
5435
                InitiatedID:                 sourceInfo.InitiatedID,
×
5436
                CompletionEvent:             sourceInfo.CompletionEvent,
×
5437
                TaskList:                    sourceInfo.TaskList,
×
5438
                WorkflowTypeName:            sourceInfo.WorkflowTypeName,
×
5439
                WorkflowTimeout:             sourceInfo.WorkflowTimeout,
×
5440
                DecisionStartToCloseTimeout: sourceInfo.DecisionStartToCloseTimeout,
×
5441
                ExecutionContext:            sourceInfo.ExecutionContext,
×
5442
                State:                       sourceInfo.State,
×
5443
                CloseStatus:                 sourceInfo.CloseStatus,
×
5444
                LastFirstEventID:            sourceInfo.LastFirstEventID,
×
5445
                NextEventID:                 sourceInfo.NextEventID,
×
5446
                LastProcessedEvent:          sourceInfo.LastProcessedEvent,
×
5447
                LastUpdatedTimestamp:        sourceInfo.LastUpdatedTimestamp,
×
5448
                StartTimestamp:              sourceInfo.StartTimestamp,
×
5449
                CreateRequestID:             sourceInfo.CreateRequestID,
×
5450
                DecisionVersion:             sourceInfo.DecisionVersion,
×
5451
                DecisionScheduleID:          sourceInfo.DecisionScheduleID,
×
5452
                DecisionStartedID:           sourceInfo.DecisionStartedID,
×
5453
                DecisionRequestID:           sourceInfo.DecisionRequestID,
×
5454
                DecisionTimeout:             sourceInfo.DecisionTimeout,
×
5455
                BranchToken:                 sourceInfo.BranchToken,
×
5456
                AutoResetPoints:             sourceInfo.AutoResetPoints,
×
5457
                PartitionConfig:             sourceInfo.PartitionConfig,
×
5458
        }
×
5459
}
×
5460

5461
func copyExecutionStats(sourceStats *p.ExecutionStats) *p.ExecutionStats {
×
5462
        return &p.ExecutionStats{
×
5463
                HistorySize: sourceStats.HistorySize,
×
5464
        }
×
5465
}
×
5466

5467
// Note: cassandra only provide millisecond precision timestamp
5468
// ref: https://docs.datastax.com/en/cql/3.3/cql/cql_reference/timestamp_type_r.html
5469
// so to use equal function, we need to do conversion, getting rid of sub milliseconds
5470
func timestampConvertor(t time.Time) time.Time {
×
5471
        return time.Unix(
×
5472
                0,
×
5473
                p.DBTimestampToUnixNano(p.UnixNanoToDBTimestamp(t.UnixNano())),
×
5474
        ).UTC()
×
5475
}
×
5476

5477
func timeComparator(t1, t2 time.Time, timeTolerance time.Duration) bool {
×
5478
        diff := t2.Sub(t1)
×
5479
        return diff.Nanoseconds() <= timeTolerance.Nanoseconds()
×
5480
}
×
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