* MM-27149: optimize initBasic

Mostly, all tests just needed the user initialization part and not
the channel and group creation. So we move the user initialization inside
the Setup call. This avoids unnecessary DB calls which take around 250-300ms
on average.

And we make the login requests concurrently to shave off a few more ms.
According to my tests, the 2 login calls take 140 ms on average, which
shaves off 70ms.

So approximately, we shave off 350ms per test. And there are 114 occurences
of these. So around 39 seconds.

* make initlogin only for Setup/SetupEnterprise

Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
Agniva De Sarker
2020-07-22 13:50:33 +05:30
коммит произвёл GitHub
родитель 30bd506e76
Коммит 4a2715974d
24 изменённых файлов: 137 добавлений и 119 удалений

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

@@ -23,7 +23,7 @@ import (
)
func TestCreateUser(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
user := model.User{Email: th.GenerateTestEmail(), Nickname: "Corey Hulen", Password: "hello1", Username: GenerateTestUsername(), Roles: model.SYSTEM_ADMIN_ROLE_ID + " " + model.SYSTEM_USER_ROLE_ID}
@@ -80,7 +80,7 @@ func TestCreateUser(t *testing.T) {
}
func TestCreateUserInputFilter(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
t.Run("DomainRestriction", func(t *testing.T) {
@@ -580,7 +580,7 @@ func TestGetMe(t *testing.T) {
}
func TestGetUser(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
user := th.CreateUser()
@@ -630,7 +630,7 @@ func TestGetUser(t *testing.T) {
}
func TestGetUserWithAcceptedTermsOfServiceForOtherUser(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
user := th.CreateUser()
@@ -829,7 +829,7 @@ func TestGetUserByUsernameWithAcceptedTermsOfService(t *testing.T) {
}
func TestGetUserByEmail(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
user := th.CreateUser()
@@ -1477,7 +1477,7 @@ func TestGetUsersByIds(t *testing.T) {
func TestGetUsersByIdsWithOptions(t *testing.T) {
t.Run("should only return specified users that have been updated since the given time", func(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
// Users before the timestamp shouldn't be returned
@@ -1559,7 +1559,7 @@ func TestGetUsersByUsernames(t *testing.T) {
}
func TestGetTotalUsersStat(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
total, _ := th.Server.Store.User().Count(model.UserCountOptions{
@@ -1574,7 +1574,7 @@ func TestGetTotalUsersStat(t *testing.T) {
}
func TestUpdateUser(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
user := th.CreateUser()
@@ -1737,7 +1737,7 @@ func TestPatchUser(t *testing.T) {
}
func TestUserUnicodeNames(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
Client := th.Client
@@ -1800,7 +1800,7 @@ func TestUserUnicodeNames(t *testing.T) {
}
func TestUpdateUserAuth(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
team := th.CreateTeamWithClient(th.SystemAdminClient)
@@ -2167,7 +2167,7 @@ func TestUpdateUserActive(t *testing.T) {
}
func TestGetUsers(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
rusers, resp := th.Client.GetUsers(0, 60, "")
@@ -3060,7 +3060,7 @@ func TestGetUserAudits(t *testing.T) {
}
func TestVerifyUserEmail(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
email := th.GenerateTestEmail()
@@ -4491,7 +4491,7 @@ func TestUserAccessTokenDisableConfig(t *testing.T) {
}
func TestUserAccessTokenDisableConfigBotsExcluded(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
th.App.UpdateConfig(func(cfg *model.Config) {
@@ -4872,7 +4872,7 @@ func TestPromoteGuestToUser(t *testing.T) {
}
func TestVerifyUserEmailWithoutToken(t *testing.T) {
th := Setup(t).InitBasic()
th := Setup(t)
defer th.TearDown()
t.Run("Should verify a new user", func(t *testing.T) {