@@ -5,52 +5,47 @@ import { MockActivityEnvironment, defaultActivityInfo } from '@temporalio/testin
5
5
import { isCancellation } from '@temporalio/workflow' ;
6
6
import { isAbortError } from '@temporalio/common/lib/type-helpers' ;
7
7
import * as activity from '@temporalio/activity' ;
8
- import { LogSource } from '@temporalio/common' ;
9
8
import { withZeroesHTTPServer } from './zeroes-http-server' ;
10
9
import { cancellableFetch } from './activities' ;
11
10
12
11
interface MyTestActivityContext extends activity . Context {
13
12
logs : Array < LogEntry > ;
14
13
}
15
14
16
- const mockLogger = new DefaultLogger ( 'DEBUG' , ( entry ) => {
17
- try {
15
+ test . before ( ( ) => {
16
+ const mockLogger = new DefaultLogger ( 'DEBUG' , ( entry ) => {
18
17
( activity . Context . current ( ) as MyTestActivityContext ) . logs ??= [ ] ;
19
18
( activity . Context . current ( ) as MyTestActivityContext ) . logs . push ( entry ) ;
20
- } catch ( e ) {
21
- // Ignore messages produced from non activity context
22
- if ( ( e as Error ) . message !== 'Activity context not initialized' ) throw e ;
23
- }
24
- } ) ;
25
- Runtime . install ( {
26
- logger : mockLogger ,
19
+ } ) ;
20
+ Runtime . install ( {
21
+ logger : mockLogger ,
22
+ } ) ;
27
23
} ) ;
28
24
29
- test ( ' Activity Context logger funnel through the parent Logger' , async ( t ) => {
30
- const env = new MockActivityEnvironment ( { } , { logger : mockLogger } ) ;
25
+ test ( " Activity Context logger defaults to Runtime's Logger" , async ( t ) => {
26
+ const env = new MockActivityEnvironment ( { } ) ;
31
27
await env . run ( async ( ) => {
32
28
activity . log . debug ( 'log message from activity' ) ;
33
29
} ) ;
34
30
const logs = ( env . context as MyTestActivityContext ) . logs ;
35
31
const entry = logs . find ( ( x ) => x . level === 'DEBUG' && x . message === 'log message from activity' ) ;
36
32
t . not ( entry , undefined ) ;
37
- t . deepEqual ( entry ?. meta , { ...activityLogAttributes ( defaultActivityInfo ) , logSource : LogSource . activity } ) ;
38
33
} ) ;
39
34
40
35
test ( 'Activity Worker logs when activity starts' , async ( t ) => {
41
- const env = new MockActivityEnvironment ( { } , { logger : mockLogger } ) ;
36
+ const env = new MockActivityEnvironment ( { } ) ;
42
37
await env . run ( async ( ) => {
43
38
activity . log . debug ( 'log message from activity' ) ;
44
39
} ) ;
45
40
const logs = ( env . context as MyTestActivityContext ) . logs ;
46
41
const entry = logs . find ( ( x ) => x . level === 'DEBUG' && x . message === 'Activity started' ) ;
47
42
t . not ( entry , undefined ) ;
48
- t . deepEqual ( entry ?. meta , { ... activityLogAttributes ( defaultActivityInfo ) , logSource : LogSource . worker } ) ;
43
+ t . deepEqual ( entry ?. meta , activityLogAttributes ( defaultActivityInfo ) ) ;
49
44
} ) ;
50
45
51
46
test ( 'Activity Worker logs warning when activity fails' , async ( t ) => {
52
47
const err = new Error ( 'Failed for test' ) ;
53
- const env = new MockActivityEnvironment ( { } , { logger : mockLogger } ) ;
48
+ const env = new MockActivityEnvironment ( { } ) ;
54
49
try {
55
50
await env . run ( async ( ) => {
56
51
throw err ;
@@ -65,11 +60,11 @@ test('Activity Worker logs warning when activity fails', async (t) => {
65
60
const { durationMs, error, ...rest } = entry ?. meta ?? { } ;
66
61
t . true ( Number . isInteger ( durationMs ) ) ;
67
62
t . is ( err , error ) ;
68
- t . deepEqual ( rest , { ... activityLogAttributes ( defaultActivityInfo ) , logSource : LogSource . worker } ) ;
63
+ t . deepEqual ( rest , activityLogAttributes ( defaultActivityInfo ) ) ;
69
64
} ) ;
70
65
71
66
test ( 'Activity Worker logs when activity completes async' , async ( t ) => {
72
- const env = new MockActivityEnvironment ( { } , { logger : mockLogger } ) ;
67
+ const env = new MockActivityEnvironment ( { } ) ;
73
68
try {
74
69
await env . run ( async ( ) => {
75
70
throw new activity . CompleteAsyncError ( ) ;
@@ -82,11 +77,11 @@ test('Activity Worker logs when activity completes async', async (t) => {
82
77
t . not ( entry , undefined ) ;
83
78
const { durationMs, ...rest } = entry ?. meta ?? { } ;
84
79
t . true ( Number . isInteger ( durationMs ) ) ;
85
- t . deepEqual ( rest , { ... activityLogAttributes ( defaultActivityInfo ) , logSource : LogSource . worker } ) ;
80
+ t . deepEqual ( rest , activityLogAttributes ( defaultActivityInfo ) ) ;
86
81
} ) ;
87
82
88
83
test ( 'Activity Worker logs when activity is cancelled with promise' , async ( t ) => {
89
- const env = new MockActivityEnvironment ( { } , { logger : mockLogger } ) ;
84
+ const env = new MockActivityEnvironment ( { } ) ;
90
85
env . on ( 'heartbeat' , ( ) => env . cancel ( ) ) ;
91
86
try {
92
87
await env . run ( async ( ) => {
@@ -101,11 +96,11 @@ test('Activity Worker logs when activity is cancelled with promise', async (t) =
101
96
t . not ( entry , undefined ) ;
102
97
const { durationMs, ...rest } = entry ?. meta ?? { } ;
103
98
t . true ( Number . isInteger ( durationMs ) ) ;
104
- t . deepEqual ( rest , { ... activityLogAttributes ( defaultActivityInfo ) , logSource : LogSource . worker } ) ;
99
+ t . deepEqual ( rest , activityLogAttributes ( defaultActivityInfo ) ) ;
105
100
} ) ;
106
101
107
102
test ( 'Activity Worker logs when activity is cancelled with signal' , async ( t ) => {
108
- const env = new MockActivityEnvironment ( { } , { logger : mockLogger } ) ;
103
+ const env = new MockActivityEnvironment ( { } ) ;
109
104
env . on ( 'heartbeat' , ( ) => env . cancel ( ) ) ;
110
105
try {
111
106
await env . run ( async ( ) => {
@@ -121,7 +116,7 @@ test('Activity Worker logs when activity is cancelled with signal', async (t) =>
121
116
t . not ( entry , undefined ) ;
122
117
const { durationMs, ...rest } = entry ?. meta ?? { } ;
123
118
t . true ( Number . isInteger ( durationMs ) ) ;
124
- t . deepEqual ( rest , { ... activityLogAttributes ( defaultActivityInfo ) , logSource : LogSource . worker } ) ;
119
+ t . deepEqual ( rest , activityLogAttributes ( defaultActivityInfo ) ) ;
125
120
} ) ;
126
121
127
122
test ( '(Legacy) ActivityInboundLogInterceptor does not override Context.log by default' , async ( t ) => {
@@ -130,7 +125,6 @@ test('(Legacy) ActivityInboundLogInterceptor does not override Context.log by de
130
125
{
131
126
// eslint-disable-next-line deprecation/deprecation
132
127
interceptors : [ ( ctx ) => ( { inbound : new ActivityInboundLogInterceptor ( ctx ) } ) ] ,
133
- logger : mockLogger ,
134
128
}
135
129
) ;
136
130
await env . run ( async ( ) => {
@@ -152,14 +146,15 @@ test('(Legacy) ActivityInboundLogInterceptor overrides Context.log if a logger i
152
146
{
153
147
// eslint-disable-next-line deprecation/deprecation
154
148
interceptors : [ ( ctx ) => ( { inbound : new ActivityInboundLogInterceptor ( ctx , logger ) } ) ] ,
155
- logger : mockLogger ,
156
149
}
157
150
) ;
158
151
await env . run ( async ( ) => {
159
152
activity . log . debug ( 'log message from activity' ) ;
160
153
} ) ;
161
- const entry = logs . find ( ( x ) => x . level === 'DEBUG' && x . message === 'log message from activity' ) ;
162
- t . not ( entry , undefined ) ;
154
+ const entry1 = logs . find ( ( x ) => x . level === 'DEBUG' && x . message === 'Activity started' ) ;
155
+ t . not ( entry1 , undefined ) ;
156
+ const entry2 = logs . find ( ( x ) => x . level === 'DEBUG' && x . message === 'log message from activity' ) ;
157
+ t . not ( entry2 , undefined ) ;
163
158
} ) ;
164
159
165
160
test ( '(Legacy) ActivityInboundLogInterceptor overrides Context.log if class is extended' , async ( t ) => {
@@ -177,7 +172,6 @@ test('(Legacy) ActivityInboundLogInterceptor overrides Context.log if class is e
177
172
{ } ,
178
173
{
179
174
interceptors : [ ( ctx ) => ( { inbound : new CustomActivityInboundLogInterceptor ( ctx ) } ) ] ,
180
- logger : mockLogger ,
181
175
}
182
176
) ;
183
177
await env . run ( async ( ) => {
0 commit comments