github.com/artpar/rclone@v1.67.3/backend/seafile/renew_test.go (about) 1 package seafile 2 3 import ( 4 "sync/atomic" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/assert" 9 ) 10 11 func TestShouldAllowShutdownTwice(t *testing.T) { 12 renew := NewRenew(time.Hour, func() error { 13 return nil 14 }) 15 renew.Shutdown() 16 renew.Shutdown() 17 } 18 19 func TestRenewalInTimeLimit(t *testing.T) { 20 var count atomic.Int64 21 22 renew := NewRenew(100*time.Millisecond, func() error { 23 count.Add(1) 24 return nil 25 }) 26 time.Sleep(time.Second) 27 renew.Shutdown() 28 29 // there's no guarantee the CI agent can handle a simple goroutine 30 renewCount := count.Load() 31 t.Logf("renew count = %d", renewCount) 32 assert.Greater(t, renewCount, int64(0)) 33 assert.Less(t, renewCount, int64(11)) 34 }