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

Function TestHeadTailBuffer_MultiMBStaysBounded

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

Source from the content-addressed store, hash-verified

117}
118
119func TestHeadTailBuffer_MultiMBStaysBounded(t *testing.T) {
120 t.Parallel()
121
122 buf := agentproc.NewHeadTailBuffer()
123
124 // Write 5MB of data in chunks.
125 chunk := []byte(strings.Repeat("x", 4096) + "\n")
126 totalWritten := 0
127 for totalWritten < 5*1024*1024 {
128 n, err := buf.Write(chunk)
129 require.NoError(t, err)
130 require.Equal(t, len(chunk), n)
131 totalWritten += n
132 }
133
134 // Memory should be bounded to head+tail.
135 require.LessOrEqual(t, buf.Len(),
136 agentproc.MaxHeadBytes+agentproc.MaxTailBytes)
137 require.Equal(t, totalWritten, buf.TotalWritten())
138
139 out, info := buf.Output()
140 require.NotNil(t, info)
141 require.Equal(t, totalWritten, info.OriginalBytes)
142 require.Greater(t, info.OmittedBytes, 0)
143 require.NotEmpty(t, out)
144}
145
146func TestHeadTailBuffer_LongLineTruncation(t *testing.T) {
147 t.Parallel()

Callers

nothing calls this directly

Calls 7

WriteMethod · 0.95
LenMethod · 0.95
TotalWrittenMethod · 0.95
OutputMethod · 0.95
NewHeadTailBufferFunction · 0.92
NotEmptyMethod · 0.80
EqualMethod · 0.45

Tested by

no test coverage detected