MCPcopy
hub / github.com/riverqueue/river / TestWork

Function TestWork

worker_test.go:16–58  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

14)
15
16func TestWork(t *testing.T) {
17 t.Parallel()
18
19 workers := NewWorkers()
20
21 AddWorker(workers, &noOpWorker{})
22 require.Contains(t, workers.workersMap, (noOpArgs{}).Kind())
23
24 require.PanicsWithError(t, `worker for kind "noOp" is already registered`, func() {
25 AddWorker(workers, &noOpWorker{})
26 })
27
28 type JobArgs struct {
29 testutil.JobArgsReflectKind[JobArgs]
30 }
31
32 AddWorker(workers, WorkFunc(func(ctx context.Context, job *Job[JobArgs]) error {
33 return nil
34 }))
35 require.Contains(t, workers.workersMap, (JobArgs{}).Kind())
36
37 AddWorker(workers, WorkFunc(func(ctx context.Context, job *Job[withKindAliasesArgs]) error {
38 return nil
39 }))
40 require.Contains(t, workers.workersMap, (withKindAliasesArgs{}).Kind())
41 require.Contains(t, workers.workersMap, (withKindAliasesArgs{}).KindAliases()[0])
42
43 require.PanicsWithError(t, `worker for kind "with_kind_alternate_alternate" is already registered`, func() {
44 AddWorker(workers, WorkFunc(func(ctx context.Context, job *Job[withKindAliasesCollisionArgs]) error {
45 return nil
46 }))
47 })
48
49 type OtherJobArgs struct {
50 testutil.JobArgsReflectKind[OtherJobArgs]
51 }
52
53 var jobArgs OtherJobArgs
54 AddWorkerArgs(workers, jobArgs, WorkFunc(func(ctx context.Context, job *Job[OtherJobArgs]) error {
55 return nil
56 }))
57 require.Contains(t, workers.workersMap, (OtherJobArgs{}).Kind())
58}
59
60type configurableArgs struct {
61 uniqueOpts UniqueOpts

Callers

nothing calls this directly

Calls 6

NewWorkersFunction · 0.85
AddWorkerFunction · 0.85
WorkFuncFunction · 0.85
AddWorkerArgsFunction · 0.85
KindMethod · 0.65
KindAliasesMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…