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

Function TestHeadTailBuffer_ConcurrentWrites

agent/agentproc/headtail_test.go:184–213  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

182}
183
184func TestHeadTailBuffer_ConcurrentWrites(t *testing.T) {
185 t.Parallel()
186
187 buf := agentproc.NewHeadTailBuffer()
188
189 const goroutines = 10
190 const writes = 1000
191 var wg sync.WaitGroup
192 wg.Add(goroutines)
193
194 for g := range goroutines {
195 go func() {
196 defer wg.Done()
197 line := fmt.Sprintf("goroutine-%d: data\n", g)
198 for range writes {
199 _, err := buf.Write([]byte(line))
200 assert.NoError(t, err)
201 }
202 }()
203 }
204
205 wg.Wait()
206
207 // Verify totals are consistent.
208 require.Greater(t, buf.TotalWritten(), 0)
209 require.Greater(t, buf.Len(), 0)
210
211 out, _ := buf.Output()
212 require.NotEmpty(t, out)
213}
214
215func TestHeadTailBuffer_TruncationInfoFields(t *testing.T) {
216 t.Parallel()

Callers

nothing calls this directly

Calls 9

WriteMethod · 0.95
TotalWrittenMethod · 0.95
LenMethod · 0.95
OutputMethod · 0.95
NewHeadTailBufferFunction · 0.92
NotEmptyMethod · 0.80
AddMethod · 0.65
WaitMethod · 0.65
DoneMethod · 0.45

Tested by

no test coverage detected