@@ -3,6 +3,7 @@ package tests
33import (
44 "context"
55 "strings"
6+ "sync"
67 "testing"
78 "time"
89
@@ -29,6 +30,9 @@ type PauseWorkflowExecutionSuite struct {
2930 workflowFn func (ctx workflow.Context ) (string , error )
3031 childWorkflowFn func (ctx workflow.Context ) (string , error )
3132 activityFn func (ctx context.Context ) (string , error )
33+
34+ activityCompletedCh chan struct {}
35+ activityCompletedOnce sync.Once
3236}
3337
3438func TestPauseWorkflowExecutionSuite (t * testing.T ) {
@@ -43,6 +47,7 @@ func (s *PauseWorkflowExecutionSuite) SetupTest() {
4347 s .testEndSignal = "test-end"
4448 s .pauseIdentity = "functional-test"
4549 s .pauseReason = "pausing workflow for acceptance test"
50+ s .activityCompletedCh = make (chan struct {}, 1 )
4651
4752 s .workflowFn = func (ctx workflow.Context ) (string , error ) {
4853 ao := workflow.ActivityOptions {
@@ -72,6 +77,10 @@ func (s *PauseWorkflowExecutionSuite) SetupTest() {
7277 }
7378
7479 s .activityFn = func (ctx context.Context ) (string , error ) {
80+ s .activityCompletedOnce .Do (func () {
81+ // blocks until the test case unblocks the activity.
82+ <- s .activityCompletedCh
83+ })
7584 return "activity" , nil
7685 }
7786}
@@ -116,6 +125,27 @@ func (s *PauseWorkflowExecutionSuite) TestPauseUnpauseWorkflowExecution() {
116125 s .NoError (err )
117126 s .NotNil (pauseResp )
118127
128+ // unblock the activity to complete.
129+ s .activityCompletedCh <- struct {}{}
130+
131+ // ensure that the workflow is paused even when the activity is completed.
132+ s .EventuallyWithT (func (t * assert.CollectT ) {
133+ desc , err := s .SdkClient ().DescribeWorkflowExecution (ctx , workflowID , runID )
134+ require .NoError (t , err )
135+ info := desc .GetWorkflowExecutionInfo ()
136+ require .NotNil (t , info )
137+ require .Equal (t , enumspb .WORKFLOW_EXECUTION_STATUS_PAUSED , info .GetStatus ())
138+ if pauseInfo := desc .GetWorkflowExtendedInfo ().GetPauseInfo (); pauseInfo != nil {
139+ require .Equal (t , s .pauseIdentity , pauseInfo .GetIdentity ())
140+ require .Equal (t , s .pauseReason , pauseInfo .GetReason ())
141+ }
142+ }, 5 * time .Second , 200 * time .Millisecond )
143+
144+ // Send unblock signal to the workflow to complete and assert that the workflow stays paused.
145+ err = s .SdkClient ().SignalWorkflow (ctx , workflowID , runID , s .testEndSignal , "signal to complete the workflow" )
146+ s .NoError (err )
147+
148+ time .Sleep (2 * time .Second ) // wait 2 seconds to give enough time record the signal.
119149 s .EventuallyWithT (func (t * assert.CollectT ) {
120150 desc , err := s .SdkClient ().DescribeWorkflowExecution (ctx , workflowID , runID )
121151 require .NoError (t , err )
@@ -141,21 +171,7 @@ func (s *PauseWorkflowExecutionSuite) TestPauseUnpauseWorkflowExecution() {
141171 s .NoError (err )
142172 s .NotNil (unpauseResp )
143173
144- // Wait until unpaused (running again).
145- s .EventuallyWithT (func (t * assert.CollectT ) {
146- desc , err := s .SdkClient ().DescribeWorkflowExecution (ctx , workflowID , runID )
147- require .NoError (t , err )
148- info := desc .GetWorkflowExecutionInfo ()
149- require .NotNil (t , info )
150- require .Equal (t , enumspb .WORKFLOW_EXECUTION_STATUS_RUNNING , info .GetStatus ())
151- require .Nil (t , desc .GetWorkflowExtendedInfo ().GetPauseInfo ())
152- }, 5 * time .Second , 200 * time .Millisecond )
153-
154- // TODO: currently pause workflow execution does not intercept workflow creation. Fix the reset of this test when that is implemented.
155- // For now sending this signal will complete the workflow and finish the test.
156- err = s .SdkClient ().SignalWorkflow (ctx , workflowID , runID , s .testEndSignal , "test end signal" )
157- s .NoError (err )
158-
174+ // assert that the workflow completes now.
159175 s .EventuallyWithT (func (t * assert.CollectT ) {
160176 desc , err := s .SdkClient ().DescribeWorkflowExecution (ctx , workflowID , runID )
161177 require .NoError (t , err )
0 commit comments