Cache test users to speed up testing (#13741)
* Cache test users to speed up testing Users were recreated for many tests and hashing passwords takes a lot of time. Testing /api4 takes around 120s less and /app 60s less. * fix build * simplifying a bit the approach Co-authored-by: mattermod <mattermod@users.noreply.github.com> Co-authored-by: Jesús Espino <jespinog@gmail.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
89f4e9d7ef
Коммит
662eef6881
@@ -11,6 +11,7 @@ import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
@@ -235,15 +236,50 @@ func (me *TestHelper) TearDown() {
|
||||
}
|
||||
}
|
||||
|
||||
var initBasicOnce sync.Once
|
||||
var userCache struct {
|
||||
SystemAdminUser *model.User
|
||||
TeamAdminUser *model.User
|
||||
BasicUser *model.User
|
||||
BasicUser2 *model.User
|
||||
}
|
||||
|
||||
func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.waitForConnectivity()
|
||||
|
||||
me.SystemAdminUser = me.CreateUser()
|
||||
me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_ADMIN_ROLE_ID, false)
|
||||
me.LoginSystemAdmin()
|
||||
// create users once and cache them because password hashing is slow
|
||||
initBasicOnce.Do(func() {
|
||||
me.SystemAdminUser = me.CreateUser()
|
||||
me.App.UpdateUserRoles(me.SystemAdminUser.Id, model.SYSTEM_USER_ROLE_ID+" "+model.SYSTEM_ADMIN_ROLE_ID, false)
|
||||
me.SystemAdminUser, _ = me.App.GetUser(me.SystemAdminUser.Id)
|
||||
userCache.SystemAdminUser = me.SystemAdminUser.DeepCopy()
|
||||
|
||||
me.TeamAdminUser = me.CreateUser()
|
||||
me.App.UpdateUserRoles(me.TeamAdminUser.Id, model.SYSTEM_USER_ROLE_ID, false)
|
||||
me.TeamAdminUser = me.CreateUser()
|
||||
me.App.UpdateUserRoles(me.TeamAdminUser.Id, model.SYSTEM_USER_ROLE_ID, false)
|
||||
me.TeamAdminUser, _ = me.App.GetUser(me.TeamAdminUser.Id)
|
||||
userCache.TeamAdminUser = me.TeamAdminUser.DeepCopy()
|
||||
|
||||
me.BasicUser = me.CreateUser()
|
||||
me.BasicUser, _ = me.App.GetUser(me.BasicUser.Id)
|
||||
userCache.BasicUser = me.BasicUser.DeepCopy()
|
||||
|
||||
me.BasicUser2 = me.CreateUser()
|
||||
me.BasicUser2, _ = me.App.GetUser(me.BasicUser2.Id)
|
||||
userCache.BasicUser2 = me.BasicUser2.DeepCopy()
|
||||
})
|
||||
// restore cached users
|
||||
me.SystemAdminUser = userCache.SystemAdminUser.DeepCopy()
|
||||
me.TeamAdminUser = userCache.TeamAdminUser.DeepCopy()
|
||||
me.BasicUser = userCache.BasicUser.DeepCopy()
|
||||
me.BasicUser2 = userCache.BasicUser2.DeepCopy()
|
||||
mainHelper.GetSQLSupplier().GetMaster().Insert(me.SystemAdminUser, me.TeamAdminUser, me.BasicUser, me.BasicUser2)
|
||||
// restore non hashed password for login
|
||||
me.SystemAdminUser.Password = "Pa$$word11"
|
||||
me.TeamAdminUser.Password = "Pa$$word11"
|
||||
me.BasicUser.Password = "Pa$$word11"
|
||||
me.BasicUser2.Password = "Pa$$word11"
|
||||
|
||||
me.LoginSystemAdmin()
|
||||
me.LoginTeamAdmin()
|
||||
|
||||
me.BasicTeam = me.CreateTeam()
|
||||
@@ -253,9 +289,7 @@ func (me *TestHelper) InitBasic() *TestHelper {
|
||||
me.BasicDeletedChannel = me.CreatePublicChannel()
|
||||
me.BasicChannel2 = me.CreatePublicChannel()
|
||||
me.BasicPost = me.CreatePost()
|
||||
me.BasicUser = me.CreateUser()
|
||||
me.LinkUserToTeam(me.BasicUser, me.BasicTeam)
|
||||
me.BasicUser2 = me.CreateUser()
|
||||
me.LinkUserToTeam(me.BasicUser2, me.BasicTeam)
|
||||
me.App.AddUserToChannel(me.BasicUser, me.BasicChannel)
|
||||
me.App.AddUserToChannel(me.BasicUser2, me.BasicChannel)
|
||||
|
||||
@@ -18,7 +18,10 @@ func TestGetPreferences(t *testing.T) {
|
||||
defer th.TearDown()
|
||||
Client := th.Client
|
||||
|
||||
// recreate basic user (cached has no default preferences)
|
||||
th.BasicUser = th.CreateUser()
|
||||
th.LoginBasic()
|
||||
|
||||
user1 := th.BasicUser
|
||||
|
||||
category := model.NewId()
|
||||
@@ -50,6 +53,8 @@ func TestGetPreferences(t *testing.T) {
|
||||
require.Equal(t, preference.UserId, th.BasicUser.Id, "user id does not match")
|
||||
}
|
||||
|
||||
// recreate basic user2
|
||||
th.BasicUser2 = th.CreateUser()
|
||||
th.LoginBasic2()
|
||||
|
||||
prefs, resp = Client.GetPreferences(th.BasicUser2.Id)
|
||||
|
||||
@@ -1242,6 +1242,10 @@ func TestAutocompleteUsers(t *testing.T) {
|
||||
func TestGetProfileImage(t *testing.T) {
|
||||
th := Setup(t).InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// recreate basic user
|
||||
th.BasicUser = th.CreateUser()
|
||||
th.LoginBasic()
|
||||
user := th.BasicUser
|
||||
|
||||
data, resp := th.Client.GetProfileImage(user.Id, "")
|
||||
|
||||
Ссылка в новой задаче
Block a user