rivertest.Worker fixes: handle nil config, rename Kind/EventKind, log panic trace#775
rivertest.Worker fixes: handle nil config, rename Kind/EventKind, log panic trace#775
Conversation
Yeah, honestly I didn't see this part on my review, but IMO the panic shouldn't be swallowed. Might even be best not to have any error/panic handlers and just let users do what they want with those values. |
| } | ||
| } | ||
|
|
||
| t.Run("HandlesANilRiverConfig", func(t *testing.T) { |
There was a problem hiding this comment.
Nit, but found the casing a bit awkward to read. Really doesn't need the "A" anyway:
| t.Run("HandlesANilRiverConfig", func(t *testing.T) { | |
| t.Run("HandlesNilRiverConfig", func(t *testing.T) { |
7947a62 to
2be891e
Compare
An error handler is necessary in order to capture and return the error via the test helper—otherwise it'd be lost and only recorded in the DB. I've restructured this so there's a |
If a panic occurs, return a `PanicError` struct containing the trace and panic cause. Do not use `tb.Fatalf` from within execution except for unexpected internal issues—instead propagate errors to the user. Also change the return type to `*WorkResult` since it may be optional when an internal error occurs.
2be891e to
21a24d2
Compare
I wrote some tests for the demo app using the test worker (#766) and found a few issues:
nil*river.Config. I fixed this by makingConfig.WithDefaultshandle a nil pointer so no change was necessary in therivertest.NewWorkercaller.Kindfield inrivertest.WorkResultfelt unnatural as I was writing assertions for it likerequire.Equal(t, river.EventKindJobCompleted, result.Kind). I renamed this toEventKindwhich I still don't love but it feels at least a little more appropriate to me.Side note on (3) above: I realized I couldn't actually use
rivertest.Workerto write a test for a worker that intentionally panics, because its panic handler callstb.Fatal. This is probably not a very likely issue for real users, and it's probably a good default behavior, but I won't be surprised if we feel compelled to add an option to the test worker type so that it avoid calling fatal and instead surface an error or calltb.Error. Wanted to run it by you in case you had other thoughts on this. For example, we could just switch it totb.ErrorbecauseFatalis quite presumptive?