Skip to content

Commit 54392f5

Browse files
authored
Merge pull request #9 from zanmato1984/codex/pb-memory-contract-coverage-final
test: align PB memory leak check with RecordSet lifecycle
2 parents cb1e1e6 + 3807537 commit 54392f5

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

pkg/executor/test/unstabletest/memory_test.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,27 @@ func TestPBMemoryLeak(t *testing.T) {
124124
// read data
125125
runtime.GC()
126126
allocatedBegin, inUseBegin := readMem()
127-
records, err := tk.Session().Execute(context.Background(), "select * from t")
128-
require.NoError(t, err)
129-
record := records[0]
130-
rowCnt := 0
131-
chk := record.NewChunk(nil)
132-
for {
133-
require.NoError(t, record.Next(context.Background(), chk))
134-
rowCnt += chk.NumRows()
135-
if chk.NumRows() == 0 {
136-
break
127+
rowCnt := func() int {
128+
records, err := tk.Session().Execute(context.Background(), "select * from t")
129+
require.NoError(t, err)
130+
require.Len(t, records, 1)
131+
132+
record := records[0]
133+
defer func() { require.NoError(t, record.Close()) }()
134+
135+
rowCnt := 0
136+
chk := record.NewChunk(nil)
137+
for {
138+
require.NoError(t, record.Next(context.Background(), chk))
139+
rowCnt += chk.NumRows()
140+
if chk.NumRows() == 0 {
141+
return rowCnt
142+
}
137143
}
138-
}
144+
}()
139145
require.Equal(t, int(numRows), rowCnt)
140146

141-
// check memory before close
147+
// check memory after the result set has been drained and closed
142148
runtime.GC()
143149
allocatedAfter, inUseAfter := readMem()
144150
require.GreaterOrEqual(t, allocatedAfter-allocatedBegin, totalSize)

0 commit comments

Comments
 (0)