(t *testing.T)
| 164 | } |
| 165 | |
| 166 | func TestResumableStepCursor(t *testing.T) { |
| 167 | t.Parallel() |
| 168 | |
| 169 | type resumableCursor struct { |
| 170 | ID int `json:"id"` |
| 171 | } |
| 172 | |
| 173 | setup := func(t *testing.T, metadata string) (context.Context, map[string]any, *rivertype.JobRow) { |
| 174 | t.Helper() |
| 175 | |
| 176 | metadataUpdates := make(map[string]any) |
| 177 | ctx := context.WithValue(context.Background(), jobexecutor.ContextKeyMetadataUpdates, metadataUpdates) |
| 178 | |
| 179 | return ctx, metadataUpdates, &rivertype.JobRow{Metadata: []byte(metadata)} |
| 180 | } |
| 181 | |
| 182 | t.Run("DuplicateStepNameSharedWithCursorStep", func(t *testing.T) { |
| 183 | t.Parallel() |
| 184 | |
| 185 | ctx, _, job := setup(t, `{}`) |
| 186 | |
| 187 | var ran []string |
| 188 | err := (&rivermiddleware.ResumableMiddleware{}).Work(ctx, job, func(ctx context.Context) error { |
| 189 | ResumableStep(ctx, "step1", nil, func(ctx context.Context) error { |
| 190 | ran = append(ran, "step") |
| 191 | return nil |
| 192 | }) |
| 193 | ResumableStepCursor(ctx, "step1", nil, func(ctx context.Context, cursor resumableCursor) error { |
| 194 | ran = append(ran, "cursor") |
| 195 | return nil |
| 196 | }) |
| 197 | |
| 198 | return nil |
| 199 | }) |
| 200 | require.EqualError(t, err, `river: duplicate resumable step name "step1"`) |
| 201 | require.Equal(t, []string{"step"}, ran) |
| 202 | }) |
| 203 | |
| 204 | t.Run("ResumesCursor", func(t *testing.T) { |
| 205 | t.Parallel() |
| 206 | |
| 207 | ctx, metadataUpdates, job := setup(t, `{}`) |
| 208 | |
| 209 | var ( |
| 210 | cursorResult resumableCursor |
| 211 | ran []int |
| 212 | ) |
| 213 | err := (&rivermiddleware.ResumableMiddleware{}).Work(ctx, job, func(ctx context.Context) error { |
| 214 | ResumableStep(ctx, "step1", nil, func(ctx context.Context) error { |
| 215 | ran = append(ran, 1) |
| 216 | return nil |
| 217 | }) |
| 218 | ResumableStepCursor(ctx, "step2", nil, func(ctx context.Context, cursor resumableCursor) error { |
| 219 | cursorResult = cursor |
| 220 | ran = append(ran, 2) |
| 221 | require.NoError(t, ResumableSetCursor(ctx, resumableCursor{ID: 42})) |
| 222 | return errors.New("step2 failed") |
| 223 | }) |
nothing calls this directly
no test coverage detected
searching dependent graphs…