refactor(node): clarify filesystem and buffer pool names
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
de8b138367
commit
dec79b54d6
3 changed files with 16 additions and 16 deletions
|
|
@ -7,8 +7,8 @@ import (
|
|||
core "dappco.re/go/core"
|
||||
)
|
||||
|
||||
// bufferPool provides reusable byte buffers for JSON encoding.
|
||||
// This reduces allocation overhead in hot paths like message serialization.
|
||||
// bufferPool provides reusable byte buffers for JSON encoding in hot paths.
|
||||
// This reduces allocation overhead in message serialization.
|
||||
var bufferPool = sync.Pool{
|
||||
New: func() any {
|
||||
return bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
|
@ -10,9 +10,9 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
// --- bufpool.go tests ---
|
||||
// --- buffer_pool.go tests ---
|
||||
|
||||
func TestBufpool_Buffer_ReturnsResetBuffer_Good(t *testing.T) {
|
||||
func TestBufferPool_Buffer_ReturnsResetBuffer_Good(t *testing.T) {
|
||||
t.Run("buffer is initially empty", func(t *testing.T) {
|
||||
buf := getBuffer()
|
||||
defer putBuffer(buf)
|
||||
|
|
@ -33,7 +33,7 @@ func TestBufpool_Buffer_ReturnsResetBuffer_Good(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestBufpool_PutBuffer_DiscardsOversizedBuffers_Good(t *testing.T) {
|
||||
func TestBufferPool_PutBuffer_DiscardsOversizedBuffers_Good(t *testing.T) {
|
||||
t.Run("buffer at 64KB limit is pooled", func(t *testing.T) {
|
||||
buf := getBuffer()
|
||||
buf.Grow(65536)
|
||||
|
|
@ -59,7 +59,7 @@ func TestBufpool_PutBuffer_DiscardsOversizedBuffers_Good(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestBufpool_BufPool_BufferIndependence_Good(t *testing.T) {
|
||||
func TestBufferPool_BufferIndependence_Good(t *testing.T) {
|
||||
buf1 := getBuffer()
|
||||
buf2 := getBuffer()
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ func TestBufpool_BufPool_BufferIndependence_Good(t *testing.T) {
|
|||
putBuffer(buf2)
|
||||
}
|
||||
|
||||
func TestBufpool_MarshalJSON_BasicTypes_Good(t *testing.T) {
|
||||
func TestBufferPool_MarshalJSON_BasicTypes_Good(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
input any
|
||||
|
|
@ -129,7 +129,7 @@ func TestBufpool_MarshalJSON_BasicTypes_Good(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBufpool_MarshalJSON_NoTrailingNewline_Good(t *testing.T) {
|
||||
func TestBufferPool_MarshalJSON_NoTrailingNewline_Good(t *testing.T) {
|
||||
data, err := MarshalJSON(map[string]string{"key": "value"})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -137,7 +137,7 @@ func TestBufpool_MarshalJSON_NoTrailingNewline_Good(t *testing.T) {
|
|||
"MarshalJSON should strip the trailing newline added by json.Encoder")
|
||||
}
|
||||
|
||||
func TestBufpool_MarshalJSON_HTMLEscaping_Good(t *testing.T) {
|
||||
func TestBufferPool_MarshalJSON_HTMLEscaping_Good(t *testing.T) {
|
||||
input := map[string]string{"html": "<script>alert('xss')</script>"}
|
||||
data, err := MarshalJSON(input)
|
||||
require.NoError(t, err)
|
||||
|
|
@ -146,7 +146,7 @@ func TestBufpool_MarshalJSON_HTMLEscaping_Good(t *testing.T) {
|
|||
"HTML characters should not be escaped when EscapeHTML is false")
|
||||
}
|
||||
|
||||
func TestBufpool_MarshalJSON_ReturnsCopy_Good(t *testing.T) {
|
||||
func TestBufferPool_MarshalJSON_ReturnsCopy_Good(t *testing.T) {
|
||||
data1, err := MarshalJSON("first")
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -161,7 +161,7 @@ func TestBufpool_MarshalJSON_ReturnsCopy_Good(t *testing.T) {
|
|||
"returned slice should be a copy and not be mutated by subsequent calls")
|
||||
}
|
||||
|
||||
func TestBufpool_MarshalJSON_ReturnsIndependentCopy_Good(t *testing.T) {
|
||||
func TestBufferPool_MarshalJSON_ReturnsIndependentCopy_Good(t *testing.T) {
|
||||
data1, err := MarshalJSON(map[string]string{"first": "call"})
|
||||
require.NoError(t, err)
|
||||
|
||||
|
|
@ -174,13 +174,13 @@ func TestBufpool_MarshalJSON_ReturnsIndependentCopy_Good(t *testing.T) {
|
|||
"second result should contain its own data")
|
||||
}
|
||||
|
||||
func TestBufpool_MarshalJSON_InvalidValue_Bad(t *testing.T) {
|
||||
func TestBufferPool_MarshalJSON_InvalidValue_Bad(t *testing.T) {
|
||||
ch := make(chan int)
|
||||
_, err := MarshalJSON(ch)
|
||||
assert.Error(t, err, "marshalling an unserialisable type should return an error")
|
||||
}
|
||||
|
||||
func TestBufpool_BufferPool_ConcurrentAccess_Ugly(t *testing.T) {
|
||||
func TestBufferPool_ConcurrentAccess_Ugly(t *testing.T) {
|
||||
const goroutines = 100
|
||||
const iterations = 50
|
||||
|
||||
|
|
@ -205,7 +205,7 @@ func TestBufpool_BufferPool_ConcurrentAccess_Ugly(t *testing.T) {
|
|||
wg.Wait()
|
||||
}
|
||||
|
||||
func TestBufpool_MarshalJSON_ConcurrentSafety_Ugly(t *testing.T) {
|
||||
func TestBufferPool_MarshalJSON_ConcurrentSafety_Ugly(t *testing.T) {
|
||||
const goroutines = 50
|
||||
|
||||
var wg sync.WaitGroup
|
||||
|
|
@ -241,7 +241,7 @@ func TestBufpool_MarshalJSON_ConcurrentSafety_Ugly(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestBufpool_BufferPool_ReuseAfterReset_Ugly(t *testing.T) {
|
||||
func TestBufferPool_ReuseAfterReset_Ugly(t *testing.T) {
|
||||
buf := getBuffer()
|
||||
buf.Write(make([]byte, 4096))
|
||||
putBuffer(buf)
|
||||
|
|
@ -51,5 +51,5 @@ func filesystemResultError(result core.Result) error {
|
|||
return err
|
||||
}
|
||||
|
||||
return core.E("node.fs", "filesystem operation failed", nil)
|
||||
return core.E("node.filesystem", "filesystem operation failed", nil)
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue