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

Function TestWaitBuffer_WaitForCond

testutil/wait_buffer_test.go:86–110  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

84}
85
86func TestWaitBuffer_WaitForCond(t *testing.T) {
87 t.Parallel()
88 ctx := testutil.Context(t, testutil.WaitShort)
89
90 wb := testutil.NewWaitBuffer()
91 done := make(chan struct{})
92 go func() {
93 defer close(done)
94 // Wait until the buffer has at least 10 bytes.
95 _ = wb.WaitForCond(ctx, func(s string) bool {
96 return len(s) >= 10
97 })
98 }()
99
100 _, err := wb.Write([]byte("12345"))
101 require.NoError(t, err)
102 _, err = wb.Write([]byte("67890"))
103 require.NoError(t, err)
104
105 select {
106 case <-done:
107 case <-ctx.Done():
108 t.Fatal("WaitForCond did not unblock when condition was met")
109 }
110}
111
112func TestWaitBuffer_ConcurrentWrites(t *testing.T) {
113 t.Parallel()

Callers

nothing calls this directly

Calls 6

WaitForCondMethod · 0.95
WriteMethod · 0.95
ContextFunction · 0.92
NewWaitBufferFunction · 0.92
FatalMethod · 0.80
DoneMethod · 0.45

Tested by

no test coverage detected