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

Function TestWorkFunc

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

Source from the content-addressed store, hash-verified

115}
116
117func TestWorkFunc(t *testing.T) {
118 t.Parallel()
119
120 ctx := context.Background()
121
122 type testBundle struct{}
123
124 setup := func(t *testing.T) (*Client[pgx.Tx], *testBundle) {
125 t.Helper()
126
127 var (
128 dbPool = riversharedtest.DBPool(ctx, t)
129 driver = riverpgxv5.New(dbPool)
130 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
131 config = newTestConfig(t, schema)
132 client = newTestClient(t, dbPool, config)
133 )
134
135 startClient(ctx, t, client)
136
137 return client, &testBundle{}
138 }
139
140 t.Run("RoundTrip", func(t *testing.T) {
141 t.Parallel()
142
143 client, _ := setup(t)
144
145 workChan := make(chan struct{})
146 AddWorker(client.config.Workers, WorkFunc(func(ctx context.Context, job *Job[WorkFuncArgs]) error {
147 workChan <- struct{}{}
148 return nil
149 }))
150
151 _, err := client.Insert(ctx, &WorkFuncArgs{}, nil)
152 require.NoError(t, err)
153
154 riversharedtest.WaitOrTimeout(t, workChan)
155 })
156
157 t.Run("StructFunction", func(t *testing.T) {
158 t.Parallel()
159
160 client, _ := setup(t)
161
162 structWithFunc := &StructWithFunc{
163 WorkChan: make(chan struct{}),
164 }
165
166 AddWorker(client.config.Workers, WorkFunc(structWithFunc.Work))
167
168 _, err := client.Insert(ctx, &WorkFuncArgs{}, nil)
169 require.NoError(t, err)
170
171 riversharedtest.WaitOrTimeout(t, structWithFunc.WorkChan)
172 })
173
174 t.Run("JobArgsReflectKind", func(t *testing.T) {

Callers

nothing calls this directly

Calls 12

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
WaitOrTimeoutFunction · 0.92
newTestClientFunction · 0.85
AddWorkerFunction · 0.85
WorkFuncFunction · 0.85
InsertMethod · 0.80
newTestConfigFunction · 0.70
startClientFunction · 0.70
HelperMethod · 0.65
RunMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…