MCPcopy Index your code
hub / github.com/coder/coder / tGoContext

Function tGoContext

cli/ssh_test.go:2458–2473  ·  view source on GitHub ↗

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))

Source from the content-addressed store, hash-verified

2456//
2457// NOTE(mafredri): This could be moved to a helper library.
2458func 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

Callers 2

TestSSHFunction · 0.85
TestSSH_CoderConnectFunction · 0.85

Calls 2

HelperMethod · 0.65
CleanupMethod · 0.65

Tested by

no test coverage detected