memory_test.go — fiber Source File
Architecture documentation for memory_test.go, a go file in the fiber codebase. 1 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 8e52f8f1_839a_b0fc_7531_40c840c383a4["memory_test.go"] d412afc8_b482_999e_79ca_16b6ad9c2e7c["testing"] 8e52f8f1_839a_b0fc_7531_40c840c383a4 --> d412afc8_b482_999e_79ca_16b6ad9c2e7c style 8e52f8f1_839a_b0fc_7531_40c840c383a4 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
package memory
import (
"testing"
"time"
"github.com/gofiber/utils/v2"
"github.com/stretchr/testify/require"
)
// go test -run Test_Memory -v -race
func Test_Memory(t *testing.T) {
t.Parallel()
store := New()
var (
key = "john-internal"
val any = []byte("doe")
exp = 1 * time.Second
)
// Set key with value
store.Set(key, val, 0)
result := store.Get(key)
require.Equal(t, val, result)
// Get non-existing key
result = store.Get("empty")
require.Nil(t, result)
// Set key with value and ttl
store.Set(key, val, exp)
time.Sleep(1100 * time.Millisecond)
result = store.Get(key)
require.Nil(t, result)
// Set key with value and no expiration
store.Set(key, val, 0)
result = store.Get(key)
require.Equal(t, val, result)
// Delete key
store.Delete(key)
result = store.Get(key)
require.Nil(t, result)
// Reset all keys
store.Set("john-reset", val, 0)
store.Set("doe-reset", val, 0)
store.Reset()
// Check if all keys are deleted
result = store.Get("john-reset")
require.Nil(t, result)
result = store.Get("doe-reset")
require.Nil(t, result)
}
// go test -v -run=^$ -bench=Benchmark_Memory -benchmem -count=4
func Benchmark_Memory(b *testing.B) {
keyLength := 1000
keys := make([]string, keyLength)
for i := range keyLength {
keys[i] = utils.UUIDv4()
}
value := []byte("joe")
ttl := 2 * time.Second
b.Run("fiber_memory", func(b *testing.B) {
d := New()
b.ReportAllocs()
for b.Loop() {
for _, key := range keys {
d.Set(key, value, ttl)
}
for _, key := range keys {
_ = d.Get(key)
}
for _, key := range keys {
d.Delete(key)
}
}
})
}
Domain
Subdomains
Functions
Classes
Dependencies
- testing
Source
Frequently Asked Questions
What does memory_test.go do?
memory_test.go is a source file in the fiber codebase, written in go. It belongs to the InternalStorage domain, MemoryStore subdomain.
What functions are defined in memory_test.go?
memory_test.go defines 2 function(s): Benchmark_Memory, Test_Memory.
What does memory_test.go depend on?
memory_test.go imports 1 module(s): testing.
Where is memory_test.go in the architecture?
memory_test.go is located at internal/memory/memory_test.go (domain: InternalStorage, subdomain: MemoryStore, directory: internal/memory).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free