@@ -3,6 +3,7 @@ import v8 from 'node:v8';
3
3
import { readFileSync } from 'node:fs' ;
4
4
import pkg from '@temporalio/worker/lib/pkg' ;
5
5
import { bundleWorkflowCode } from '@temporalio/worker' ;
6
+ import { temporal } from '@temporalio/proto' ;
6
7
import { configMacro , makeTestFn } from './helpers-integration-multi-codec' ;
7
8
import { configurableHelpers } from './helpers-integration' ;
8
9
import { withZeroesHTTPServer } from './zeroes-http-server' ;
@@ -140,3 +141,56 @@ if ('promiseHooks' in v8) {
140
141
t . deepEqual ( Object . entries ( enhancedStack . sources ) , expectedSources ) ;
141
142
} ) ;
142
143
}
144
+
145
+ test (
146
+ 'priorities can be specified and propagated across child workflows and activities' ,
147
+ configMacro ,
148
+ async ( t , config ) => {
149
+ const { env, createWorkerWithDefaults } = config ;
150
+ const { startWorkflow } = configurableHelpers ( t , t . context . workflowBundle , env ) ;
151
+ const worker = await createWorkerWithDefaults ( t , { activities } ) ;
152
+ const handle = await startWorkflow ( workflows . priorityWorkflow , {
153
+ args : [ false , 1 ] ,
154
+ priority : { priorityKey : 1 } ,
155
+ } ) ;
156
+ await worker . runUntil ( handle . result ( ) ) ;
157
+ let firstChild = true ;
158
+ const history = await handle . fetchHistory ( ) ;
159
+ console . log ( 'events' ) ;
160
+ for ( const event of history ?. events ?? [ ] ) {
161
+ switch ( event . eventType ) {
162
+ case temporal . api . enums . v1 . EventType . EVENT_TYPE_WORKFLOW_EXECUTION_STARTED :
163
+ t . deepEqual ( event . workflowExecutionStartedEventAttributes ?. priority ?. priorityKey , 1 ) ;
164
+ break ;
165
+ case temporal . api . enums . v1 . EventType . EVENT_TYPE_START_CHILD_WORKFLOW_EXECUTION_INITIATED : {
166
+ const pri = event . startChildWorkflowExecutionInitiatedEventAttributes ?. priority ?. priorityKey ;
167
+ if ( firstChild ) {
168
+ t . deepEqual ( pri , 4 ) ;
169
+ firstChild = false ;
170
+ } else {
171
+ t . deepEqual ( pri , 2 ) ;
172
+ }
173
+ break ;
174
+ }
175
+ case temporal . api . enums . v1 . EventType . EVENT_TYPE_ACTIVITY_TASK_SCHEDULED :
176
+ t . deepEqual ( event . activityTaskScheduledEventAttributes ?. priority ?. priorityKey , 5 ) ;
177
+ break ;
178
+ }
179
+ }
180
+ }
181
+ ) ;
182
+
183
+ test ( 'workflow start without priorities sees undefined for the key' , configMacro , async ( t , config ) => {
184
+ const { env, createWorkerWithDefaults } = config ;
185
+ const { startWorkflow } = configurableHelpers ( t , t . context . workflowBundle , env ) ;
186
+ const worker = await createWorkerWithDefaults ( t , { activities } ) ;
187
+ console . log ( 'STARTING WORKFLOW' ) ;
188
+
189
+ const handle1 = await startWorkflow ( workflows . priorityWorkflow , {
190
+ args : [ true , undefined ] ,
191
+ } ) ;
192
+ await worker . runUntil ( handle1 . result ( ) ) ;
193
+
194
+ // check occurs in the workflow, need an assert in the test itself in order to run
195
+ t . true ( true ) ;
196
+ } ) ;
0 commit comments