Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

testfactory: automatically set FinalizedAt if finalized state #585

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions internal/riverinternaltest/riverdrivertest/riverdrivertest.go
Original file line number Diff line number Diff line change
Expand Up @@ -1091,9 +1091,11 @@ func Exercise[TTx any](ctx context.Context, t *testing.T,
exec, _ := setup(ctx, t)
// Create a job with the target state but without a finalized_at,
// expect an error:
_, err := exec.JobInsertFull(ctx, testfactory.Job_Build(t, &testfactory.JobOpts{
params := testfactory.Job_Build(t, &testfactory.JobOpts{
State: &state,
}))
})
params.FinalizedAt = nil
_, err := exec.JobInsertFull(ctx, params)
require.ErrorContains(t, err, "violates check constraint \"finalized_or_finalized_at_null\"")
})

Expand Down
9 changes: 8 additions & 1 deletion internal/riverinternaltest/testfactory/test_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ func Job_Build(tb testing.TB, opts *JobOpts) *riverdriver.JobInsertFullParams {
encodedArgs = []byte("{}")
}

finalizedAt := opts.FinalizedAt
if finalizedAt == nil && (opts.State != nil && (*opts.State == rivertype.JobStateCompleted ||
*opts.State == rivertype.JobStateCancelled ||
*opts.State == rivertype.JobStateDiscarded)) {
finalizedAt = ptrutil.Ptr(time.Now())
}

metadata := opts.Metadata
if opts.Metadata == nil {
metadata = []byte("{}")
Expand All @@ -68,7 +75,7 @@ func Job_Build(tb testing.TB, opts *JobOpts) *riverdriver.JobInsertFullParams {
CreatedAt: opts.CreatedAt,
EncodedArgs: encodedArgs,
Errors: opts.Errors,
FinalizedAt: opts.FinalizedAt,
FinalizedAt: finalizedAt,
Kind: ptrutil.ValOrDefault(opts.Kind, "fake_job"),
MaxAttempts: ptrutil.ValOrDefault(opts.MaxAttempts, rivercommon.MaxAttemptsDefault),
Metadata: metadata,
Expand Down
2 changes: 1 addition & 1 deletion riverdriver/river_driver_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,9 @@ type Notification struct {
}

type JobCancelParams struct {
ID int64
CancelAttemptedAt time.Time
ControlTopic string
ID int64
}

type JobDeleteBeforeParams struct {
Expand Down
Loading