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

Function TestWaitBuffer_ConcurrentWrites

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

Source from the content-addressed store, hash-verified

110}
111
112func TestWaitBuffer_ConcurrentWrites(t *testing.T) {
113 t.Parallel()
114
115 wb := testutil.NewWaitBuffer()
116 var wg sync.WaitGroup
117 const writers = 10
118 const iterations = 100
119 wg.Add(writers)
120 for i := range writers {
121 go func() {
122 defer wg.Done()
123 for j := range iterations {
124 _, _ = wb.Write([]byte(fmt.Sprintf("w%d-%d ", i, j)))
125 }
126 }()
127 }
128 wg.Wait()
129
130 // Every write should have landed; verify no data was lost by
131 // checking the length is at least as large as expected.
132 assert.GreaterOrEqual(t, len(wb.Bytes()), writers*iterations)
133}
134
135func TestWaitBuffer_WaitFor_BackgroundGoroutine(t *testing.T) {
136 t.Parallel()

Callers

nothing calls this directly

Calls 6

WriteMethod · 0.95
BytesMethod · 0.95
NewWaitBufferFunction · 0.92
AddMethod · 0.65
WaitMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected