MM-28067: Optimize app server startup in tests (#16263)
* MM-28067: Optimize app server startup in tests For every test, we would wipe out the database and then start the server again. This would run through all the migrations and create new rows in Systems and Roles table every time. As a result, this was consuming a lot of setup time for every test. We optimize this by preloading the DB with dummy data in the roles and systems table so that the server code just skips over those migrations. This is completely forward compatible and adding new migrations does not need to generate the sql files again. Only in case of schema changes to the roles or systems table, this would need to be done. It is unlikely the Systems table schema will get changed. The Roles table might change in future but it's a comparatively rare event. Given the reduction in CI runtime we are seeing, it's a worthy optimization. We also apply some more optimizations: - Coalesce multiple UpdateConfig calls into a single one. Each UpdateConfig call has to do a json marshal which would take precious CPU cycles. It's much more efficient to do everything in a single call. - Remove unnecessary debug.FreeOSMemory in reload config. This was an artifact from old days and is no longer required. Numbers: Results show a full **2 minutes** shaved off the test runtime. Earlier, tests would take around 16 minutes. Now they take 14 minutes. ```release-note NONE ``` * fix app package
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e162c6c787
Коммит
c82c37a36e
@@ -130,30 +130,26 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
||||
// Disable sniffing, otherwise elastic client fails to connect to docker node
|
||||
// More details: https://github.com/olivere/elastic/wiki/Sniffing
|
||||
*cfg.ElasticsearchSettings.Sniff = false
|
||||
})
|
||||
prevListenAddress := *th.App.Config().ServiceSettings.ListenAddress
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = ":0" })
|
||||
if err := th.Server.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.ListenAddress = prevListenAddress })
|
||||
Init(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
InitLocal(th.Server, th.Server.AppOptions, th.App.Srv().LocalRouter)
|
||||
web.New(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
wsapi.Init(th.App.Srv())
|
||||
th.App.DoAppMigrations()
|
||||
*cfg.TeamSettings.EnableOpenServer = true
|
||||
|
||||
th.App.UpdateConfig(func(cfg *model.Config) { *cfg.TeamSettings.EnableOpenServer = true })
|
||||
|
||||
// Disable strict password requirements for test
|
||||
th.App.UpdateConfig(func(cfg *model.Config) {
|
||||
// Disable strict password requirements for test
|
||||
*cfg.PasswordSettings.MinimumLength = 5
|
||||
*cfg.PasswordSettings.Lowercase = false
|
||||
*cfg.PasswordSettings.Uppercase = false
|
||||
*cfg.PasswordSettings.Symbol = false
|
||||
*cfg.PasswordSettings.Number = false
|
||||
|
||||
*cfg.ServiceSettings.ListenAddress = ":0"
|
||||
})
|
||||
if err := th.Server.Start(); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
Init(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
InitLocal(th.Server, th.Server.AppOptions, th.App.Srv().LocalRouter)
|
||||
web.New(th.Server, th.Server.AppOptions, th.App.Srv().Router)
|
||||
wsapi.Init(th.App.Srv())
|
||||
|
||||
if enterprise {
|
||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||
@@ -197,6 +193,7 @@ func SetupEnterprise(tb testing.TB) *TestHelper {
|
||||
dbStore := mainHelper.GetStore()
|
||||
dbStore.DropAllTables()
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, true, true, nil)
|
||||
th.InitLogin()
|
||||
@@ -215,6 +212,7 @@ func Setup(tb testing.TB) *TestHelper {
|
||||
dbStore := mainHelper.GetStore()
|
||||
dbStore.DropAllTables()
|
||||
dbStore.MarkSystemRanUnitTests()
|
||||
mainHelper.PreloadMigrations()
|
||||
searchEngine := mainHelper.GetSearchEngine()
|
||||
th := setupTestHelper(dbStore, searchEngine, false, true, nil)
|
||||
th.InitLogin()
|
||||
|
||||
Ссылка в новой задаче
Block a user