From 34285d8cca93fc0f473636e78680fade03f26bda Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 16 Oct 2017 08:09:43 -0700 Subject: parallel tests (#7629) --- app/apptestlib.go | 45 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 deletions(-) (limited to 'app/apptestlib.go') diff --git a/app/apptestlib.go b/app/apptestlib.go index 09bf02d39..9c26e0bbb 100644 --- a/app/apptestlib.go +++ b/app/apptestlib.go @@ -7,6 +7,9 @@ import ( "time" "github.com/mattermost/mattermost-server/model" + "github.com/mattermost/mattermost-server/store" + "github.com/mattermost/mattermost-server/store/sqlstore" + "github.com/mattermost/mattermost-server/store/storetest" "github.com/mattermost/mattermost-server/utils" l4g "github.com/alecthomas/log4go" @@ -21,13 +24,47 @@ type TestHelper struct { BasicPost *model.Post } +type persistentTestStore struct { + store.Store +} + +func (*persistentTestStore) Close() {} + +var testStoreContainer *storetest.RunningContainer +var testStore *persistentTestStore + +// UseTestStore sets the container and corresponding settings to use for tests. Once the tests are +// complete (e.g. at the end of your TestMain implementation), you should call StopTestStore. +func UseTestStore(container *storetest.RunningContainer, settings *model.SqlSettings) { + testStoreContainer = container + testStore = &persistentTestStore{store.NewLayeredStore(sqlstore.NewSqlSupplier(*settings, nil), nil, nil)} +} + +func StopTestStore() { + if testStoreContainer != nil { + testStoreContainer.Stop() + testStoreContainer = nil + } +} + func setupTestHelper(enterprise bool) *TestHelper { - utils.TranslationsPreInit() + if utils.T == nil { + utils.TranslationsPreInit() + } utils.LoadConfig("config.json") utils.InitTranslations(utils.Cfg.LocalizationSettings) + var options []Option + if testStore != nil { + options = append(options, StoreOverride(testStore)) + options = append(options, ConfigOverride(func(cfg *model.Config) { + cfg.ServiceSettings.ListenAddress = new(string) + *cfg.ServiceSettings.ListenAddress = ":0" + })) + } + th := &TestHelper{ - App: New(), + App: New(options...), } *utils.Cfg.TeamSettings.MaxUsersPerTeam = 50 @@ -188,4 +225,8 @@ func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) { func (me *TestHelper) TearDown() { me.App.Shutdown() + if err := recover(); err != nil { + StopTestStore() + panic(err) + } } -- cgit v1.2.3-1-g7c22