MCPcopy Create free account
hub / github.com/codechenx/FastTableViewer / TestMemoryLimit_Stats

Function TestMemoryLimit_Stats

memory_limit_test.go:87–144  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

85}
86
87func TestMemoryLimit_Stats(t *testing.T) {
88 b := createNewBuffer()
89 b.setMemoryLimit(1024 * 1024) // 1 MB
90
91 // Add some data
92 for i := 0; i < 10; i++ {
93 row := []string{
94 fmt.Sprintf("value_%d", i),
95 fmt.Sprintf("data_%d", i),
96 fmt.Sprintf("test_%d", i),
97 }
98 err := b.contAppendSli(row, false)
99 if err != nil {
100 t.Fatalf("Failed to add row: %v", err)
101 }
102 }
103
104 stats := b.getMemoryStats()
105
106 // Check required fields
107 if _, ok := stats["current_bytes"]; !ok {
108 t.Error("Stats should include current_bytes")
109 }
110
111 if _, ok := stats["current_formatted"]; !ok {
112 t.Error("Stats should include current_formatted")
113 }
114
115 if _, ok := stats["limit_bytes"]; !ok {
116 t.Error("Stats should include limit_bytes")
117 }
118
119 if _, ok := stats["limit_formatted"]; !ok {
120 t.Error("Stats should include limit_formatted")
121 }
122
123 if _, ok := stats["usage_percent"]; !ok {
124 t.Error("Stats should include usage_percent")
125 }
126
127 // Check values
128 currentBytes := stats["current_bytes"].(int64)
129 if currentBytes <= 0 {
130 t.Error("Current bytes should be > 0")
131 }
132
133 limitBytes := stats["limit_bytes"].(int64)
134 if limitBytes != 1024*1024 {
135 t.Errorf("Limit should be 1048576, got %d", limitBytes)
136 }
137
138 usagePercent := stats["usage_percent"].(float64)
139 if usagePercent < 0 || usagePercent > 100 {
140 t.Errorf("Usage percent should be 0-100, got %f", usagePercent)
141 }
142
143 t.Logf("Memory stats: %+v", stats)
144}

Callers

nothing calls this directly

Calls 4

createNewBufferFunction · 0.85
setMemoryLimitMethod · 0.80
contAppendSliMethod · 0.80
getMemoryStatsMethod · 0.80

Tested by

no test coverage detected