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

Function WaitOrTimeout

rivershared/riversharedtest/riversharedtest.go:277–290  ·  view source on GitHub ↗

WaitOrTimeout tries to wait on the given channel for a value to come through, and returns it if one does, but times out after a reasonable amount of time. Useful to guarantee that test cases don't hang forever, even in the event of something wrong.

(tb testing.TB, waitChan <-chan T)

Source from the content-addressed store, hash-verified

275// Useful to guarantee that test cases don't hang forever, even in the event of
276// something wrong.
277func WaitOrTimeout[T any](tb testing.TB, waitChan <-chan T) T {
278 tb.Helper()
279
280 timeout := WaitTimeout()
281
282 select {
283 case value := <-waitChan:
284 return value
285 case <-time.After(timeout):
286 require.FailNowf(tb, "WaitOrTimeout timed out",
287 "WaitOrTimeout timed out after waiting %s", timeout)
288 }
289 return *new(T) // unreachable
290}
291
292// WaitOrTimeoutN tries to wait on the given channel for N values to come
293// through, and returns it if they do, but times out after a reasonable amount

Callers 15

TestClientPilotPluginFunction · 0.92
TestWorkFuncFunction · 0.92
Test_RecordedOutputFunction · 0.92
Test_Client_CommonFunction · 0.92
Test_Client_Stop_CommonFunction · 0.92
Test_Client_JobDeleteFunction · 0.92
Test_Client_InsertFunction · 0.92

Calls 3

WaitTimeoutFunction · 0.85
AfterMethod · 0.80
HelperMethod · 0.65

Tested by 15

TestClientPilotPluginFunction · 0.74
TestWorkFuncFunction · 0.74
Test_RecordedOutputFunction · 0.74
Test_Client_CommonFunction · 0.74
Test_Client_Stop_CommonFunction · 0.74
Test_Client_JobDeleteFunction · 0.74
Test_Client_InsertFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…