MCPcopy Create free account
hub / github.com/ajitpratap0/GoSQLX / TestPoolReuse

Function TestPoolReuse

pkg/sql/ast/pool_test.go:205–249  ·  view source on GitHub ↗

Test pool reuse

(t *testing.T)

Source from the content-addressed store, hash-verified

203
204// Test pool reuse
205func TestPoolReuse(t *testing.T) {
206 t.Run("InsertStatement reuse", func(t *testing.T) {
207 // Get first statement
208 stmt1 := GetInsertStatement()
209 stmt1.TableName = "test"
210
211 // Return it
212 PutInsertStatement(stmt1)
213
214 // Get another statement - might be the same one
215 stmt2 := GetInsertStatement()
216 if stmt2 == nil {
217 t.Fatal("GetInsertStatement() returned nil on reuse")
218 }
219
220 // Should be clean
221 if stmt2.TableName != "" {
222 t.Errorf("Reused statement not clean, TableName = %v", stmt2.TableName)
223 }
224
225 PutInsertStatement(stmt2)
226 })
227
228 t.Run("LiteralValue reuse", func(t *testing.T) {
229 // Get first literal
230 lit1 := GetLiteralValue()
231 lit1.Value = "first"
232
233 // Return it
234 PutLiteralValue(lit1)
235
236 // Get another literal - might be the same one
237 lit2 := GetLiteralValue()
238 if lit2 == nil {
239 t.Fatal("GetLiteralValue() returned nil on reuse")
240 }
241
242 // Should be clean (Value is interface{}, so check for nil not empty string)
243 if lit2.Value != nil {
244 t.Errorf("Reused literal not clean, Value = %v", lit2.Value)
245 }
246
247 PutLiteralValue(lit2)
248 })
249}
250
251// Memory leak detection tests for all pools
252func TestMemoryLeaks_ASTPool(t *testing.T) {

Callers

nothing calls this directly

Calls 6

GetInsertStatementFunction · 0.85
PutInsertStatementFunction · 0.85
GetLiteralValueFunction · 0.85
PutLiteralValueFunction · 0.85
RunMethod · 0.80
ErrorfMethod · 0.65

Tested by

no test coverage detected