unittest using externally managed database (#9400)
* MM-12083: unittest using externally managed database * cherry-pick Makefile changes from @cpanato * Jenkins changes (#9915) * add docker compose * udpate * when using minio dont need to set the region * update * add wait for it script * using old minio * add new jenkins file * update makefile * add dockerfile * rename the docker-compose proj to avoid colision (#9917) * rename the docker-compose proj to avoid colision * enable debug * enable debug to double checkt the branchs and fix docker-compose name (#9919) * add ee hash to check (#9920) * fix name (#9921) * update jenkins file to push from branch and prs * if a new push comes in stop the running build * split mysql and postgres variables * add script to run jenkins-like env in local dev env * update docker-compose project name to use uuid to make it more randon * fix DCNAME definition * update elasticsearch docker image * revert test * tidy up stages, and wait for mysql differently * update docker image and add check for postgres * checking if is ready * update docker compose to have a wait for deps * add readme and rename dockerfile * fix -unittest setup * using mm docker image * restore parallel unit tests at the package level Spin up a dedicated database for each package under test to avoid races in accessing the same tables. Simplify the interface for configuring the test database to just a DSN instead of multiple exports for each field. * try to work around root mysql access in CI * update local-test-env.sh too * MYSQL_ROOT_HOST: % * fix missing quotes * setting some memory limits for mysql * revert memory docker compose does not support * fix env name for postgres * expose errors in app/export_test.go * fix test label, better error checking on teardown * increase query timeout for tests * fix export_test * update local dev script * add configurable mysql root passwd
Этот коммит содержится в:
коммит произвёл
Carlos Tadeu Panato Junior
родитель
204dde9f48
Коммит
8374b6221e
@@ -15,23 +15,15 @@ import (
|
||||
"github.com/mattermost/mattermost-server/utils"
|
||||
)
|
||||
|
||||
var storeTypes = []*struct {
|
||||
type storeType struct {
|
||||
Name string
|
||||
Func func() (*storetest.RunningContainer, *model.SqlSettings, error)
|
||||
Container *storetest.RunningContainer
|
||||
SqlSettings *model.SqlSettings
|
||||
SqlSupplier *SqlSupplier
|
||||
Store store.Store
|
||||
}{
|
||||
{
|
||||
Name: "MySQL",
|
||||
Func: storetest.NewMySQLContainer,
|
||||
},
|
||||
{
|
||||
Name: "PostgreSQL",
|
||||
Func: storetest.NewPostgreSQLContainer,
|
||||
},
|
||||
}
|
||||
|
||||
var storeTypes []*storeType
|
||||
|
||||
func StoreTest(t *testing.T, f func(*testing.T, store.Store)) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
@@ -59,6 +51,15 @@ func StoreTestWithSqlSupplier(t *testing.T, f func(*testing.T, store.Store, stor
|
||||
}
|
||||
|
||||
func initStores() {
|
||||
storeTypes = append(storeTypes, &storeType{
|
||||
Name: "MySQL",
|
||||
SqlSettings: storetest.MakeSqlSettings(model.DATABASE_DRIVER_MYSQL),
|
||||
})
|
||||
storeTypes = append(storeTypes, &storeType{
|
||||
Name: "PostgreSQL",
|
||||
SqlSettings: storetest.MakeSqlSettings(model.DATABASE_DRIVER_POSTGRES),
|
||||
})
|
||||
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
tearDownStores()
|
||||
@@ -66,29 +67,18 @@ func initStores() {
|
||||
}
|
||||
}()
|
||||
var wg sync.WaitGroup
|
||||
errCh := make(chan error, len(storeTypes))
|
||||
wg.Add(len(storeTypes))
|
||||
for _, st := range storeTypes {
|
||||
st := st
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
container, settings, err := st.Func()
|
||||
if err != nil {
|
||||
errCh <- err
|
||||
return
|
||||
}
|
||||
st.Container = container
|
||||
st.SqlSupplier = NewSqlSupplier(*settings, nil)
|
||||
st.SqlSupplier = NewSqlSupplier(*st.SqlSettings, nil)
|
||||
st.Store = store.NewLayeredStore(st.SqlSupplier, nil, nil)
|
||||
st.Store.DropAllTables()
|
||||
st.Store.MarkSystemRanUnitTests()
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
select {
|
||||
case err := <-errCh:
|
||||
panic(err)
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
var tearDownStoresOnce sync.Once
|
||||
@@ -103,9 +93,6 @@ func tearDownStores() {
|
||||
if st.Store != nil {
|
||||
st.Store.Close()
|
||||
}
|
||||
if st.Container != nil {
|
||||
st.Container.Stop()
|
||||
}
|
||||
wg.Done()
|
||||
}()
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user