ABC-73 Move session clean-up to daily task (#8095)

* Move session clean-up to daily task

* Split delete query into batches
Этот коммит содержится в:
Joram Wilander
2018-01-17 08:50:49 -05:00
коммит произвёл GitHub
родитель d35d9484f4
Коммит dce0616305
5 изменённых файлов: 103 добавлений и 22 удалений

Просмотреть файл

@@ -29,6 +29,11 @@ func (_m *SessionStore) AnalyticsSessionCount() store.StoreChannel {
return r0
}
// Cleanup provides a mock function with given fields: expiryTime, batchSize
func (_m *SessionStore) Cleanup(expiryTime int64, batchSize int64) {
_m.Called(expiryTime, batchSize)
}
// Get provides a mock function with given fields: sessionIdOrToken
func (_m *SessionStore) Get(sessionIdOrToken string) store.StoreChannel {
ret := _m.Called(sessionIdOrToken)

Просмотреть файл

@@ -8,9 +8,14 @@ import (
"github.com/mattermost/mattermost-server/model"
"github.com/mattermost/mattermost-server/store"
"github.com/stretchr/testify/assert"
)
func TestSessionStore(t *testing.T, ss store.Store) {
// Run serially to prevent interfering with other tests
testSessionCleanup(t, ss)
t.Run("Save", func(t *testing.T) { testSessionStoreSave(t, ss) })
t.Run("SessionGet", func(t *testing.T) { testSessionGet(t, ss) })
t.Run("SessionGetWithDeviceId", func(t *testing.T) { testSessionGetWithDeviceId(t, ss) })
@@ -58,7 +63,7 @@ func testSessionGet(t *testing.T, ss store.Store) {
if rs2 := (<-ss.Session().GetSessions(s1.UserId)); rs2.Err != nil {
t.Fatal(rs2.Err)
} else {
if len(rs2.Data.([]*model.Session)) != 2 {
if len(rs2.Data.([]*model.Session)) != 3 {
t.Fatal("should match len")
}
}
@@ -248,3 +253,44 @@ func testSessionCount(t *testing.T, ss store.Store) {
}
}
}
func testSessionCleanup(t *testing.T, ss store.Store) {
now := model.GetMillis()
s1 := model.Session{}
s1.UserId = model.NewId()
s1.ExpiresAt = 0 // never expires
store.Must(ss.Session().Save(&s1))
s2 := model.Session{}
s2.UserId = s1.UserId
s2.ExpiresAt = now + 1000000 // expires in the future
store.Must(ss.Session().Save(&s2))
s3 := model.Session{}
s3.UserId = model.NewId()
s3.ExpiresAt = 1 // expired
store.Must(ss.Session().Save(&s3))
s4 := model.Session{}
s4.UserId = model.NewId()
s4.ExpiresAt = 2 // expired
store.Must(ss.Session().Save(&s4))
ss.Session().Cleanup(now, 1)
err := (<-ss.Session().Get(s1.Id)).Err
assert.Nil(t, err)
err = (<-ss.Session().Get(s2.Id)).Err
assert.Nil(t, err)
err = (<-ss.Session().Get(s3.Id)).Err
assert.NotNil(t, err)
err = (<-ss.Session().Get(s4.Id)).Err
assert.NotNil(t, err)
store.Must(ss.Session().Remove(s1.Id))
store.Must(ss.Session().Remove(s2.Id))
}