mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
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
This commit is contained in:
34
app/app.go
34
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) {
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -222,5 +222,7 @@ func (a *App) StopServer() {
|
||||
|
||||
a.ShutDownPlugins()
|
||||
|
||||
a.Srv = nil
|
||||
|
||||
l4g.Info(utils.T("api.server.stop_server.stopped.info"))
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user