Fail vs. fatal on store startup (#24170)

If the store fails to initialize (e.g. run a migration), it would `log.Fatal` and then `os.Exit`. Unfortunately, this trips up `TestMain`, which happily keeps running tests, now guaranteed to fail.

Avoid this by instead returning an error from the store initialization, handling appropriately at the layer above.
Этот коммит содержится в:
Jesse Hallam
2023-08-04 23:05:01 -03:00
коммит произвёл GitHub
родитель c030bb44f5
Коммит e39b485c4b
11 изменённых файлов: 98 добавлений и 41 удалений

Просмотреть файл

@@ -12,6 +12,7 @@ import (
"github.com/mattermost/mattermost/server/v8/channels/store"
"github.com/mattermost/mattermost/server/v8/channels/store/sqlstore"
"github.com/mattermost/mattermost/server/v8/channels/store/storetest"
"golang.org/x/sync/errgroup"
)
type storeType struct {
@@ -91,23 +92,29 @@ func initStores() {
panic(err)
}
}()
var wg sync.WaitGroup
var eg errgroup.Group
for _, st := range storeTypes {
st := st
wg.Add(1)
go func() {
eg.Go(func() error {
var err error
defer wg.Done()
st.SqlStore = sqlstore.New(*st.SqlSettings, nil)
st.SqlStore, err = sqlstore.New(*st.SqlSettings, nil)
if err != nil {
return err
}
st.Store, err = NewLocalCacheLayer(st.SqlStore, nil, nil, getMockCacheProvider())
if err != nil {
panic(err)
return err
}
st.Store.DropAllTables()
st.Store.MarkSystemRanUnitTests()
}()
return nil
})
}
if err := eg.Wait(); err != nil {
panic(err)
}
wg.Wait()
}
var tearDownStoresOnce sync.Once