seafile: fix for flaky tests #6799

This commit is contained in:
Fred 2023-03-02 16:39:58 +00:00 committed by Nick Craig-Wood
parent 23d17b76be
commit 06e1e18793

View file

@ -1,7 +1,6 @@
package seafile package seafile
import ( import (
"sync"
"sync/atomic" "sync/atomic"
"testing" "testing"
"time" "time"
@ -17,19 +16,19 @@ func TestShouldAllowShutdownTwice(t *testing.T) {
renew.Shutdown() renew.Shutdown()
} }
func TestRenewal(t *testing.T) { func TestRenewalInTimeLimit(t *testing.T) {
var count int64 var count int64
wg := sync.WaitGroup{} renew := NewRenew(100*time.Millisecond, func() error {
wg.Add(2) // run the renewal twice
renew := NewRenew(time.Millisecond, func() error {
atomic.AddInt64(&count, 1) atomic.AddInt64(&count, 1)
wg.Done()
return nil return nil
}) })
wg.Wait() time.Sleep(time.Second)
renew.Shutdown() renew.Shutdown()
// it is technically possible that a third renewal gets triggered between Wait() and Shutdown() // there's no guarantee the CI agent can handle a simple goroutine
assert.GreaterOrEqual(t, atomic.LoadInt64(&count), int64(2)) renewCount := atomic.LoadInt64(&count)
t.Logf("renew count = %d", renewCount)
assert.Greater(t, renewCount, int64(0))
assert.Less(t, renewCount, int64(11))
} }