Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix unstable TestMemoryLeak #28111

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5723,13 +5723,14 @@ func (s *testTiDBAsLibrary) TestMemoryLeak(c *C) {
runtime.ReadMemStats(&memStat)
oldHeapInUse := memStat.HeapInuse

for i := 0; i < 10; i++ {
for i := 0; i < 20; i++ {
initAndCloseTiDB()
}

runtime.GC()
runtime.ReadMemStats(&memStat)
c.Assert(memStat.HeapInuse-oldHeapInUse, Less, uint64(150*units.MiB))
// before the fix, initAndCloseTiDB for 20 times will cost 900 MB memory, so we test for a quite loose upper bound.
c.Assert(memStat.HeapInuse-oldHeapInUse, Less, uint64(300*units.MiB))
Comment on lines 5724 to +5733
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain how this is expected to work?

I would have thought either oldHeapInUse is calculated after initAndCloseTiDB() has been executed 20 times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this unstable test is introduced by #28027 , after dom.Close some memory didn't get released.

so repeat some times, leak grows significantly than usual memory. more repeat times gives us a wider bound to assert

}

func (s *testSessionSuite) TestTiDBReadStaleness(c *C) {
Expand Down