tGoContext runs fn in a goroutine passing a context that will be canceled on test completion and wait until fn has finished executing. Done and cancel are returned for optionally waiting until completion or early cancellation. NOTE(mafredri): This could be moved to a helper library.
(t *testing.T, fn func(context.Context))
| 2456 | // |
| 2457 | // NOTE(mafredri): This could be moved to a helper library. |
| 2458 | func tGoContext(t *testing.T, fn func(context.Context)) (done <-chan struct{}, cancel context.CancelFunc) { |
| 2459 | t.Helper() |
| 2460 | |
| 2461 | ctx, cancel := context.WithCancel(context.Background()) |
| 2462 | doneC := make(chan struct{}) |
| 2463 | t.Cleanup(func() { |
| 2464 | cancel() |
| 2465 | <-done |
| 2466 | }) |
| 2467 | go func() { |
| 2468 | fn(ctx) |
| 2469 | close(doneC) |
| 2470 | }() |
| 2471 | |
| 2472 | return doneC, cancel |
| 2473 | } |
| 2474 | |
| 2475 | // tGo runs fn in a goroutine and waits until fn has completed before |
| 2476 | // test completion. Done is returned for optionally waiting for fn to |
no test coverage detected