f31ab6d178
Passwords for encrypted libraries are kept in memory in the server and flushed after an hour. This MR fixes an issue when the library password expires after 1 hour.
35 lines
673 B
Go
35 lines
673 B
Go
package seafile
|
|
|
|
import (
|
|
"sync"
|
|
"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()
|
|
}
|
|
|
|
func TestRenewal(t *testing.T) {
|
|
var count int64
|
|
|
|
wg := sync.WaitGroup{}
|
|
wg.Add(2) // run the renewal twice
|
|
renew := NewRenew(time.Millisecond, func() error {
|
|
atomic.AddInt64(&count, 1)
|
|
wg.Done()
|
|
return nil
|
|
})
|
|
wg.Wait()
|
|
renew.Shutdown()
|
|
|
|
// it is technically possible that a third renewal gets triggered between Wait() and Shutdown()
|
|
assert.GreaterOrEqual(t, atomic.LoadInt64(&count), int64(2))
|
|
}
|