@@ -10,6 +10,7 @@ import {
10
10
} from '@temporalio/client' ;
11
11
import * as wf from '@temporalio/workflow' ;
12
12
import { temporal } from '@temporalio/proto' ;
13
+ import { LogEntry } from '@temporalio/worker' ;
13
14
import { helpers , makeTestFunction } from './helpers-integration' ;
14
15
import { signalUpdateOrderingWorkflow } from './workflows/signal-update-ordering' ;
15
16
import { signalsActivitiesTimersPromiseOrdering } from './workflows/signals-timers-activities-order' ;
@@ -19,6 +20,8 @@ import { loadHistory, waitUntil } from './helpers';
19
20
// polling/retry strategies result in the expected behavior
20
21
const LONG_POLL_EXPIRATION_INTERVAL_SECONDS = 5.0 ;
21
22
23
+ const recordedLogs : { [ workflowId : string ] : LogEntry [ ] } = { } ;
24
+
22
25
const test = makeTestFunction ( {
23
26
workflowsPath : __filename ,
24
27
workflowEnvironmentOpts : {
@@ -29,6 +32,7 @@ const test = makeTestFunction({
29
32
] ,
30
33
} ,
31
34
} ,
35
+ recordedLogs,
32
36
} ) ;
33
37
34
38
export const update = wf . defineUpdate < string [ ] , [ string ] > ( 'update' ) ;
@@ -1016,3 +1020,35 @@ test('Can complete update after workflow returns - pre-1.11.0 compatibility', as
1016
1020
await runReplayHistory ( { } , hist ) ;
1017
1021
t . pass ( ) ;
1018
1022
} ) ;
1023
+
1024
+ const logUpdate = wf . defineUpdate < [ string , string ] , [ string ] > ( 'log-update' ) ;
1025
+ export async function workflowWithLogInUpdate ( ) : Promise < void > {
1026
+ const updateHandler = ( msg : string ) : [ string , string ] => {
1027
+ const updateInfo = wf . currentUpdateInfo ( ) ;
1028
+ if ( ! updateInfo ) {
1029
+ throw new Error ( 'expected updateInfo to be defined' ) ;
1030
+ }
1031
+ wf . log . info ( msg ) ;
1032
+ return [ updateInfo . id , updateInfo . name ] ;
1033
+ } ;
1034
+ wf . setHandler ( logUpdate , updateHandler ) ;
1035
+ await wf . condition ( ( ) => false ) ;
1036
+ }
1037
+
1038
+ test ( 'Workflow Worker logs update info when logging within update handler' , async ( t ) => {
1039
+ const { createWorker, startWorkflow } = helpers ( t ) ;
1040
+ const worker = await createWorker ( ) ;
1041
+ await worker . runUntil ( async ( ) => {
1042
+ const wfHandle = await startWorkflow ( workflowWithLogInUpdate ) ;
1043
+ const logMsg = 'log msg' ;
1044
+ const [ updateId , updateName ] = await wfHandle . executeUpdate ( logUpdate , { args : [ logMsg ] } ) ;
1045
+ t . true (
1046
+ recordedLogs [ wfHandle . workflowId ] . some (
1047
+ ( logEntry ) =>
1048
+ logEntry . meta ?. updateName === updateName &&
1049
+ logEntry . meta ?. updateId === updateId &&
1050
+ logEntry . message === logMsg
1051
+ )
1052
+ ) ;
1053
+ } ) ;
1054
+ } ) ;
0 commit comments