@@ -28,9 +28,10 @@ func TriggerCallbackOn[Type any, Status StatusType, Payload any](
2828 panic ("*workflow.Workflow required for testing utility functions" )
2929 }
3030
31- _ = waitFor (t , w , foreignID , func (r * Record ) (bool , error ) {
31+ _ , err : = waitFor (t , w , foreignID , func (r * Record ) (bool , error ) {
3232 return r .Status == int (waitForStatus ), nil
3333 })
34+ require .NoError (t , err )
3435
3536 b , err := json .Marshal (p )
3637 require .NoError (t , err )
@@ -109,12 +110,13 @@ func Require[Type any, Status StatusType](
109110 return
110111 }
111112
112- wr := waitFor (t , w , foreignID , func (r * Record ) (bool , error ) {
113+ wr , err := waitFor (t , w , foreignID , func (r * Record ) (bool , error ) {
113114 return r .Status == int (waitForStatus ), nil
114115 })
116+ require .NoError (t , err )
115117
116118 var actual Type
117- err : = Unmarshal (wr .Object , & actual )
119+ err = Unmarshal (wr .Object , & actual )
118120 require .NoError (t , err )
119121
120122 // Due to nuances in encoding libraries such as json with the ability to implement custom
@@ -147,27 +149,28 @@ func WaitFor[Type any, Status StatusType](
147149 panic ("*workflow.Workflow required for testing utility functions" )
148150 }
149151
150- waitFor (t , w , foreignID , func (r * Record ) (bool , error ) {
152+ _ , err := waitFor (t , w , foreignID , func (r * Record ) (bool , error ) {
151153 run , err := buildRun [Type , Status ](w .recordStore .Store , r )
152154 require .NoError (t , err )
153155
154156 return fn (run )
155157 })
158+ require .NoError (t , err )
156159}
157160
158161func waitFor [Type any , Status StatusType ](
159162 t testing.TB ,
160163 w * Workflow [Type , Status ],
161164 foreignID string ,
162165 fn func (r * Record ) (bool , error ),
163- ) * Record {
166+ ) ( * Record , error ) {
164167 testingStore , ok := w .recordStore .(TestingRecordStore )
165168 if ! ok {
166169 panic ("TestingRecordStore implementation for record store dependency required" )
167170 }
168171
169172 var runID string
170- for runID == "" {
173+ for runID == "" && w . ctx . Err () == nil {
171174 latest , err := w .recordStore .Latest (context .Background (), w .Name (), foreignID )
172175 if errors .Is (err , ErrRecordNotFound ) {
173176 continue
@@ -182,7 +185,7 @@ func waitFor[Type any, Status StatusType](
182185 // testingStore.SetSnapshotOffset(w.name, foreignID, runID, 0)
183186
184187 var wr Record
185- for wr .RunID == "" {
188+ for wr .RunID == "" && w . ctx . Err () == nil {
186189 snapshots := testingStore .Snapshots (w .Name (), foreignID , runID )
187190 for _ , r := range snapshots {
188191 ok , err := fn (r )
@@ -194,7 +197,7 @@ func waitFor[Type any, Status StatusType](
194197 }
195198 }
196199
197- return & wr
200+ return & wr , w . ctx . Err ()
198201}
199202
200203// NewTestingRun should be used when testing logic that defines a workflow.Run as a parameter. This is usually the
@@ -255,10 +258,11 @@ func WithDeleteDataFn(deleteData func(ctx context.Context) error) TestingRunOpti
255258}
256259
257260type testingRunStateController struct {
258- pause func (ctx context.Context ) error
259- cancel func (ctx context.Context ) error
260- resume func (ctx context.Context ) error
261- deleteData func (ctx context.Context ) error
261+ pause func (ctx context.Context ) error
262+ cancel func (ctx context.Context ) error
263+ resume func (ctx context.Context ) error
264+ deleteData func (ctx context.Context ) error
265+ saveAndRepeat func (ctx context.Context ) error
262266}
263267
264268func (c * testingRunStateController ) Pause (ctx context.Context , reason string ) error {
@@ -293,4 +297,12 @@ func (c *testingRunStateController) DeleteData(ctx context.Context, reason strin
293297 return c .deleteData (ctx )
294298}
295299
300+ func (c * testingRunStateController ) SaveAndRepeat (ctx context.Context ) error {
301+ if c .saveAndRepeat == nil {
302+ return nil
303+ }
304+
305+ return c .saveAndRepeat (ctx )
306+ }
307+
296308var _ RunStateController = (* testingRunStateController )(nil )
0 commit comments