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

Function Test_Client_Stop_ContextImmediatelyCancelled

client_test.go:2343–2387  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2341}
2342
2343func Test_Client_Stop_ContextImmediatelyCancelled(t *testing.T) {
2344 t.Parallel()
2345
2346 ctx := context.Background()
2347
2348 ctx, cancel := context.WithCancel(ctx)
2349 defer cancel()
2350
2351 var (
2352 dbPool = riversharedtest.DBPool(ctx, t)
2353 driver = riverpgxv5.New(dbPool)
2354 schema = riverdbtest.TestSchema(ctx, t, driver, nil)
2355 config = newTestConfig(t, schema)
2356 )
2357 config.Schema = schema
2358
2359 type JobArgs struct {
2360 testutil.JobArgsReflectKind[JobArgs]
2361 }
2362
2363 // doneCh will never close, job will exit due to context cancellation:
2364 var (
2365 doneCh = make(chan struct{})
2366 startedCh = make(chan int64)
2367 )
2368 AddWorker(config.Workers, makeAwaitWorker[JobArgs](startedCh, doneCh))
2369
2370 client := newTestClient(t, dbPool, config)
2371
2372 // Doesn't use newTestClient because it turns out that the test will fail on
2373 // waiting for stop to timeout if a non-background context is used. I added
2374 // the test below (Test_Client_Stop_AfterContextCancelled, currently
2375 // skipped) to reproduce the problem and which we should fix.
2376 require.NoError(t, client.Start(ctx))
2377 t.Cleanup(func() { require.NoError(t, client.Stop(context.Background())) })
2378
2379 insertRes, err := client.Insert(ctx, JobArgs{}, nil)
2380 require.NoError(t, err)
2381 startedJobID := riversharedtest.WaitOrTimeout(t, startedCh)
2382 require.Equal(t, insertRes.Job.ID, startedJobID)
2383
2384 cancel()
2385
2386 require.ErrorIs(t, client.Stop(ctx), context.Canceled)
2387}
2388
2389// Added this failing test case as skipped while working on another project,
2390// detecting a problem that the test case above was glossing over, but finding

Callers

nothing calls this directly

Calls 11

DBPoolFunction · 0.92
NewFunction · 0.92
TestSchemaFunction · 0.92
WaitOrTimeoutFunction · 0.92
AddWorkerFunction · 0.85
newTestClientFunction · 0.85
CleanupMethod · 0.80
InsertMethod · 0.80
newTestConfigFunction · 0.70
StartMethod · 0.65
StopMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…