MCPcopy Index your code
hub / github.com/riverqueue/river / ExerciseClient

Function ExerciseClient

riverdriver/riverdrivertest/driver_client_test.go:202–768  ·  view source on GitHub ↗

ExerciseClient exercises a client using a generic driver using a minimal set of test cases to verify that the driver works end to end.

(ctx context.Context, t *testing.T,
	driverWithSchema func(ctx context.Context, t *testing.T) (riverdriver.Driver[TTx], string),
)

Source from the content-addressed store, hash-verified

200// ExerciseClient exercises a client using a generic driver using a minimal set
201// of test cases to verify that the driver works end to end.
202func ExerciseClient[TTx any](ctx context.Context, t *testing.T,
203 driverWithSchema func(ctx context.Context, t *testing.T) (riverdriver.Driver[TTx], string),
204) {
205 t.Helper()
206
207 type testBundle struct {
208 config *river.Config
209 driver riverdriver.Driver[TTx]
210 exec riverdriver.Executor
211 schema string
212 }
213
214 // Alternate setup returning only client Config rather than a full Client.
215 setupConfig := func(t *testing.T) (*river.Config, *testBundle) {
216 t.Helper()
217
218 var (
219 driver, schema = driverWithSchema(ctx, t)
220 config = newTestConfig(t, schema)
221 )
222
223 return config, &testBundle{
224 config: config,
225 driver: driver,
226 exec: driver.GetExecutor(),
227 schema: schema,
228 }
229 }
230
231 setup := func(t *testing.T) (*river.Client[TTx], *testBundle) {
232 t.Helper()
233
234 config, bundle := setupConfig(t)
235
236 client, err := river.NewClient(bundle.driver, config)
237 require.NoError(t, err)
238
239 return client, bundle
240 }
241
242 beginTx := func(ctx context.Context, t *testing.T, bundle *testBundle) (TTx, riverdriver.ExecutorTx) {
243 t.Helper()
244
245 execTx, err := bundle.driver.GetExecutor().Begin(ctx)
246 require.NoError(t, err)
247
248 // Ignore error on cleanup so we can roll back early in tests where desirable.
249 t.Cleanup(func() { _ = execTx.Rollback(ctx) })
250
251 return bundle.driver.UnwrapTx(execTx), execTx
252 }
253
254 t.Run("StartInsertAndWork", func(t *testing.T) {
255 t.Parallel()
256
257 client, bundle := setup(t)
258
259 type JobArgs struct {

Calls 15

WhereMethod · 0.95
NewClientFunction · 0.92
AddWorkerFunction · 0.92
WorkFuncFunction · 0.92
WaitOrTimeoutFunction · 0.92
JobFunction · 0.92
NewJobDeleteManyParamsFunction · 0.92
NewJobListParamsFunction · 0.92
QueueFunction · 0.92
NewQueueListParamsFunction · 0.92
CleanupMethod · 0.80
InsertMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…