MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / TestAsyncBufferClose

Function TestAsyncBufferClose

asyncbuffer/buffer_test.go:282–305  ·  view source on GitHub ↗

TestAsyncBufferClose tests closing the AsyncBuffer

(t *testing.T)

Source from the content-addressed store, hash-verified

280
281// TestAsyncBufferClose tests closing the AsyncBuffer
282func TestAsyncBufferClose(t *testing.T) {
283 _, bytesReader := generateSourceData(t, asyncbuffer.ChunkSize*4+halfChunkSize)
284
285 // Create an AsyncBuffer with the byte slice
286 ab := asyncbuffer.New(bytesReader, -1)
287
288 reader1 := ab.Reader()
289 reader2 := ab.Reader()
290
291 ab.Close()
292
293 b := make([]byte, 10)
294 _, err := reader1.Read(b)
295 require.Error(t, err, "asyncbuffer.AsyncBuffer.ReadAt: attempt to read on closed reader")
296
297 _, err = reader2.Read(b)
298 require.Error(t, err, "asyncbuffer.AsyncBuffer.ReadAt: attempt to read on closed reader")
299
300 // After closing the closed reader, it should not panic
301 ab.Close()
302
303 _, err = reader2.Read(b)
304 require.Error(t, err, "asyncbuffer.AsyncBuffer.ReadAt: attempt to read on closed reader")
305}
306
307// TestAsyncBufferReadAtErrAtSomePoint tests reading from AsyncBuffer using readAt method
308// which would fail somewhere

Callers

nothing calls this directly

Calls 6

NewFunction · 0.92
generateSourceDataFunction · 0.85
ReaderMethod · 0.65
CloseMethod · 0.65
ErrorMethod · 0.65
ReadMethod · 0.45

Tested by

no test coverage detected