From dec79b54d6fedc99c093bb0839d2e87fae4fd8b1 Mon Sep 17 00:00:00 2001 From: Virgil Date: Mon, 30 Mar 2026 21:50:35 +0000 Subject: [PATCH] refactor(node): clarify filesystem and buffer pool names Co-Authored-By: Virgil --- node/{bufpool.go => buffer_pool.go} | 4 +-- node/{bufpool_test.go => buffer_pool_test.go} | 26 +++++++++---------- node/{core_fs.go => filesystem.go} | 2 +- 3 files changed, 16 insertions(+), 16 deletions(-) rename node/{bufpool.go => buffer_pool.go} (90%) rename node/{bufpool_test.go => buffer_pool_test.go} (85%) rename node/{core_fs.go => filesystem.go} (94%) diff --git a/node/bufpool.go b/node/buffer_pool.go similarity index 90% rename from node/bufpool.go rename to node/buffer_pool.go index 49d98ac..ace5915 100644 --- a/node/bufpool.go +++ b/node/buffer_pool.go @@ -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)) diff --git a/node/bufpool_test.go b/node/buffer_pool_test.go similarity index 85% rename from node/bufpool_test.go rename to node/buffer_pool_test.go index 3f931d7..35e1cc5 100644 --- a/node/bufpool_test.go +++ b/node/buffer_pool_test.go @@ -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": ""} 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) diff --git a/node/core_fs.go b/node/filesystem.go similarity index 94% rename from node/core_fs.go rename to node/filesystem.go index 2deb2dd..4139b7b 100644 --- a/node/core_fs.go +++ b/node/filesystem.go @@ -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) }