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

Add missing integration-level job snooze test #31

Merged
merged 1 commit into from
Nov 17, 2023
Merged

Conversation

brandur
Copy link
Contributor

@brandur brandur commented Nov 15, 2023

I noticed while trying to refactor something the other day that I had a
problem around snoozing, but only the example snooze test was failing.
Looking into it further, it turned out that it was because the snooze
example was the only snooze test we had.

Example tests aren't great because they do obnoxious things like swallow
all output (making it harder to debug), but they also don't support some
feature like -count, making it harder to debug intermittent problems.

Here, add another client test for snooze. We use the new client test
line that makes use of JobArgsReflectKind and WorkFunc, keeping the
implementation clean and all local to the specific test case that needs
it.

And since snooze and cancel are quite similar, I added a test case for
cancel as well. Cancel did have another test elsewhere, but I figure I
might as well add one in this new line too to line up with the snooze
test case. It should be a pretty fast test, so doesn't hurt to have a
duplicate.

@brandur brandur requested a review from bgentry November 15, 2023 03:22
Copy link
Contributor

@bgentry bgentry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, sorry I missed this coverage but thank you for adding it.

Comment on lines +226 to +229
AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
return JobCancel(fmt.Errorf("a persisted internal error"))
}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check the job in the database after this is all done for completeness? i.e. make sure it is cancelled and the error is saved

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure! Added.

Comment on lines +250 to +258
AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
return JobSnooze(15 * time.Minute)
}))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likewise, should we check anything about the job in the DB after this executes? Since this is an integration test it might be a good safety check.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

I noticed while trying to refactor something the other day that I had a
problem around snoozing, but only the example snooze test was failing.
Looking into it further, it turned out that it was because the snooze
example was the only snooze test we had.

Example tests aren't great because they do obnoxious things like swallow
all output (making it harder to debug), but they also don't support some
feature like `-count`, making it harder to debug intermittent problems.

Here, add another client test for snooze. We use the new client test
line that makes use of `JobArgsReflectKind` and `WorkFunc`, keeping the
implementation clean and all local to the specific test case that needs
it.

And since snooze and cancel are quite similar, I added a test case for
cancel as well. Cancel did have another test elsewhere, but I figure I
might as well add one in this new line too to line up with the snooze
test case. It should be a pretty fast test, so doesn't hurt to have a
duplicate.
@brandur brandur force-pushed the brandur-snooze-test branch from 7f94356 to ce5f5da Compare November 17, 2023 02:10
@brandur brandur merged commit 9b0edd0 into master Nov 17, 2023
5 checks passed
@brandur brandur deleted the brandur-snooze-test branch November 17, 2023 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants