From 9bc7af0c5704bbf73f8240b4569d5ea215352e39 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 2 Oct 2017 03:50:56 -0500 Subject: Don't use global app for api / api4 tests (#7528) * don't use global app for api / api4 tests * put sleep back. we're gonna have to do some goroutine wrangling * fix oauth test config assumptions * jobs package, i'm comin' for you next * app test fix * try increasing sleep a little --- app/app.go | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'app/app.go') 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) { -- cgit v1.2.3-1-g7c22