113
}
114
116
>
rangeID := rand.Int63()
117
>
taskQueue := s.createTaskQueue(rangeID)
118
>
119
>
var tasks []*persistencespb.AllocatedTaskInfo
120
>
for pass := int64(1); pass <= 5; pass++ {
121
>
tasks = append(tasks, s.randomTask(pass, pass))
122
>
}
123
>
_, err := s.taskManager.CreateTasks(s.ctx, &p.CreateTasksRequest{
124
>
TaskQueueInfo: &p.PersistedTaskQueueInfo{RangeID: rangeID, Data: taskQueue},
125
>
Tasks: tasks,
126
>
})
127
>
s.NoError(err)
128
>
129
>
_, err = s.taskManager.CompleteTasksLessThan(s.ctx, &p.CompleteTasksLessThanRequest{
130
>
NamespaceID: s.namespaceID,
131
>
TaskQueueName: s.taskQueueName,
132
>
TaskType: s.taskQueueType,
133
>
ExclusiveMaxPass: 3,
134
>
ExclusiveMaxTaskID: 0,
135
>
Limit: 10,
136
>
})
137
>
s.NoError(err)
138
>
139
>
resp, err := s.taskManager.GetTasks(s.ctx, &p.GetTasksRequest{
140
>
NamespaceID: s.namespaceID,
141
>
TaskQueue: s.taskQueueName,
142
>
TaskType: s.taskQueueType,
143
>
InclusiveMinPass: 1,
144
>
InclusiveMinTaskID: 0,
145
>
ExclusiveMaxTaskID: math.MaxInt64,
146
>
PageSize: 10,
147
>
})
148
>
s.NoError(err)
149
>
150
>
expected := []*persistencespb.AllocatedTaskInfo{tasks[2], tasks[3], tasks[4]}
151
>
protorequire.ProtoSliceEqual(s.T(), expected, resp.Tasks)
152
>
s.Nil(resp.NextPageToken)
153
}
154
155
>
func (s *TaskQueueFairTaskSuite) createTaskQueue(rangeID int64) *persistencespb.TaskQueueInfo {
task_queue_fair_task.go
156
>
taskQueueKind := enumspb.TaskQueueKind(rand.Int31n(int32(len(enumspb.TaskQueueKind_name)) + 1))
157
>
taskQueue := s.randomTaskQueueInfo(taskQueueKind)
158
>
_, err := s.taskManager.CreateTaskQueue(s.ctx, &p.CreateTaskQueueRequest{
159
>
RangeID: rangeID,
160
>
TaskQueueInfo: taskQueue,
161
>
})
162
>
s.NoError(err)
163
>
return taskQueue
164
>
}
165
166
>
func (s *TaskQueueFairTaskSuite) randomTaskQueueInfo(taskQueueKind enumspb.TaskQueueKind) *persistencespb.TaskQueueInfo {
task_queue_fair_task.go
167
>
now := time.Now().UTC()
168
>
var expiryTime *timestamppb.Timestamp
169
>
if taskQueueKind == enumspb.TASK_QUEUE_KIND_STICKY {
170
expiryTime = timestamppb.New(now.Add(s.stickyTTL))
171
}
173
>
NamespaceId: s.namespaceID,
174
>
Name: s.taskQueueName,
175
>
TaskType: s.taskQueueType,
176
>
Kind: taskQueueKind,
177
>
AckLevel: rand.Int63(),
178
>
ExpiryTime: expiryTime,
179
>
LastUpdateTime: timestamppb.New(now),
180
>
}
181
}
182
183
>
func (s *TaskQueueFairTaskSuite) randomTask(taskID, pass int64) *persistencespb.AllocatedTaskInfo {
task_queue_fair_task.go
184
>
now := time.Now().UTC()
185
>
return &persistencespb.AllocatedTaskInfo{
186
>
TaskId: taskID,
187
>
TaskPass: pass,
188
>
Data: &persistencespb.TaskInfo{
189
>
NamespaceId: s.namespaceID,
190
>
WorkflowId: uuid.New().String(),
191
>
RunId: uuid.New().String(),
192
>
ScheduledEventId: rand.Int63(),
193
>
CreateTime: timestamppb.New(now),
194
>
ExpiryTime: timestamppb.New(now.Add(s.taskTTL)),
195
>
Clock: &clockspb.VectorClock{
196
>
ClusterId: rand.Int63(),
197
>
ShardId: rand.Int31(),
198
>
Clock: rand.Int63(),
199
>
},
200
>
},
201
>
}
202
>
}