summaryrefslogtreecommitdiffstats
path: root/app/app.go
diff options
context:
space:
mode:
authorChris <ccbrown112@gmail.com>2017-10-02 03:50:56 -0500
committerGeorge Goldberg <george@gberg.me>2017-10-02 09:50:56 +0100
commit9bc7af0c5704bbf73f8240b4569d5ea215352e39 (patch)
treeb17ddafc83ab43ccdce2116e83358299a08a50a6 /app/app.go
parentb84736e9b6401df0c6eeab9950bef09458a6aefd (diff)
downloadchat-9bc7af0c5704bbf73f8240b4569d5ea215352e39.tar.gz
chat-9bc7af0c5704bbf73f8240b4569d5ea215352e39.tar.bz2
chat-9bc7af0c5704bbf73f8240b4569d5ea215352e39.zip
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
Diffstat (limited to 'app/app.go')
-rw-r--r--app/app.go34
1 files changed, 33 insertions, 1 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) {