1
1
import { ApplicationFailure , defaultPayloadConverter , WorkflowClient , WorkflowFailedError } from '@temporalio/client' ;
2
2
import { temporal } from '@temporalio/proto' ;
3
- import { Worker } from '@temporalio/worker' ;
3
+ import { bundleWorkflowCode , Worker , WorkflowBundleWithSourceMap } from '@temporalio/worker' ;
4
4
import { isCancellation } from '@temporalio/workflow' ;
5
5
import anyTest , { TestInterface } from 'ava' ;
6
6
import { firstValueFrom , Subject } from 'rxjs' ;
@@ -10,30 +10,40 @@ import { RUN_INTEGRATION_TESTS } from './helpers';
10
10
import * as workflows from './workflows/local-activity-testers' ;
11
11
12
12
interface Context {
13
+ workflowBundle : WorkflowBundleWithSourceMap ;
13
14
taskQueue : string ;
14
15
client : WorkflowClient ;
16
+ getWorker : ( ) => Promise < Worker > ;
15
17
}
16
18
17
19
const test = anyTest as TestInterface < Context > ;
18
20
21
+ test . before ( async ( t ) => {
22
+ t . context . workflowBundle = await bundleWorkflowCode ( {
23
+ workflowsPath : require . resolve ( './workflows/local-activity-testers' ) ,
24
+ } ) ;
25
+ } ) ;
26
+
19
27
test . beforeEach ( async ( t ) => {
20
28
const title = t . title . replace ( 'beforeEach hook for ' , '' ) ;
21
29
const taskQueue = `test-local-activities-${ title } ` ;
22
- t . context = { client : new WorkflowClient ( ) , taskQueue } ;
23
- } ) ;
24
-
25
- async function defaultWorker ( taskQueue : string ) {
26
- return await Worker . create ( {
30
+ t . context = {
31
+ ...t . context ,
32
+ client : new WorkflowClient ( ) ,
27
33
taskQueue,
28
- workflowsPath : require . resolve ( './workflows/local-activity-testers' ) ,
29
- activities,
30
- } ) ;
31
- }
34
+ getWorker : ( ) =>
35
+ Worker . create ( {
36
+ taskQueue,
37
+ workflowBundle : t . context . workflowBundle ,
38
+ activities,
39
+ } ) ,
40
+ } ;
41
+ } ) ;
32
42
33
43
if ( RUN_INTEGRATION_TESTS ) {
34
44
test ( 'Simple local activity works end to end' , async ( t ) => {
35
- const { client, taskQueue } = t . context ;
36
- const worker = await defaultWorker ( taskQueue ) ;
45
+ const { client, taskQueue, getWorker } = t . context ;
46
+ const worker = await getWorker ( ) ;
37
47
await worker . runUntil ( async ( ) => {
38
48
const res = await client . execute ( workflows . runOneLocalActivity , {
39
49
workflowId : uuid4 ( ) ,
@@ -44,9 +54,29 @@ if (RUN_INTEGRATION_TESTS) {
44
54
} ) ;
45
55
} ) ;
46
56
57
+ test ( 'isLocal is set correctly' , async ( t ) => {
58
+ const { client, taskQueue, getWorker } = t . context ;
59
+ const worker = await getWorker ( ) ;
60
+ await worker . runUntil ( async ( ) => {
61
+ const res1 = await client . execute ( workflows . getIsLocal , {
62
+ workflowId : uuid4 ( ) ,
63
+ taskQueue,
64
+ args : [ true ] ,
65
+ } ) ;
66
+ t . is ( res1 , true ) ;
67
+
68
+ const res2 = await client . execute ( workflows . getIsLocal , {
69
+ workflowId : uuid4 ( ) ,
70
+ taskQueue,
71
+ args : [ false ] ,
72
+ } ) ;
73
+ t . is ( res2 , false ) ;
74
+ } ) ;
75
+ } ) ;
76
+
47
77
test ( 'Parallel local activities work end to end' , async ( t ) => {
48
- const { client, taskQueue } = t . context ;
49
- const worker = await defaultWorker ( taskQueue ) ;
78
+ const { client, taskQueue, getWorker } = t . context ;
79
+ const worker = await getWorker ( ) ;
50
80
await worker . runUntil ( async ( ) => {
51
81
const args = [ 'hey' , 'ho' , 'lets' , 'go' ] ;
52
82
const handle = await client . start ( workflows . runParallelLocalActivities , {
@@ -70,8 +100,8 @@ if (RUN_INTEGRATION_TESTS) {
70
100
} ) ;
71
101
72
102
test ( 'Local activity error is propagated properly to the Workflow' , async ( t ) => {
73
- const { client, taskQueue } = t . context ;
74
- const worker = await defaultWorker ( taskQueue ) ;
103
+ const { client, taskQueue, getWorker } = t . context ;
104
+ const worker = await getWorker ( ) ;
75
105
await worker . runUntil ( async ( ) => {
76
106
const err : WorkflowFailedError = await t . throwsAsync (
77
107
client . execute ( workflows . throwAnErrorFromLocalActivity , {
@@ -86,8 +116,8 @@ if (RUN_INTEGRATION_TESTS) {
86
116
} ) ;
87
117
88
118
test ( 'Local activity cancellation is propagated properly to the Workflow' , async ( t ) => {
89
- const { client, taskQueue } = t . context ;
90
- const worker = await defaultWorker ( taskQueue ) ;
119
+ const { client, taskQueue, getWorker } = t . context ;
120
+ const worker = await getWorker ( ) ;
91
121
await worker . runUntil ( async ( ) => {
92
122
const err : WorkflowFailedError = await t . throwsAsync (
93
123
client . execute ( workflows . cancelALocalActivity , {
@@ -104,8 +134,8 @@ if (RUN_INTEGRATION_TESTS) {
104
134
} ) ;
105
135
106
136
test ( 'Failing local activity can be cancelled' , async ( t ) => {
107
- const { client, taskQueue } = t . context ;
108
- const worker = await defaultWorker ( taskQueue ) ;
137
+ const { client, taskQueue, getWorker } = t . context ;
138
+ const worker = await getWorker ( ) ;
109
139
await worker . runUntil ( async ( ) => {
110
140
const err : WorkflowFailedError = await t . throwsAsync (
111
141
client . execute ( workflows . cancelALocalActivity , {
@@ -122,8 +152,8 @@ if (RUN_INTEGRATION_TESTS) {
122
152
} ) ;
123
153
124
154
test ( 'Serial local activities (in the same task) work end to end' , async ( t ) => {
125
- const { client, taskQueue } = t . context ;
126
- const worker = await defaultWorker ( taskQueue ) ;
155
+ const { client, taskQueue, getWorker } = t . context ;
156
+ const worker = await getWorker ( ) ;
127
157
await worker . runUntil ( async ( ) => {
128
158
const handle = await client . start ( workflows . runSerialLocalActivities , {
129
159
workflowId : uuid4 ( ) ,
@@ -145,8 +175,8 @@ if (RUN_INTEGRATION_TESTS) {
145
175
} ) ;
146
176
147
177
test ( 'Local activity does not retry if error is in nonRetryableErrorTypes' , async ( t ) => {
148
- const { client, taskQueue } = t . context ;
149
- const worker = await defaultWorker ( taskQueue ) ;
178
+ const { client, taskQueue, getWorker } = t . context ;
179
+ const worker = await getWorker ( ) ;
150
180
await worker . runUntil ( async ( ) => {
151
181
const err : WorkflowFailedError = await t . throwsAsync (
152
182
client . execute ( workflows . throwAnExplicitNonRetryableErrorFromLocalActivity , {
@@ -259,8 +289,7 @@ if (RUN_INTEGRATION_TESTS) {
259
289
} ) ;
260
290
} ) ;
261
291
262
- // TODO: fix Core shutdown and reenable this test
263
- test . skip ( 'Worker shutdown while running a local activity completes after completion' , async ( t ) => {
292
+ test ( 'Worker shutdown while running a local activity completes after completion' , async ( t ) => {
264
293
const { client, taskQueue } = t . context ;
265
294
const subj = new Subject < void > ( ) ;
266
295
const worker = await Worker . create ( {
@@ -300,8 +329,8 @@ if (RUN_INTEGRATION_TESTS) {
300
329
} ) ;
301
330
302
331
test ( 'Local activity fails if not registered on Worker' , async ( t ) => {
303
- const { client, taskQueue } = t . context ;
304
- const worker = await defaultWorker ( taskQueue ) ;
332
+ const { client, taskQueue, getWorker } = t . context ;
333
+ const worker = await getWorker ( ) ;
305
334
await worker . runUntil ( async ( ) => {
306
335
const err : WorkflowFailedError = await t . throwsAsync (
307
336
client . execute ( workflows . runANonExisitingLocalActivity , {
0 commit comments