@@ -304,6 +304,7 @@ func (s *WorkersTestSuite) TestLongRunningDecisionTask() {
304
304
StartedEventId : common .Int64Ptr (3 ),
305
305
History : & m.History {Events : testEvents [0 :3 ]},
306
306
NextPageToken : nil ,
307
+ NextEventId : common .Int64Ptr (4 ),
307
308
}
308
309
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (task , nil ).Times (1 )
309
310
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (& m.PollForDecisionTaskResponse {}, & m.InternalServiceError {}).AnyTimes ()
@@ -359,6 +360,174 @@ func (s *WorkersTestSuite) TestLongRunningDecisionTask() {
359
360
s .Equal (2 , localActivityCalledCount )
360
361
}
361
362
363
+ func (s * WorkersTestSuite ) TestQueryTask_WorkflowCacheEvicted () {
364
+ domain := "testDomain"
365
+ taskList := "query-task-cache-evicted-tl"
366
+ workflowType := "query-task-cache-evicted-workflow"
367
+ workflowID := "query-task-cache-evicted-workflow-id"
368
+ runID := "query-task-cache-evicted-workflow-run-id"
369
+ activityType := "query-task-cache-evicted-activity"
370
+ queryType := "state"
371
+ doneCh := make (chan struct {})
372
+
373
+ activityFn := func (ctx context.Context ) error {
374
+ return nil
375
+ }
376
+
377
+ queryWorkflowFn := func (ctx Context ) error {
378
+ queryResult := "started"
379
+ // setup query handler for query type "state"
380
+ if err := SetQueryHandler (ctx , queryType , func (input []byte ) (string , error ) {
381
+ return queryResult , nil
382
+ }); err != nil {
383
+ return err
384
+ }
385
+
386
+ queryResult = "waiting on timer"
387
+ NewTimer (ctx , time .Minute * 2 ).Get (ctx , nil )
388
+
389
+ queryResult = "waiting on activity"
390
+ ctx = WithActivityOptions (ctx , ActivityOptions {
391
+ ScheduleToStartTimeout : 10 * time .Second ,
392
+ StartToCloseTimeout : 10 * time .Second ,
393
+ })
394
+ if err := ExecuteActivity (ctx , activityFn ).Get (ctx , nil ); err != nil {
395
+ return err
396
+ }
397
+ queryResult = "done"
398
+ return nil
399
+ }
400
+
401
+ testEvents := []* m.HistoryEvent {
402
+ {
403
+ EventId : common .Int64Ptr (1 ),
404
+ EventType : common .EventTypePtr (m .EventTypeWorkflowExecutionStarted ),
405
+ WorkflowExecutionStartedEventAttributes : & m.WorkflowExecutionStartedEventAttributes {
406
+ TaskList : & m.TaskList {Name : & taskList },
407
+ ExecutionStartToCloseTimeoutSeconds : common .Int32Ptr (180 ),
408
+ TaskStartToCloseTimeoutSeconds : common .Int32Ptr (2 ),
409
+ WorkflowType : & m.WorkflowType {Name : common .StringPtr (workflowType )},
410
+ },
411
+ },
412
+ createTestEventDecisionTaskScheduled (2 , & m.DecisionTaskScheduledEventAttributes {TaskList : & m.TaskList {Name : & taskList }}),
413
+ createTestEventDecisionTaskStarted (3 ),
414
+ createTestEventDecisionTaskCompleted (4 , & m.DecisionTaskCompletedEventAttributes {ScheduledEventId : common .Int64Ptr (2 )}),
415
+ {
416
+ EventId : common .Int64Ptr (5 ),
417
+ EventType : common .EventTypePtr (m .EventTypeTimerStarted ),
418
+ TimerStartedEventAttributes : & m.TimerStartedEventAttributes {
419
+ TimerId : common .StringPtr ("0" ),
420
+ StartToFireTimeoutSeconds : common .Int64Ptr (120 ),
421
+ DecisionTaskCompletedEventId : common .Int64Ptr (4 ),
422
+ },
423
+ },
424
+ {
425
+ EventId : common .Int64Ptr (6 ),
426
+ EventType : common .EventTypePtr (m .EventTypeTimerFired ),
427
+ TimerFiredEventAttributes : & m.TimerFiredEventAttributes {
428
+ TimerId : common .StringPtr ("0" ),
429
+ StartedEventId : common .Int64Ptr (5 ),
430
+ },
431
+ },
432
+ createTestEventDecisionTaskScheduled (7 , & m.DecisionTaskScheduledEventAttributes {TaskList : & m.TaskList {Name : & taskList }}),
433
+ createTestEventDecisionTaskStarted (8 ),
434
+ createTestEventDecisionTaskCompleted (9 , & m.DecisionTaskCompletedEventAttributes {ScheduledEventId : common .Int64Ptr (2 )}),
435
+ createTestEventActivityTaskScheduled (10 , & m.ActivityTaskScheduledEventAttributes {
436
+ ActivityId : common .StringPtr ("1" ),
437
+ ActivityType : & m.ActivityType {
438
+ Name : common .StringPtr (activityType ),
439
+ },
440
+ Domain : common .StringPtr (domain ),
441
+ TaskList : & m.TaskList {
442
+ Name : common .StringPtr (taskList ),
443
+ },
444
+ ScheduleToStartTimeoutSeconds : common .Int32Ptr (10 ),
445
+ StartToCloseTimeoutSeconds : common .Int32Ptr (10 ),
446
+ DecisionTaskCompletedEventId : common .Int64Ptr (9 ),
447
+ }),
448
+ }
449
+
450
+ s .service .EXPECT ().DescribeDomain (gomock .Any (), gomock .Any (), callOptions ... ).Return (nil , nil ).AnyTimes ()
451
+ task := & m.PollForDecisionTaskResponse {
452
+ TaskToken : []byte ("test-token" ),
453
+ WorkflowExecution : & m.WorkflowExecution {
454
+ WorkflowId : common .StringPtr (workflowID ),
455
+ RunId : common .StringPtr (runID ),
456
+ },
457
+ WorkflowType : & m.WorkflowType {
458
+ Name : common .StringPtr (workflowType ),
459
+ },
460
+ PreviousStartedEventId : common .Int64Ptr (0 ),
461
+ StartedEventId : common .Int64Ptr (3 ),
462
+ History : & m.History {Events : testEvents [0 :3 ]},
463
+ NextPageToken : nil ,
464
+ NextEventId : common .Int64Ptr (4 ),
465
+ }
466
+ s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (task , nil ).Times (1 )
467
+ s .service .EXPECT ().RespondDecisionTaskCompleted (gomock .Any (), gomock .Any (), callOptions ... ).DoAndReturn (func (ctx context.Context , request * m.RespondDecisionTaskCompletedRequest , opts ... yarpc.CallOption ,
468
+ ) (success * m.RespondDecisionTaskCompletedResponse , err error ) {
469
+ s .Equal (1 , len (request .Decisions ))
470
+ s .Equal (m .DecisionTypeStartTimer , request .Decisions [0 ].GetDecisionType ())
471
+ return & m.RespondDecisionTaskCompletedResponse {}, nil
472
+ }).Times (1 )
473
+ queryTask := & m.PollForDecisionTaskResponse {
474
+ TaskToken : []byte ("test-token" ),
475
+ WorkflowExecution : & m.WorkflowExecution {
476
+ WorkflowId : common .StringPtr (workflowID ),
477
+ RunId : common .StringPtr (runID ),
478
+ },
479
+ WorkflowType : & m.WorkflowType {
480
+ Name : common .StringPtr (workflowType ),
481
+ },
482
+ PreviousStartedEventId : common .Int64Ptr (3 ),
483
+ History : & m.History {}, // sticky query, so there's no history
484
+ NextPageToken : nil ,
485
+ NextEventId : common .Int64Ptr (5 ),
486
+ Query : & m.WorkflowQuery {
487
+ QueryType : common .StringPtr (queryType ),
488
+ },
489
+ }
490
+ s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).DoAndReturn (func (ctx context.Context , request * m.PollForDecisionTaskRequest , opts ... yarpc.CallOption ,
491
+ ) (success * m.PollForDecisionTaskResponse , err error ) {
492
+ getWorkflowCache ().Delete (runID ) // force remove the workflow state
493
+ return queryTask , nil
494
+ }).Times (1 )
495
+ s .service .EXPECT ().ResetStickyTaskList (gomock .Any (), gomock .Any (), callOptions ... ).Return (& m.ResetStickyTaskListResponse {}, nil ).AnyTimes ()
496
+ s .service .EXPECT ().GetWorkflowExecutionHistory (gomock .Any (), gomock .Any (), callOptions ... ).Return (& m.GetWorkflowExecutionHistoryResponse {
497
+ History : & m.History {Events : testEvents }, // workflow has made progress, return all available events
498
+ }, nil ).Times (1 )
499
+ dc := getDefaultDataConverter ()
500
+ expectedResult , err := dc .ToData ("waiting on timer" )
501
+ s .NoError (err )
502
+ s .service .EXPECT ().RespondQueryTaskCompleted (gomock .Any (), gomock .Any (), callOptions ... ).DoAndReturn (func (ctx context.Context , request * m.RespondQueryTaskCompletedRequest , opts ... yarpc.CallOption ) error {
503
+ s .Equal (m .QueryTaskCompletedTypeCompleted , request .GetCompletedType ())
504
+ s .Equal (expectedResult , request .GetQueryResult ())
505
+ close (doneCh )
506
+ return nil
507
+ }).Times (1 )
508
+ s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (& m.PollForDecisionTaskResponse {}, & m.InternalServiceError {}).AnyTimes ()
509
+
510
+ options := WorkerOptions {
511
+ Logger : zap .NewNop (),
512
+ DisableActivityWorker : true ,
513
+ Identity : "test-worker-identity" ,
514
+ DataConverter : dc ,
515
+ }
516
+ worker := newAggregatedWorker (s .service , domain , taskList , options )
517
+ worker .RegisterWorkflowWithOptions (
518
+ queryWorkflowFn ,
519
+ RegisterWorkflowOptions {Name : workflowType },
520
+ )
521
+ worker .RegisterActivityWithOptions (
522
+ activityFn ,
523
+ RegisterActivityOptions {Name : activityType },
524
+ )
525
+
526
+ worker .Start ()
527
+ <- doneCh
528
+ worker .Stop ()
529
+ }
530
+
362
531
func (s * WorkersTestSuite ) TestMultipleLocalActivities () {
363
532
localActivityCalledCount := 0
364
533
localActivitySleep := func (duration time.Duration ) error {
@@ -441,6 +610,7 @@ func (s *WorkersTestSuite) TestMultipleLocalActivities() {
441
610
StartedEventId : common .Int64Ptr (3 ),
442
611
History : & m.History {Events : testEvents [0 :3 ]},
443
612
NextPageToken : nil ,
613
+ NextEventId : common .Int64Ptr (4 ),
444
614
}
445
615
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (task , nil ).Times (1 )
446
616
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (& m.PollForDecisionTaskResponse {}, & m.InternalServiceError {}).AnyTimes ()
@@ -554,6 +724,7 @@ func (s *WorkersTestSuite) TestLocallyDispatchedActivity() {
554
724
StartedEventId : common .Int64Ptr (3 ),
555
725
History : & m.History {Events : testEvents [0 :3 ]},
556
726
NextPageToken : nil ,
727
+ NextEventId : common .Int64Ptr (4 ),
557
728
}
558
729
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (task , nil ).Times (1 )
559
730
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (& m.PollForDecisionTaskResponse {}, & m.InternalServiceError {}).AnyTimes ()
@@ -666,6 +837,7 @@ func (s *WorkersTestSuite) TestMultipleLocallyDispatchedActivity() {
666
837
StartedEventId : common .Int64Ptr (3 ),
667
838
History : & m.History {Events : testEvents [0 :3 ]},
668
839
NextPageToken : nil ,
840
+ NextEventId : common .Int64Ptr (4 ),
669
841
}
670
842
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (task , nil ).Times (1 )
671
843
s .service .EXPECT ().PollForDecisionTask (gomock .Any (), gomock .Any (), callOptions ... ).Return (& m.PollForDecisionTaskResponse {}, & m.InternalServiceError {}).AnyTimes ()
0 commit comments