(t *testing.T)
| 2341 | } |
| 2342 | |
| 2343 | func 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 |
nothing calls this directly
no test coverage detected
searching dependent graphs…