55namespace Temporal \Tests \Acceptance \Harness \Activity \CancelTryCancel ;
66
77use PHPUnit \Framework \Attributes \Test ;
8- use React \Promise \PromiseInterface ;
98use Temporal \Activity ;
109use Temporal \Activity \ActivityInterface ;
1110use Temporal \Activity \ActivityMethod ;
2120use Temporal \Workflow \WorkflowInterface ;
2221use Temporal \Workflow \WorkflowMethod ;
2322
24- /*
25-
26- # Activity cancellation - Try Cancel mode
27- Activities may be cancelled in three different ways, this feature spec covers the
28- Try Cancel mode.
29-
30- Each feature workflow in this folder should start an activity and cancel it
31- using the Try Cancel mode. The implementation should demonstrate that the activity
32- keeps receives a cancel request after the workflow has issued it, but the workflow
33- immediately should proceed with the activity result being cancelled.
34-
35- ## Detailed spec
36-
37- * When the SDK issues the activity cancel request command, server will write an
38- activity cancel requested event to history
39- * The workflow immediately resolves the activity with its result being cancelled
40- * Server will notify the activity cancellation has been requested via a response
41- to activity heartbeating
42- * The activity may ignore the cancellation request if it explicitly chooses to
43-
44- ## Feature implementation
45-
46- * Execute activity that heartbeats and checks cancellation
47- * If a minute passes without cancellation, send workflow a signal that it timed out
48- * If cancellation is received, send workflow a signal that it was cancelled
49- * Cancel activity and confirm cancellation error is returned
50- * Check in the workflow that the signal sent from the activity is showing it was cancelled
51-
52- */
53-
23+ /**
24+ * # Activity cancellation - Try Cancel mode
25+ *
26+ * Activities may be cancelled in three different ways, this feature spec covers the
27+ * Try Cancel mode.
28+ *
29+ * Each feature workflow in this folder should start an activity and cancel it
30+ * using the Try Cancel mode. The implementation should demonstrate that the activity
31+ * keeps receives a cancel request after the workflow has issued it, but the workflow
32+ * immediately should proceed with the activity result being cancelled.
33+ *
34+ * ## Detailed spec
35+ *
36+ * When the SDK issues the activity cancel request command, server will write an
37+ * activity cancel requested event to history
38+ * The workflow immediately resolves the activity with its result being cancelled
39+ * Server will notify the activity cancellation has been requested via a response
40+ * to activity heartbeating
41+ * The activity may ignore the cancellation request if it explicitly chooses to
42+ *
43+ * ## Feature implementation
44+ *
45+ * Execute activity that heartbeats and checks cancellation
46+ * If a minute passes without cancellation, send workflow a signal that it timed out
47+ * If cancellation is received, send workflow a signal that it was cancelled
48+ * Cancel activity and confirm cancellation error is returned
49+ * Check in the workflow that the signal sent from the activity is showing it was cancelled
50+ */
5451class CancelTryCancelTest extends TestCase
5552{
5653 #[Test]
57- public static function check (#[Stub('Harness_Activity_CancelTryCancel ' )]WorkflowStubInterface $ stub ): void
58- {
54+ public static function check (
55+ #[Stub('Harness_Activity_CancelTryCancel ' )]
56+ WorkflowStubInterface $ stub ,
57+ ): void {
5958 self ::assertSame ('cancelled ' , $ stub ->getResult (timeout: 10 ));
6059 }
6160}
@@ -76,7 +75,7 @@ public function run()
7675 ->withHeartbeatTimeout ('5 seconds ' )
7776 # Disable retry
7877 ->withRetryOptions (RetryOptions::new ()->withMaximumAttempts (1 ))
79- ->withCancellationType (Activity \ActivityCancellationType::TryCancel)
78+ ->withCancellationType (Activity \ActivityCancellationType::TryCancel),
8079 );
8180
8281 $ scope = Workflow::async (static fn () => $ activity ->cancellableActivity ());
@@ -98,7 +97,7 @@ public function run()
9897 }
9998
10099 #[Workflow \SignalMethod('activity_result ' )]
101- public function activityResult (string $ result )
100+ public function activityResult (string $ result ): void
102101 {
103102 $ this ->result = $ result ;
104103 }
@@ -109,14 +108,10 @@ class FeatureActivity
109108{
110109 public function __construct (
111110 private readonly WorkflowClientInterface $ client ,
112- ) {
113- }
111+ ) {}
114112
115- /**
116- * @return PromiseInterface<null>
117- */
118113 #[ActivityMethod('cancellable_activity ' )]
119- public function cancellableActivity ()
114+ public function cancellableActivity (): void
120115 {
121116 # Heartbeat every second for a minute
122117 $ result = 'timeout ' ;
0 commit comments