2023-01-12 04:25:44 +08:00
|
|
|
package seafile
|
|
|
|
|
|
|
|
import (
|
|
|
|
"sync/atomic"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestShouldAllowShutdownTwice(t *testing.T) {
|
|
|
|
renew := NewRenew(time.Hour, func() error {
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
renew.Shutdown()
|
|
|
|
renew.Shutdown()
|
|
|
|
}
|
|
|
|
|
2023-03-03 00:39:58 +08:00
|
|
|
func TestRenewalInTimeLimit(t *testing.T) {
|
2023-08-18 22:29:18 +08:00
|
|
|
var count atomic.Int64
|
2023-01-12 04:25:44 +08:00
|
|
|
|
2023-03-03 00:39:58 +08:00
|
|
|
renew := NewRenew(100*time.Millisecond, func() error {
|
2023-08-18 22:29:18 +08:00
|
|
|
count.Add(1)
|
2023-01-12 04:25:44 +08:00
|
|
|
return nil
|
|
|
|
})
|
2023-03-03 00:39:58 +08:00
|
|
|
time.Sleep(time.Second)
|
2023-01-12 04:25:44 +08:00
|
|
|
renew.Shutdown()
|
|
|
|
|
2023-03-03 00:39:58 +08:00
|
|
|
// there's no guarantee the CI agent can handle a simple goroutine
|
2023-08-18 22:29:18 +08:00
|
|
|
renewCount := count.Load()
|
2023-03-03 00:39:58 +08:00
|
|
|
t.Logf("renew count = %d", renewCount)
|
|
|
|
assert.Greater(t, renewCount, int64(0))
|
|
|
|
assert.Less(t, renewCount, int64(11))
|
2023-01-12 04:25:44 +08:00
|
|
|
}
|