diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/app.go | 34 | ||||
-rw-r--r-- | app/apptestlib.go | 16 | ||||
-rw-r--r-- | app/server.go | 2 | ||||
-rw-r--r-- | app/webhook_test.go | 2 |
4 files changed, 43 insertions, 11 deletions
diff --git a/app/app.go b/app/app.go index 26388d841..508c652c1 100644 --- a/app/app.go +++ b/app/app.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net/http" "sync" + "time" "github.com/mattermost/mattermost-server/einterfaces" ejobs "github.com/mattermost/mattermost-server/einterfaces/jobs" @@ -44,15 +45,46 @@ var globalApp App = App{ Jobs: &jobs.JobServer{}, } +var appCount = 0 var initEnterprise sync.Once -func Global() *App { +var UseGlobalApp = true + +// New creates a new App. You must call Shutdown when you're done with it. +// XXX: Doesn't necessarily create a new App yet. +func New() *App { + appCount++ + + if !UseGlobalApp { + if appCount > 1 { + panic("Only one App should exist at a time. Did you forget to call Shutdown()?") + } + app := &App{ + Jobs: &jobs.JobServer{}, + } + app.initEnterprise() + return app + } + initEnterprise.Do(func() { globalApp.initEnterprise() }) return &globalApp } +func (a *App) Shutdown() { + appCount-- + if appCount == 0 { + // XXX: This is to give all of our runaway goroutines time to complete. + // We should wrangle them up and remove this. + time.Sleep(time.Second) + + if a.Srv != nil { + a.StopServer() + } + } +} + var accountMigrationInterface func(*App) einterfaces.AccountMigrationInterface func RegisterAccountMigrationInterface(f func(*App) einterfaces.AccountMigrationInterface) { diff --git a/app/apptestlib.go b/app/apptestlib.go index 67a380f2d..29139ac39 100644 --- a/app/apptestlib.go +++ b/app/apptestlib.go @@ -23,7 +23,7 @@ type TestHelper struct { func setupTestHelper(enterprise bool) *TestHelper { th := &TestHelper{ - App: Global(), + App: New(), } if th.App.Srv == nil { @@ -62,9 +62,9 @@ func Setup() *TestHelper { func (me *TestHelper) InitBasic() *TestHelper { me.BasicTeam = me.CreateTeam() me.BasicUser = me.CreateUser() - me.App.LinkUserToTeam(me.BasicUser, me.BasicTeam) + me.LinkUserToTeam(me.BasicUser, me.BasicTeam) me.BasicUser2 = me.CreateUser() - me.App.LinkUserToTeam(me.BasicUser2, me.BasicTeam) + me.LinkUserToTeam(me.BasicUser2, me.BasicTeam) me.BasicChannel = me.CreateChannel(me.BasicTeam) me.BasicPost = me.CreatePost(me.BasicChannel) @@ -175,10 +175,10 @@ func (me *TestHelper) CreatePost(channel *model.Channel) *model.Post { return post } -func (a *App) LinkUserToTeam(user *model.User, team *model.Team) { +func (me *TestHelper) LinkUserToTeam(user *model.User, team *model.Team) { utils.DisableDebugLogForTest() - err := a.JoinUserToTeam(team, user, "") + err := me.App.JoinUserToTeam(team, user, "") if err != nil { l4g.Error(err.Error()) l4g.Close() @@ -189,8 +189,6 @@ func (a *App) LinkUserToTeam(user *model.User, team *model.Team) { utils.EnableDebugLogForTest() } -func (a *App) TearDown() { - if a.Srv != nil { - a.StopServer() - } +func (me *TestHelper) TearDown() { + me.App.Shutdown() } diff --git a/app/server.go b/app/server.go index 6915369c4..3df6a39bb 100644 --- a/app/server.go +++ b/app/server.go @@ -222,5 +222,7 @@ func (a *App) StopServer() { a.ShutDownPlugins() + a.Srv = nil + l4g.Info(utils.T("api.server.stop_server.stopped.info")) } diff --git a/app/webhook_test.go b/app/webhook_test.go index 0a6bd0fb5..5699addbf 100644 --- a/app/webhook_test.go +++ b/app/webhook_test.go @@ -12,7 +12,7 @@ import ( func TestCreateWebhookPost(t *testing.T) { th := Setup().InitBasic() - defer th.App.TearDown() + defer th.TearDown() enableIncomingHooks := utils.Cfg.ServiceSettings.EnableIncomingWebhooks defer func() { |