Drop callback args in favor of single, uniform test convention#856
Conversation
| nil, | ||
| ) | ||
|
|
||
| return newPeriodicJobBundle(newTestConfig(t, nil), periodicJobEnqueuer), &testBundle{} |
There was a problem hiding this comment.
Made schema the second argument to newTestConfig instead, but honestly could see it with or without. It does save one LOC for test case where schemas are used (which is a lot of them), but it tends to be empty for test cases using the runNewTestClient helper, which injects its own schema.
| ) | ||
|
|
||
| var ( |
There was a problem hiding this comment.
I'm seeing a few cases where you have two consecutive var blocks—what's the strategy there? It's more verbose so I'm wanting to understand when this would be beneficial for readability or grouping.
There was a problem hiding this comment.
Ah yeah, I think I was just thinking that since dbPool / driver / schema / config are commonly found in a single group, it might make sense for the other two vars to get their own.
I don't feel strongly about it though. I just changed it back to a single var block.
d8e15ce to
d6caf1f
Compare
This one's largely a cosmetic change. We remove callback args/worker in
favor of using test case local args using `JobArgsReflectKind` and a
standard invocation to `AddWorker`:
type JobArgs struct {
JobArgsReflectKind[JobArgs]
}
AddWorker(config.Workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
return JobCancel(errors.New("oops"))
}))
It's a little more verbose, but has the advantage of using only normal
River primitives, meaning that one has to be familiar with fewer test
helpers to understand what's going on.
Besides that and convention, another small benefit is that it introduces
a little more type safety and makes job args impossible to accidentally
cross reference between test cases. Previously, a test could insert a
callback args while intending to use a callback for them registered in a
different test case. With the new approach, it's very obvious when
`JobArgs` is either forgotten (a compilation error), or when there's a
missing `AddWorker` (because that's supposed to live close to the
definition of `JobArgs`).
d6caf1f to
f5db3fb
Compare
|
Thanks! |
This one's largely a cosmetic change. We remove callback args/worker in
favor of using test case local args using
JobArgsReflectKindand astandard invocation to
AddWorker:It's a little more verbose, but has the advantage of using only normal
River primitives, meaning that one has to be familiar with fewer test
helpers to understand what's going on.
Besides that and convention, another small benefit is that it introduces
a little more type safety and makes job args impossible to accidentally
cross reference between test cases. Previously, a test could insert a
callback args while intending to use a callback for them registered in a
different test case. With the new approach, it's very obvious when
JobArgsis either forgotten (a compilation error), or when there's amissing
AddWorker(because that's supposed to live close to thedefinition of
JobArgs).