@@ -4,13 +4,21 @@ import * as fs from 'fs';
4
4
import path from 'path' ;
5
5
import anyTest , { TestFn } from 'ava' ;
6
6
import { temporal } from '@temporalio/proto' ;
7
- import { DefaultLogger , ReplayError , Runtime } from '@temporalio/worker' ;
7
+ import { bundleWorkflowCode , ReplayError , WorkflowBundle } from '@temporalio/worker' ;
8
8
import { DeterminismViolationError } from '@temporalio/workflow' ;
9
9
import { Worker } from './helpers' ;
10
10
import History = temporal . api . history . v1 . History ;
11
11
12
+ async function gen2array < T > ( gen : AsyncIterable < T > ) : Promise < T [ ] > {
13
+ const out : T [ ] = [ ] ;
14
+ for await ( const x of gen ) {
15
+ out . push ( x ) ;
16
+ }
17
+ return out ;
18
+ }
19
+
12
20
export interface Context {
13
- runtime : Runtime ;
21
+ bundle : WorkflowBundle ;
14
22
}
15
23
16
24
async function getHistories ( fname : string ) : Promise < History > {
@@ -38,18 +46,18 @@ const test = anyTest as TestFn<Context>;
38
46
test . before ( async ( t ) => {
39
47
// We don't want AVA to whine about unhandled rejections thrown by workflows
40
48
process . removeAllListeners ( 'unhandledRejection' ) ;
41
- const logger = new DefaultLogger ( 'DEBUG' ) ;
42
- const runtime = Runtime . install ( { logger } ) ;
49
+ const bundle = await bundleWorkflowCode ( { workflowsPath : require . resolve ( './workflows' ) } ) ;
50
+
43
51
t . context = {
44
- runtime ,
52
+ bundle ,
45
53
} ;
46
54
} ) ;
47
55
48
56
test ( 'cancel-fake-progress-replay' , async ( t ) => {
49
57
const hist = await getHistories ( 'cancel_fake_progress_history.bin' ) ;
50
58
await Worker . runReplayHistory (
51
59
{
52
- workflowsPath : require . resolve ( './workflows' ) ,
60
+ workflowBundle : t . context . bundle ,
53
61
} ,
54
62
hist
55
63
) ;
@@ -60,7 +68,7 @@ test('cancel-fake-progress-replay from JSON', async (t) => {
60
68
const hist = await getHistories ( 'cancel_fake_progress_history.json' ) ;
61
69
await Worker . runReplayHistory (
62
70
{
63
- workflowsPath : require . resolve ( './workflows' ) ,
71
+ workflowBundle : t . context . bundle ,
64
72
} ,
65
73
hist
66
74
) ;
@@ -75,8 +83,7 @@ test('cancel-fake-progress-replay-nondeterministic', async (t) => {
75
83
await t . throwsAsync (
76
84
Worker . runReplayHistory (
77
85
{
78
- workflowsPath : require . resolve ( './workflows' ) ,
79
- failFast : false , // Verify this flag is ignored for single replay
86
+ workflowBundle : t . context . bundle ,
80
87
} ,
81
88
hist
82
89
) ,
@@ -91,67 +98,69 @@ test('workflow-task-failure-fails-replay', async (t) => {
91
98
// Manually alter the workflow type to point to our workflow which will fail workflow tasks
92
99
hist . events [ 0 ] . workflowExecutionStartedEventAttributes ! . workflowType ! . name = 'failsWorkflowTask' ;
93
100
94
- const err : ReplayError | undefined = await t . throwsAsync (
101
+ await t . throwsAsync (
95
102
Worker . runReplayHistory (
96
103
{
97
- workflowsPath : require . resolve ( './workflows' ) ,
104
+ workflowBundle : t . context . bundle ,
98
105
replayName : t . title ,
99
106
} ,
100
107
hist
101
108
) ,
102
109
{ instanceOf : ReplayError }
103
110
) ;
104
- t . false ( err ?. isNonDeterminism ) ;
105
111
} ) ;
106
112
107
113
test ( 'multiple-histories-replay' , async ( t ) => {
108
114
const hist1 = await getHistories ( 'cancel_fake_progress_history.bin' ) ;
109
115
const hist2 = await getHistories ( 'cancel_fake_progress_history.json' ) ;
110
116
const histories = historator ( [ hist1 , hist2 ] ) ;
111
117
112
- const res = await Worker . runReplayHistories (
113
- {
114
- workflowsPath : require . resolve ( './workflows' ) ,
115
- replayName : t . title ,
116
- } ,
117
- histories
118
+ const res = await gen2array (
119
+ Worker . runReplayHistories (
120
+ {
121
+ workflowBundle : t . context . bundle ,
122
+ replayName : t . title ,
123
+ } ,
124
+ histories
125
+ )
126
+ ) ;
127
+ t . deepEqual (
128
+ res . map ( ( { error } ) => error ) ,
129
+ [ undefined , undefined ]
118
130
) ;
119
- t . is ( res . errors . length , 0 ) ;
120
131
} ) ;
121
132
122
- test ( 'multiple-histories-replay-fails-fast ' , async ( t ) => {
133
+ test ( 'multiple-histories-replay-returns-errors ' , async ( t ) => {
123
134
const hist1 = await getHistories ( 'cancel_fake_progress_history.bin' ) ;
124
135
const hist2 = await getHistories ( 'cancel_fake_progress_history.json' ) ;
125
136
// change workflow type to break determinism
126
137
hist1 . events [ 0 ] . workflowExecutionStartedEventAttributes ! . workflowType ! . name = 'http' ;
127
138
hist2 . events [ 0 ] . workflowExecutionStartedEventAttributes ! . workflowType ! . name = 'http' ;
128
139
const histories = historator ( [ hist1 , hist2 ] ) ;
129
140
130
- await t . throwsAsync (
141
+ const results = await gen2array (
131
142
Worker . runReplayHistories (
132
143
{
133
- workflowsPath : require . resolve ( './workflows' ) ,
144
+ workflowBundle : t . context . bundle ,
134
145
replayName : t . title ,
135
146
} ,
136
147
histories
137
148
)
138
149
) ;
150
+
151
+ t . is ( results . filter ( ( { error } ) => error instanceof DeterminismViolationError ) . length , 2 ) ;
139
152
} ) ;
140
153
141
- test ( 'multiple-histories-replay-fails-slow' , async ( t ) => {
142
- const hist1 = await getHistories ( 'cancel_fake_progress_history.bin' ) ;
143
- const hist2 = await getHistories ( 'cancel_fake_progress_history.json' ) ;
144
- // change workflow type to break determinism
145
- hist1 . events [ 0 ] . workflowExecutionStartedEventAttributes ! . workflowType ! . name = 'http' ;
146
- const histories = historator ( [ hist1 , hist2 ] ) ;
154
+ test ( 'empty-histories-replay-returns-empty-result' , async ( t ) => {
155
+ const histories = historator ( [ ] ) ;
147
156
148
- const res = await Worker . runReplayHistories (
149
- {
150
- workflowsPath : require . resolve ( './workflows' ) ,
151
- replayName : t . title ,
152
- failFast : false ,
153
- } ,
154
- histories
157
+ const res = await gen2array (
158
+ Worker . runReplayHistories (
159
+ {
160
+ workflowBundle : t . context . bundle ,
161
+ } ,
162
+ histories
163
+ )
155
164
) ;
156
- t . is ( res . errors . length , 1 ) ;
165
+ t . is ( res . length , 0 ) ;
157
166
} ) ;
0 commit comments