From f51ba5cbc9736fb024f5b393e0d4928ff77e4080 Mon Sep 17 00:00:00 2001 From: Zixiong Liu Date: Mon, 30 Aug 2021 16:16:26 +0800 Subject: [PATCH] fix unit test --- cdc/puller/sorter/memory_backend_test.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cdc/puller/sorter/memory_backend_test.go b/cdc/puller/sorter/memory_backend_test.go index d615e9113bb..86b93b3ebcf 100644 --- a/cdc/puller/sorter/memory_backend_test.go +++ b/cdc/puller/sorter/memory_backend_test.go @@ -16,6 +16,7 @@ package sorter import ( "runtime" "sync/atomic" + "time" "github.com/pingcap/check" "github.com/pingcap/ticdc/cdc/model" @@ -54,12 +55,24 @@ func (s *memoryBackendSuite) TestNoLeaking(c *check.C) { c.Assert(err, check.IsNil) } - runtime.GC() + for i := 0; i < 10; i++ { + runtime.GC() + if atomic.LoadInt64(&objCount) <= 5000 { + break + } + time.Sleep(100 * time.Millisecond) + } c.Assert(atomic.LoadInt64(&objCount), check.LessEqual, int64(5000)) err = rdr.resetAndClose() c.Assert(err, check.IsNil) - runtime.GC() + for i := 0; i < 10; i++ { + runtime.GC() + if atomic.LoadInt64(&objCount) == 0 { + break + } + time.Sleep(100 * time.Millisecond) + } c.Assert(atomic.LoadInt64(&objCount), check.Equals, int64(0)) }