37 lines
1.4 KiB
Go
37 lines
1.4 KiB
Go
package jobs
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/riverqueue/river"
|
|
)
|
|
|
|
// Two properties of the queue that are one line each to write and expensive to get wrong, because
|
|
// both fail SILENTLY: a renamed kind orphans every job already in the table (River dispatches by
|
|
// that string, and a job whose kind no worker claims simply waits forever), and a MaxAttempts above
|
|
// one turns "start a run" into "start it again" — the reflex this zone deliberately refuses, since
|
|
// a retry here spawns a SECOND engine rather than finishing lost work.
|
|
func TestTheQueuesKindsAndRetryPolicyAreWhatTheRestOfTheSystemAssumes(t *testing.T) {
|
|
cases := []struct {
|
|
name string
|
|
kind string
|
|
opts river.InsertOpts
|
|
}{
|
|
{"spawn", SpawnArgs{}.Kind(), SpawnArgs{}.InsertOpts()},
|
|
{"parse", ParseArgs{}.Kind(), ParseArgs{}.InsertOpts()},
|
|
}
|
|
want := map[string]string{"spawn": "tm_spawn_run", "parse": "tm_parse_book"}
|
|
for _, tc := range cases {
|
|
if tc.kind != want[tc.name] {
|
|
t.Errorf("%s kind is %q, want %q — a renamed kind orphans the jobs already queued under the old one",
|
|
tc.name, tc.kind, want[tc.name])
|
|
}
|
|
if tc.opts.MaxAttempts != 1 {
|
|
t.Errorf("%s MaxAttempts is %d, want 1: recovery is the reconciler's job, not the queue's",
|
|
tc.name, tc.opts.MaxAttempts)
|
|
}
|
|
if tc.opts.Queue != river.QueueDefault {
|
|
t.Errorf("%s queue is %q, want the default one the client works", tc.name, tc.opts.Queue)
|
|
}
|
|
}
|
|
}
|