@@ -6112,3 +6112,76 @@ func (s *mutableStateSuite) TestCHASMNodeSize() {
61126112 expectedTotalSize += len (newNodeKey ) + newNode .Size ()
61136113 s .Equal (expectedTotalSize , mutableState .GetApproximatePersistedSize ())
61146114}
6115+
6116+ func (s * mutableStateSuite ) TestAddActivityTaskStartedEventStoresWorkerInstanceKey () {
6117+ s .mockEventsCache .EXPECT ().PutEvent (gomock .Any (), gomock .Any ()).AnyTimes ()
6118+
6119+ // Setup workflow execution
6120+ _ , err := s .mutableState .AddWorkflowExecutionStartedEvent (
6121+ & commonpb.WorkflowExecution {WorkflowId : tests .WorkflowID , RunId : tests .RunID },
6122+ & historyservice.StartWorkflowExecutionRequest {
6123+ NamespaceId : tests .NamespaceID .String (),
6124+ StartRequest : & workflowservice.StartWorkflowExecutionRequest {
6125+ WorkflowType : & commonpb.WorkflowType {Name : "workflow-type" },
6126+ TaskQueue : & taskqueuepb.TaskQueue {Name : "task-queue" },
6127+ WorkflowRunTimeout : durationpb .New (200 * time .Second ),
6128+ WorkflowTaskTimeout : durationpb .New (1 * time .Second ),
6129+ },
6130+ },
6131+ )
6132+ s .NoError (err )
6133+
6134+ di , err := s .mutableState .AddWorkflowTaskScheduledEvent (false , enumsspb .WORKFLOW_TASK_TYPE_NORMAL )
6135+ s .NoError (err )
6136+ _ , _ , err = s .mutableState .AddWorkflowTaskStartedEvent (
6137+ di .ScheduledEventID ,
6138+ di .RequestID ,
6139+ di .TaskQueue ,
6140+ "identity" ,
6141+ nil ,
6142+ nil ,
6143+ nil ,
6144+ false ,
6145+ nil ,
6146+ )
6147+ s .NoError (err )
6148+ _ , err = s .mutableState .AddWorkflowTaskCompletedEvent (
6149+ di ,
6150+ & workflowservice.RespondWorkflowTaskCompletedRequest {Identity : "identity" },
6151+ workflowTaskCompletionLimits ,
6152+ )
6153+ s .NoError (err )
6154+
6155+ // Schedule activity
6156+ workflowTaskCompletedEventID := int64 (4 )
6157+ _ , activityInfo , err := s .mutableState .AddActivityTaskScheduledEvent (
6158+ workflowTaskCompletedEventID ,
6159+ & commandpb.ScheduleActivityTaskCommandAttributes {
6160+ ActivityId : "test-activity-1" ,
6161+ ActivityType : & commonpb.ActivityType {Name : "test-activity-type" },
6162+ TaskQueue : & taskqueuepb.TaskQueue {Name : "test-task-queue" },
6163+ },
6164+ false ,
6165+ )
6166+ s .NoError (err )
6167+ s .Empty (activityInfo .WorkerInstanceKey , "WorkerInstanceKey should be empty before activity starts" )
6168+
6169+ // Start activity with workerInstanceKey
6170+ expectedWorkerInstanceKey := "test-worker-instance-key-12345"
6171+ _ , err = s .mutableState .AddActivityTaskStartedEvent (
6172+ activityInfo ,
6173+ activityInfo .ScheduledEventId ,
6174+ uuid .NewString (),
6175+ "worker-identity" ,
6176+ nil ,
6177+ nil ,
6178+ nil ,
6179+ expectedWorkerInstanceKey ,
6180+ )
6181+ s .NoError (err )
6182+
6183+ // Verify workerInstanceKey is stored
6184+ updatedActivityInfo , ok := s .mutableState .GetActivityInfo (activityInfo .ScheduledEventId )
6185+ s .True (ok )
6186+ s .Equal (expectedWorkerInstanceKey , updatedActivityInfo .WorkerInstanceKey )
6187+ }
0 commit comments