forked from temporalio/temporal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_integration_test.go
673 lines (586 loc) · 20.2 KB
/
client_integration_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
// The MIT License
//
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
//
// Copyright (c) 2020 Uber Technologies, Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
package host
import (
"bytes"
"context"
"encoding/gob"
"errors"
"flag"
"fmt"
"strconv"
"strings"
"sync"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/suite"
commonpb "go.temporal.io/api/common/v1"
enumspb "go.temporal.io/api/enums/v1"
historypb "go.temporal.io/api/history/v1"
"go.temporal.io/sdk/activity"
sdkclient "go.temporal.io/sdk/client"
"go.temporal.io/sdk/converter"
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/worker"
"go.temporal.io/sdk/workflow"
"go.temporal.io/server/api/adminservice/v1"
"go.temporal.io/server/common"
"go.temporal.io/server/common/log/tag"
"go.temporal.io/server/common/rpc"
)
type (
clientIntegrationSuite struct {
// override suite.Suite.Assertions with require.Assertions; this means that s.NotNil(nil) will stop the test,
// not merely log an error
*require.Assertions
IntegrationBase
hostPort string
sdkClient sdkclient.Client
worker worker.Worker
taskQueue string
}
)
var (
ErrEncodingIsNotSet = errors.New("payload encoding metadata is not set")
ErrEncodingIsNotSupported = errors.New("payload encoding is not supported")
)
func TestClientIntegrationSuite(t *testing.T) {
flag.Parse()
suite.Run(t, new(clientIntegrationSuite))
}
func (s *clientIntegrationSuite) SetupSuite() {
s.setupSuite("testdata/clientintegrationtestcluster.yaml")
s.hostPort = "127.0.0.1:7134"
if TestFlags.FrontendAddr != "" {
s.hostPort = TestFlags.FrontendAddr
}
}
func (s *clientIntegrationSuite) TearDownSuite() {
s.tearDownSuite()
}
func (s *clientIntegrationSuite) SetupTest() {
// Have to define our overridden assertions in the test setup. If we did it earlier, s.T() will return nil
s.Assertions = require.New(s.T())
sdkClient, err := sdkclient.NewClient(sdkclient.Options{
HostPort: s.hostPort,
Namespace: s.namespace,
ConnectionOptions: sdkclient.ConnectionOptions{
DisableHealthCheck: true,
},
})
if err != nil {
s.Logger.Fatal("Error when creating SDK client", tag.Error(err))
}
s.sdkClient = sdkClient
s.taskQueue = s.randomizeStr("tq")
s.worker = worker.New(s.sdkClient, s.taskQueue, worker.Options{})
workflowFn := func(ctx workflow.Context) error {
s.Logger.Fatal("Should not reach here")
return nil
}
activityFn := func(ctx context.Context) error {
s.Logger.Fatal("Should not reach here")
return nil
}
// register dummy workflow and activity, otherwise worker won't start.
s.worker.RegisterWorkflow(workflowFn)
s.worker.RegisterActivity(activityFn)
if err := s.worker.Start(); err != nil {
s.Logger.Fatal("Error when start worker", tag.Error(err))
}
}
func (s *clientIntegrationSuite) TearDownTest() {
s.worker.Stop()
s.sdkClient.Close()
}
// testDataConverter implements encoded.DataConverter using gob
type testDataConverter struct {
NumOfCallToPayloads int // for testing to know testDataConverter is called as expected
NumOfCallFromPayloads int
}
func (tdc *testDataConverter) ToPayloads(values ...interface{}) (*commonpb.Payloads, error) {
tdc.NumOfCallToPayloads++
result := &commonpb.Payloads{}
for i, value := range values {
p, err := tdc.ToPayload(value)
if err != nil {
return nil, fmt.Errorf(
"args[%d], %T: %w", i, value, err)
}
result.Payloads = append(result.Payloads, p)
}
return result, nil
}
func (tdc *testDataConverter) FromPayloads(payloads *commonpb.Payloads, valuePtrs ...interface{}) error {
tdc.NumOfCallFromPayloads++
for i, p := range payloads.GetPayloads() {
err := tdc.FromPayload(p, valuePtrs[i])
if err != nil {
return fmt.Errorf("args[%d]: %w", i, err)
}
}
return nil
}
func (tdc *testDataConverter) ToPayload(value interface{}) (*commonpb.Payload, error) {
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
if err := enc.Encode(value); err != nil {
return nil, err
}
p := &commonpb.Payload{
Metadata: map[string][]byte{
"encoding": []byte("gob"),
},
Data: buf.Bytes(),
}
return p, nil
}
func (tdc *testDataConverter) FromPayload(payload *commonpb.Payload, valuePtr interface{}) error {
encoding, ok := payload.GetMetadata()["encoding"]
if !ok {
return ErrEncodingIsNotSet
}
e := string(encoding)
if e != "gob" {
return ErrEncodingIsNotSupported
}
return decodeGob(payload, valuePtr)
}
func (tdc *testDataConverter) ToStrings(payloads *commonpb.Payloads) []string {
var result []string
for _, p := range payloads.GetPayloads() {
result = append(result, tdc.ToString(p))
}
return result
}
func decodeGob(payload *commonpb.Payload, valuePtr interface{}) error {
dec := gob.NewDecoder(bytes.NewBuffer(payload.GetData()))
return dec.Decode(valuePtr)
}
func (tdc *testDataConverter) ToString(payload *commonpb.Payload) string {
encoding, ok := payload.GetMetadata()["encoding"]
if !ok {
return ErrEncodingIsNotSet.Error()
}
e := string(encoding)
if e != "gob" {
return ErrEncodingIsNotSupported.Error()
}
var value interface{}
err := decodeGob(payload, &value)
if err != nil {
return err.Error()
}
return fmt.Sprintf("%+v", value)
}
func newTestDataConverter() converter.DataConverter {
return &testDataConverter{}
}
func testActivity(ctx context.Context, msg string) (string, error) {
return "hello_" + msg, nil
}
func testDataConverterWorkflow(ctx workflow.Context, tl string) (string, error) {
ao := workflow.ActivityOptions{
ScheduleToStartTimeout: 20 * time.Second,
StartToCloseTimeout: 40 * time.Second,
}
ctx = workflow.WithActivityOptions(ctx, ao)
var result string
err := workflow.ExecuteActivity(ctx, testActivity, "world").Get(ctx, &result)
if err != nil {
return "", err
}
// use another converter to run activity,
// with new taskQueue so that worker with same data converter can properly process tasks.
var result1 string
ctx1 := workflow.WithDataConverter(ctx, newTestDataConverter())
ctx1 = workflow.WithTaskQueue(ctx1, tl)
err1 := workflow.ExecuteActivity(ctx1, testActivity, "world1").Get(ctx1, &result1)
if err1 != nil {
return "", err1
}
return result + "," + result1, nil
}
func (s *clientIntegrationSuite) startWorkerWithDataConverter(tl string, dataConverter converter.DataConverter) (sdkclient.Client, worker.Worker) {
sdkClient, err := sdkclient.NewClient(sdkclient.Options{
HostPort: s.hostPort,
Namespace: s.namespace,
DataConverter: dataConverter,
ConnectionOptions: sdkclient.ConnectionOptions{
DisableHealthCheck: true,
},
})
if err != nil {
s.Logger.Fatal("Error when creating SDK client", tag.Error(err))
}
worker := worker.New(sdkClient, tl, worker.Options{})
worker.RegisterActivity(testActivity)
worker.RegisterWorkflow(testChildWorkflow)
if err := worker.Start(); err != nil {
s.Logger.Fatal("Error when start worker with data converter", tag.Error(err))
}
return sdkClient, worker
}
func (s *clientIntegrationSuite) TestClientDataConverter() {
tl := "client-integration-data-converter-activity-taskqueue"
dc := newTestDataConverter()
sdkClient, worker := s.startWorkerWithDataConverter(tl, dc)
defer func() {
worker.Stop()
sdkClient.Close()
}()
id := "client-integration-data-converter-workflow"
workflowOptions := sdkclient.StartWorkflowOptions{
ID: id,
TaskQueue: s.taskQueue,
WorkflowRunTimeout: time.Minute,
}
ctx, cancel := rpc.NewContextWithTimeoutAndHeaders(time.Minute)
defer cancel()
s.worker.RegisterWorkflow(testDataConverterWorkflow)
s.worker.RegisterActivity(testActivity)
we, err := s.sdkClient.ExecuteWorkflow(ctx, workflowOptions, testDataConverterWorkflow, tl)
if err != nil {
s.Logger.Fatal("Start workflow with err", tag.Error(err))
}
s.NotNil(we)
s.True(we.GetRunID() != "")
var res string
err = we.Get(ctx, &res)
s.NoError(err)
s.Equal("hello_world,hello_world1", res)
// to ensure custom data converter is used, this number might be different if client changed.
d := dc.(*testDataConverter)
s.Equal(1, d.NumOfCallToPayloads)
s.Equal(1, d.NumOfCallFromPayloads)
}
func (s *clientIntegrationSuite) TestClientDataConverter_Failed() {
tl := "client-integration-data-converter-activity-failed-taskqueue"
sdkClient, worker := s.startWorkerWithDataConverter(tl, nil) // mismatch of data converter
defer func() {
worker.Stop()
sdkClient.Close()
}()
id := "client-integration-data-converter-failed-workflow"
workflowOptions := sdkclient.StartWorkflowOptions{
ID: id,
TaskQueue: s.taskQueue,
WorkflowRunTimeout: time.Minute,
}
ctx, cancel := rpc.NewContextWithTimeoutAndHeaders(time.Minute)
defer cancel()
s.worker.RegisterWorkflow(testDataConverterWorkflow)
s.worker.RegisterActivity(testActivity)
we, err := s.sdkClient.ExecuteWorkflow(ctx, workflowOptions, testDataConverterWorkflow, tl)
if err != nil {
s.Logger.Fatal("Start workflow with err", tag.Error(err))
}
s.NotNil(we)
s.True(we.GetRunID() != "")
var res string
err = we.Get(ctx, &res)
s.Error(err)
// Get history to make sure only the 2nd activity is failed because of mismatch of data converter
iter := s.sdkClient.GetWorkflowHistory(ctx, id, we.GetRunID(), false, 0)
completedAct := 0
failedAct := 0
for iter.HasNext() {
event, err := iter.Next()
s.NoError(err)
if event.GetEventType() == enumspb.EVENT_TYPE_ACTIVITY_TASK_COMPLETED {
completedAct++
}
if event.GetEventType() == enumspb.EVENT_TYPE_ACTIVITY_TASK_FAILED {
failedAct++
s.NotNil(event.GetActivityTaskFailedEventAttributes().GetFailure().GetApplicationFailureInfo())
s.True(strings.HasPrefix(event.GetActivityTaskFailedEventAttributes().GetFailure().GetMessage(), "unable to decode the activity function input payload with error"))
}
}
s.Equal(1, completedAct)
s.Equal(1, failedAct)
}
var childTaskQueue = "client-integration-data-converter-child-taskqueue"
func testParentWorkflow(ctx workflow.Context) (string, error) {
logger := workflow.GetLogger(ctx)
execution := workflow.GetInfo(ctx).WorkflowExecution
childID := fmt.Sprintf("child_workflow:%v", execution.RunID)
cwo := workflow.ChildWorkflowOptions{
WorkflowID: childID,
WorkflowRunTimeout: time.Minute,
}
ctx = workflow.WithChildOptions(ctx, cwo)
var result string
err := workflow.ExecuteChildWorkflow(ctx, testChildWorkflow, 0, 3).Get(ctx, &result)
if err != nil {
logger.Error("Parent execution received child execution failure", "error", err)
return "", err
}
childID1 := fmt.Sprintf("child_workflow1:%v", execution.RunID)
cwo1 := workflow.ChildWorkflowOptions{
WorkflowID: childID1,
WorkflowRunTimeout: time.Minute,
TaskQueue: childTaskQueue,
}
ctx1 := workflow.WithChildOptions(ctx, cwo1)
ctx1 = workflow.WithDataConverter(ctx1, newTestDataConverter())
var result1 string
err1 := workflow.ExecuteChildWorkflow(ctx1, testChildWorkflow, 0, 2).Get(ctx1, &result1)
if err1 != nil {
logger.Error("Parent execution received child execution 1 failure", "error", err1)
return "", err1
}
res := fmt.Sprintf("Complete child1 %s times, complete child2 %s times", result, result1)
logger.Info("Parent execution completed", "Result", res)
return res, nil
}
func testChildWorkflow(ctx workflow.Context, totalCount, runCount int) (string, error) {
logger := workflow.GetLogger(ctx)
logger.Info("Child workflow execution started")
if runCount <= 0 {
logger.Error("Invalid valid for run count", "RunCount", runCount)
return "", errors.New("invalid run count")
}
totalCount++
runCount--
if runCount == 0 {
result := fmt.Sprintf("Child workflow execution completed after %v runs", totalCount)
logger.Info("Child workflow completed", "Result", result)
return strconv.Itoa(totalCount), nil
}
logger.Info("Child workflow starting new run", "RunCount", runCount, "TotalCount", totalCount)
return "", workflow.NewContinueAsNewError(ctx, testChildWorkflow, totalCount, runCount)
}
func (s *clientIntegrationSuite) TestClientDataConverter_WithChild() {
dc := newTestDataConverter()
sdkClient, worker := s.startWorkerWithDataConverter(childTaskQueue, dc)
defer func() {
worker.Stop()
sdkClient.Close()
}()
id := "client-integration-data-converter-with-child-workflow"
workflowOptions := sdkclient.StartWorkflowOptions{
ID: id,
TaskQueue: s.taskQueue,
WorkflowRunTimeout: time.Minute,
}
ctx, cancel := rpc.NewContextWithTimeoutAndHeaders(time.Minute)
defer cancel()
s.worker.RegisterWorkflow(testParentWorkflow)
s.worker.RegisterWorkflow(testChildWorkflow)
we, err := s.sdkClient.ExecuteWorkflow(ctx, workflowOptions, testParentWorkflow)
if err != nil {
s.Logger.Fatal("Start workflow with err", tag.Error(err))
}
s.NotNil(we)
s.True(we.GetRunID() != "")
var res string
err = we.Get(ctx, &res)
s.NoError(err)
s.Equal("Complete child1 3 times, complete child2 2 times", res)
// to ensure custom data converter is used, this number might be different if client changed.
d := dc.(*testDataConverter)
s.Equal(3, d.NumOfCallToPayloads)
s.Equal(2, d.NumOfCallFromPayloads)
}
func (s *clientIntegrationSuite) Test_ActivityTimeouts() {
activityFn := func(ctx context.Context) error {
info := activity.GetInfo(ctx)
if info.ActivityID == "Heartbeat" {
go func() {
for i := 0; i < 4; i++ {
activity.RecordHeartbeat(ctx, i)
time.Sleep(500 * time.Millisecond)
}
}()
}
time.Sleep(5 * time.Second)
return nil
}
var err1, err2, err3, err4 error
workflowFn := func(ctx workflow.Context) error {
noRetryPolicy := &temporal.RetryPolicy{
MaximumAttempts: 1, // disable retry
}
ctx1 := workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
ActivityID: "ScheduleToStart",
ScheduleToStartTimeout: 2 * time.Second,
StartToCloseTimeout: 2 * time.Second,
TaskQueue: "NoWorkerTaskQueue",
RetryPolicy: noRetryPolicy,
})
f1 := workflow.ExecuteActivity(ctx1, activityFn)
ctx2 := workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
ActivityID: "StartToClose",
ScheduleToStartTimeout: 2 * time.Second,
StartToCloseTimeout: 2 * time.Second,
RetryPolicy: noRetryPolicy,
})
f2 := workflow.ExecuteActivity(ctx2, activityFn)
ctx3 := workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
ActivityID: "ScheduleToClose",
ScheduleToCloseTimeout: 2 * time.Second,
StartToCloseTimeout: 3 * time.Second,
RetryPolicy: noRetryPolicy,
})
f3 := workflow.ExecuteActivity(ctx3, activityFn)
ctx4 := workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
ActivityID: "Heartbeat",
StartToCloseTimeout: 10 * time.Second,
HeartbeatTimeout: 2 * time.Second,
RetryPolicy: noRetryPolicy,
})
f4 := workflow.ExecuteActivity(ctx4, activityFn)
err1 = f1.Get(ctx1, nil)
err2 = f2.Get(ctx2, nil)
err3 = f3.Get(ctx3, nil)
err4 = f4.Get(ctx4, nil)
return nil
}
s.worker.RegisterActivity(activityFn)
s.worker.RegisterWorkflow(workflowFn)
id := "integration-test-activity-timeouts"
workflowOptions := sdkclient.StartWorkflowOptions{
ID: id,
TaskQueue: s.taskQueue,
WorkflowRunTimeout: 20 * time.Second,
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
workflowRun, err := s.sdkClient.ExecuteWorkflow(ctx, workflowOptions, workflowFn)
if err != nil {
s.Logger.Fatal("Start workflow failed with err", tag.Error(err))
}
s.NotNil(workflowRun)
s.True(workflowRun.GetRunID() != "")
err = workflowRun.Get(ctx, nil)
s.NoError(err)
// verify activity timeout type
s.Error(err1)
activityErr, ok := err1.(*temporal.ActivityError)
s.True(ok)
s.Equal("ScheduleToStart", activityErr.ActivityID())
timeoutErr, ok := activityErr.Unwrap().(*temporal.TimeoutError)
s.True(ok)
s.Equal(enumspb.TIMEOUT_TYPE_SCHEDULE_TO_START, timeoutErr.TimeoutType())
s.Error(err2)
activityErr, ok = err2.(*temporal.ActivityError)
s.True(ok)
s.Equal("StartToClose", activityErr.ActivityID())
timeoutErr, ok = activityErr.Unwrap().(*temporal.TimeoutError)
s.True(ok)
s.Equal(enumspb.TIMEOUT_TYPE_START_TO_CLOSE, timeoutErr.TimeoutType())
s.Error(err3)
activityErr, ok = err3.(*temporal.ActivityError)
s.True(ok)
s.Equal("ScheduleToClose", activityErr.ActivityID())
timeoutErr, ok = activityErr.Unwrap().(*temporal.TimeoutError)
s.True(ok)
s.Equal(enumspb.TIMEOUT_TYPE_SCHEDULE_TO_CLOSE, timeoutErr.TimeoutType())
s.Error(err4)
activityErr, ok = err4.(*temporal.ActivityError)
s.True(ok)
s.Equal("Heartbeat", activityErr.ActivityID())
timeoutErr, ok = activityErr.Unwrap().(*temporal.TimeoutError)
s.True(ok)
s.Equal(enumspb.TIMEOUT_TYPE_HEARTBEAT, timeoutErr.TimeoutType())
s.True(timeoutErr.HasLastHeartbeatDetails())
var v int
s.NoError(timeoutErr.LastHeartbeatDetails(&v))
s.Equal(3, v)
//s.printHistory(id, workflowRun.GetRunID())
}
func (s *clientIntegrationSuite) Test_BufferedQuery() {
localActivityFn := func(ctx context.Context) error {
time.Sleep(5 * time.Second) // use local activity sleep to block workflow task to force query to be buffered
return nil
}
wfStarted := sync.WaitGroup{}
wfStarted.Add(1)
workflowFn := func(ctx workflow.Context) error {
wfStarted.Done()
status := "init"
workflow.SetQueryHandler(ctx, "foo", func() (string, error) {
return status, nil
})
ctx1 := workflow.WithLocalActivityOptions(ctx, workflow.LocalActivityOptions{
ScheduleToCloseTimeout: 10 * time.Second,
})
status = "calling"
f1 := workflow.ExecuteLocalActivity(ctx1, localActivityFn)
status = "waiting"
err1 := f1.Get(ctx1, nil)
status = "done"
workflow.Sleep(ctx, 5*time.Second)
return err1
}
s.worker.RegisterWorkflow(workflowFn)
id := "integration-test-buffered-query"
workflowOptions := sdkclient.StartWorkflowOptions{
ID: id,
TaskQueue: s.taskQueue,
WorkflowRunTimeout: 20 * time.Second,
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
workflowRun, err := s.sdkClient.ExecuteWorkflow(ctx, workflowOptions, workflowFn)
if err != nil {
s.Logger.Fatal("Start workflow failed with err", tag.Error(err))
}
s.NotNil(workflowRun)
s.True(workflowRun.GetRunID() != "")
// wait until first wf task started
wfStarted.Wait()
go func() {
// sleep 2s to make sure DescribeMutableState is called after QueryWorkflow
time.Sleep(2 * time.Second)
// make DescribeMutableState call, which force mutable state to reload from db
s.adminClient.DescribeMutableState(ctx, &adminservice.DescribeMutableStateRequest{
Namespace: s.namespace,
Execution: &commonpb.WorkflowExecution{
WorkflowId: id,
RunId: workflowRun.GetRunID(),
},
})
}()
// this query will be buffered in mutable state because workflow task is in-flight.
encodedQueryResult, err := s.sdkClient.QueryWorkflow(ctx, id, workflowRun.GetRunID(), "foo")
s.NoError(err)
var queryResult string
err = encodedQueryResult.Get(&queryResult)
s.NoError(err)
s.Equal("done", queryResult)
err = workflowRun.Get(ctx, nil)
s.NoError(err)
}
func (s *clientIntegrationSuite) printHistory(workflowID string, runID string) {
iter := s.sdkClient.GetWorkflowHistory(context.Background(), workflowID, runID, false, 0)
history := &historypb.History{}
for iter.HasNext() {
event, err := iter.Next()
s.NoError(err)
history.Events = append(history.Events, event)
}
common.PrettyPrintHistory(history, s.Logger)
}