1919class PriorityTest extends TestCase
2020{
2121 #[Test]
22- public function instanceInPriority (
22+ public function priorityKey (
2323 WorkflowClientInterface $ client ,
2424 Feature $ feature ,
2525 ): void {
@@ -34,10 +34,38 @@ public function instanceInPriority(
3434 $ client ->start ($ stub , true );
3535 $ result = $ stub ->getResult ('array ' );
3636
37+ self ::assertSame (2 , $ result ['activity ' ]['priority_key ' ]);
38+ self ::assertSame (1 , $ result ['child ' ]['priority_key ' ]);
39+ self ::assertSame (4 , $ result ['workflow ' ]['priority_key ' ]);
40+ }
41+
42+ #[Test]
43+ public function fairness (
44+ WorkflowClientInterface $ client ,
45+ Feature $ feature ,
46+ ): void {
47+ $ stub = $ client ->newUntypedWorkflowStub (
48+ 'Extra_Workflow_Priority ' ,
49+ WorkflowOptions::new ()
50+ ->withTaskQueue ($ feature ->taskQueue )
51+ ->withPriority (
52+ Priority::new ()
53+ ->withFairnessKey ('parent-key ' )
54+ ->withFairnessWeight (2.2 ),
55+ ),
56+ );
3757
38- self ::assertSame ([2 ], $ result ['activity ' ]);
39- self ::assertSame ([1 ], $ result ['child ' ]);
40- self ::assertSame ([4 ], $ result ['workflow ' ]);
58+ /** @see TestWorkflow::handle() */
59+ $ client ->start ($ stub , true );
60+ $ result = $ stub ->getResult ('array ' );
61+
62+
63+ self ::assertSame ('activity-key ' , $ result ['activity ' ]['fairness_key ' ]);
64+ self ::assertSame (5.4 , $ result ['activity ' ]['fairness_weight ' ]);
65+ self ::assertSame ('parent-key ' , $ result ['workflow ' ]['fairness_key ' ]);
66+ self ::assertSame (2.2 , $ result ['workflow ' ]['fairness_weight ' ]);
67+ self ::assertSame ('child-key ' , $ result ['child ' ]['fairness_key ' ]);
68+ self ::assertSame (3.3 , $ result ['child ' ]['fairness_weight ' ]);
4169 }
4270}
4371
@@ -51,7 +79,11 @@ public function handle(bool $runChild = false)
5179 'Extra_Workflow_Priority.handler ' ,
5280 options: Activity \ActivityOptions::new ()
5381 ->withScheduleToCloseTimeout ('10 seconds ' )
54- ->withPriority (Priority::new (2 )),
82+ ->withPriority (
83+ Priority::new (2 )
84+ ->withFairnessKey ('activity-key ' )
85+ ->withFairnessWeight (5.4 ),
86+ ),
5587 );
5688
5789 Workflow \ChildWorkflowOptions::new ()->priority ->priorityKey === Workflow::getInfo ()->priority ->priorityKey or
@@ -61,14 +93,22 @@ public function handle(bool $runChild = false)
6193 $ child = yield Workflow::executeChildWorkflow (
6294 'Extra_Workflow_Priority ' ,
6395 [false ],
64- Workflow \ChildWorkflowOptions::new ()->withPriority (Priority::new (1 )),
96+ Workflow \ChildWorkflowOptions::new ()->withPriority (
97+ Priority::new (1 )
98+ ->withFairnessKey ('child-key ' )
99+ ->withFairnessWeight (3.3 ),
100+ ),
65101 'array ' ,
66102 );
67103 }
68104
69105 return [
70106 'activity ' => $ activity ,
71- 'workflow ' => [Workflow::getInfo ()->priority ->priorityKey ],
107+ 'workflow ' => [
108+ 'priority_key ' => Workflow::getInfo ()->priority ->priorityKey ,
109+ 'fairness_key ' => Workflow::getInfo ()->priority ->fairnessKey ,
110+ 'fairness_weight ' => Workflow::getInfo ()->priority ->fairnessWeight ,
111+ ],
72112 'child ' => $ child ['workflow ' ] ?? null ,
73113 ];
74114 }
@@ -80,6 +120,10 @@ class TestActivity
80120 #[Activity \ActivityMethod]
81121 public function handler (): array
82122 {
83- return [Activity::getInfo ()->priority ->priorityKey ];
123+ return [
124+ 'priority_key ' => Activity::getInfo ()->priority ->priorityKey ,
125+ 'fairness_key ' => Activity::getInfo ()->priority ->fairnessKey ,
126+ 'fairness_weight ' => Activity::getInfo ()->priority ->fairnessWeight ,
127+ ];
84128 }
85129}
0 commit comments