MCPcopy
hub / github.com/redis/go-redis / TestInlineSliceAllocations

Function TestInlineSliceAllocations

internal/pool/conn_state_alloc_test.go:27–43  ·  view source on GitHub ↗

TestInlineSliceAllocations shows that inline slices cause allocations

(t *testing.T)

Source from the content-addressed store, hash-verified

25
26// TestInlineSliceAllocations shows that inline slices cause allocations
27func TestInlineSliceAllocations(t *testing.T) {
28 sm := NewConnStateMachine()
29 sm.Transition(StateIdle)
30 ctx := context.Background()
31
32 // Test with inline slice - will allocate
33 allocs := testing.AllocsPerRun(100, func() {
34 _, _ = sm.AwaitAndTransition(ctx, []ConnState{StateIdle}, StateUnusable)
35 sm.Transition(StateIdle)
36 })
37
38 if allocs == 0 {
39 t.Logf("Inline slice had 0 allocations (compiler optimization)")
40 } else {
41 t.Logf("Inline slice caused %.2f allocations per run (expected)", allocs)
42 }
43}
44
45// BenchmarkAwaitAndTransition_PredefinedSlice benchmarks with predefined slice
46func BenchmarkAwaitAndTransition_PredefinedSlice(b *testing.B) {

Callers

nothing calls this directly

Calls 3

TransitionMethod · 0.95
AwaitAndTransitionMethod · 0.95
NewConnStateMachineFunction · 0.85

Tested by

no test coverage detected