@@ -10,7 +10,9 @@ import (
1010 "github.com/stretchr/testify/assert"
1111 "github.com/stretchr/testify/require"
1212 "github.com/stretchr/testify/suite"
13+ commonpb "go.temporal.io/api/common/v1"
1314 enumspb "go.temporal.io/api/enums/v1"
15+ querypb "go.temporal.io/api/query/v1"
1416 "go.temporal.io/api/serviceerror"
1517 "go.temporal.io/api/workflowservice/v1"
1618 sdkclient "go.temporal.io/sdk/client"
@@ -113,6 +115,87 @@ func (s *PauseWorkflowExecutionSuite) TestPauseWorkflowExecution() {
113115 }, 5 * time .Second , 200 * time .Millisecond )
114116}
115117
118+ func (s * PauseWorkflowExecutionSuite ) TestQueryWorkflowWhenPaused () {
119+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
120+ defer cancel ()
121+
122+ s .Worker ().RegisterWorkflow (s .workflowFn )
123+
124+ workflowOptions := sdkclient.StartWorkflowOptions {
125+ ID : testcore .RandomizeStr ("pause-wf-" + s .T ().Name ()),
126+ TaskQueue : s .TaskQueue (),
127+ }
128+
129+ workflowRun , err := s .SdkClient ().ExecuteWorkflow (ctx , workflowOptions , s .workflowFn )
130+ s .NoError (err )
131+ workflowID := workflowRun .GetID ()
132+ runID := workflowRun .GetRunID ()
133+
134+ s .EventuallyWithT (func (t * assert.CollectT ) {
135+ desc , err := s .SdkClient ().DescribeWorkflowExecution (ctx , workflowID , runID )
136+ require .NoError (t , err )
137+ info := desc .GetWorkflowExecutionInfo ()
138+ require .NotNil (t , info )
139+ require .Equal (t , enumspb .WORKFLOW_EXECUTION_STATUS_RUNNING , info .GetStatus ())
140+ }, 5 * time .Second , 100 * time .Millisecond )
141+
142+ // Pause the workflow.
143+ pauseRequest := & workflowservice.PauseWorkflowExecutionRequest {
144+ Namespace : s .Namespace ().String (),
145+ WorkflowId : workflowID ,
146+ RunId : runID ,
147+ Identity : s .pauseIdentity ,
148+ Reason : s .pauseReason ,
149+ RequestId : uuid .New (),
150+ }
151+ pauseResp , err := s .FrontendClient ().PauseWorkflowExecution (ctx , pauseRequest )
152+ s .NoError (err )
153+ s .NotNil (pauseResp )
154+
155+ // Wait until paused.
156+ s .EventuallyWithT (func (t * assert.CollectT ) {
157+ desc , err := s .SdkClient ().DescribeWorkflowExecution (ctx , workflowID , runID )
158+ require .NoError (t , err )
159+ info := desc .GetWorkflowExecutionInfo ()
160+ require .NotNil (t , info )
161+ require .Equal (t , enumspb .WORKFLOW_EXECUTION_STATUS_PAUSED , info .GetStatus ())
162+ if pauseInfo := desc .GetWorkflowExtendedInfo ().GetPauseInfo (); pauseInfo != nil {
163+ require .Equal (t , s .pauseIdentity , pauseInfo .GetIdentity ())
164+ require .Equal (t , s .pauseReason , pauseInfo .GetReason ())
165+ }
166+ }, 5 * time .Second , 200 * time .Millisecond )
167+
168+ // Issue a query with reject condition so that paused workflows return QueryRejected with PAUSED status.
169+ queryReq := & workflowservice.QueryWorkflowRequest {
170+ Namespace : s .Namespace ().String (),
171+ Execution : & commonpb.WorkflowExecution {
172+ WorkflowId : workflowID ,
173+ RunId : runID ,
174+ },
175+ Query : & querypb.WorkflowQuery {
176+ QueryType : "__stack_trace" ,
177+ },
178+ QueryRejectCondition : enumspb .QUERY_REJECT_CONDITION_NOT_OPEN ,
179+ }
180+ queryResp , err := s .FrontendClient ().QueryWorkflow (ctx , queryReq )
181+ s .NoError (err )
182+ s .NotNil (queryResp )
183+ s .NotNil (queryResp .GetQueryRejected ())
184+ s .Equal (enumspb .WORKFLOW_EXECUTION_STATUS_PAUSED , queryResp .GetQueryRejected ().GetStatus ())
185+
186+ // Complete the workflow to finish the test.
187+ err = s .SdkClient ().SignalWorkflow (ctx , workflowID , runID , s .testEndSignal , "test end signal" )
188+ s .NoError (err )
189+
190+ s .EventuallyWithT (func (t * assert.CollectT ) {
191+ desc , err := s .SdkClient ().DescribeWorkflowExecution (ctx , workflowID , runID )
192+ require .NoError (t , err )
193+ info := desc .GetWorkflowExecutionInfo ()
194+ require .NotNil (t , info )
195+ require .Equal (t , enumspb .WORKFLOW_EXECUTION_STATUS_COMPLETED , info .GetStatus ())
196+ }, 5 * time .Second , 200 * time .Millisecond )
197+ }
198+
116199// TestPauseWorkflowExecutionRequestValidation tests that pause workflow execution request validation. We don't really need a valid workflow to test this.
117200// - fails when the identity is too long.
118201// - fails when the reason is too long.
0 commit comments