From 06e1e187936838b0456d21e66a10c3cf22550f7e Mon Sep 17 00:00:00 2001 From: Fred Date: Thu, 2 Mar 2023 16:39:58 +0000 Subject: [PATCH] seafile: fix for flaky tests #6799 --- backend/seafile/renew_test.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/backend/seafile/renew_test.go b/backend/seafile/renew_test.go index 4e9c4e13b..610f553fd 100644 --- a/backend/seafile/renew_test.go +++ b/backend/seafile/renew_test.go @@ -1,7 +1,6 @@ package seafile import ( - "sync" "sync/atomic" "testing" "time" @@ -17,19 +16,19 @@ func TestShouldAllowShutdownTwice(t *testing.T) { renew.Shutdown() } -func TestRenewal(t *testing.T) { +func TestRenewalInTimeLimit(t *testing.T) { var count int64 - wg := sync.WaitGroup{} - wg.Add(2) // run the renewal twice - renew := NewRenew(time.Millisecond, func() error { + renew := NewRenew(100*time.Millisecond, func() error { atomic.AddInt64(&count, 1) - wg.Done() return nil }) - wg.Wait() + time.Sleep(time.Second) renew.Shutdown() - // it is technically possible that a third renewal gets triggered between Wait() and Shutdown() - assert.GreaterOrEqual(t, atomic.LoadInt64(&count), int64(2)) + // there's no guarantee the CI agent can handle a simple goroutine + renewCount := atomic.LoadInt64(&count) + t.Logf("renew count = %d", renewCount) + assert.Greater(t, renewCount, int64(0)) + assert.Less(t, renewCount, int64(11)) }