Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test database import across a matrix of input/output backends #696

Merged
merged 1 commit into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 47 additions & 36 deletions tests/integration/golang/database/import_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ type ImportTestSuite struct {
runs []*models.Run
inputRunFixtures *fixtures.RunFixtures
outputRunFixtures *fixtures.RunFixtures
inputBackend string
outputBackend string
inputDB *gorm.DB
outputDB *gorm.DB
populatedRowCounts rowCounts
Expand All @@ -42,9 +44,9 @@ func TestImportTestSuite(t *testing.T) {
suite.Run(t, new(ImportTestSuite))
}

func (s *ImportTestSuite) SetupTest() {
func (s *ImportTestSuite) SetupSubTest() {
// prepare input database.
dsn, err := helpers.GenerateDatabaseURI(s.T(), helpers.GetInputDatabaseBackend())
dsn, err := helpers.GenerateDatabaseURI(s.T(), s.inputBackend)
s.Require().Nil(err)
db, err := database.NewDBProvider(
dsn,
Expand All @@ -63,7 +65,7 @@ func (s *ImportTestSuite) SetupTest() {
s.populateDB(s.inputDB)

// prepare output database.
dsn, err = helpers.GenerateDatabaseURI(s.T(), helpers.GetOutputDatabaseBackend())
dsn, err = helpers.GenerateDatabaseURI(s.T(), s.outputBackend)
s.Require().Nil(err)
db, err = database.NewDBProvider(
dsn,
Expand Down Expand Up @@ -164,44 +166,53 @@ func (s *ImportTestSuite) populateDB(db *gorm.DB) {
s.Require().Nil(err)
}

func (s *ImportTestSuite) TearDownTest() {
func (s *ImportTestSuite) TearDownSubTest() {
s.Require().Nil(s.inputRunFixtures.TruncateTables())
s.Require().Nil(s.outputRunFixtures.TruncateTables())
}

func (s *ImportTestSuite) Test_Ok() {
// source DB should have expected
s.validateRowCounts(s.inputDB, s.populatedRowCounts)

// initially, dest DB is empty
s.validateRowCounts(s.outputDB, rowCounts{namespaces: 1, experiments: 1})

// invoke the Importer.Import() method
importer := database.NewImporter(s.inputDB, s.outputDB)
s.Require().Nil(importer.Import())

// dest DB should now have the expected
s.validateRowCounts(s.outputDB, s.populatedRowCounts)

// invoke the Importer.Import method a 2nd time
s.Require().Nil(importer.Import())

// dest DB should still only have the expected (idempotent)
s.validateRowCounts(s.outputDB, s.populatedRowCounts)

// confirm row-for-row equality
for _, table := range []string{
"namespaces",
"apps",
"dashboards",
"experiment_tags",
"runs",
"tags",
"params",
"metrics",
"latest_metrics",
} {
s.validateTable(s.inputDB, s.outputDB, table)
backends := []string{"sqlite", "sqlcipher", "postgres"}
for _, inputBackend := range backends {
for _, outputBackend := range backends {
s.inputBackend = inputBackend
s.outputBackend = outputBackend
s.Run(inputBackend+"->"+outputBackend, func() {
// source DB should have expected
s.validateRowCounts(s.inputDB, s.populatedRowCounts)

// initially, dest DB is empty
s.validateRowCounts(s.outputDB, rowCounts{namespaces: 1, experiments: 1})

// invoke the Importer.Import() method
importer := database.NewImporter(s.inputDB, s.outputDB)
s.Require().Nil(importer.Import())

// dest DB should now have the expected
s.validateRowCounts(s.outputDB, s.populatedRowCounts)

// invoke the Importer.Import method a 2nd time
s.Require().Nil(importer.Import())

// dest DB should still only have the expected (idempotent)
s.validateRowCounts(s.outputDB, s.populatedRowCounts)

// confirm row-for-row equality
for _, table := range []string{
"namespaces",
"apps",
"dashboards",
"experiment_tags",
"runs",
"tags",
"params",
"metrics",
"latest_metrics",
} {
s.validateTable(s.inputDB, s.outputDB, table)
}
})
}
}
}

Expand Down
16 changes: 0 additions & 16 deletions tests/integration/golang/helpers/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,6 @@ func GetDatabaseBackend() string {
return defaultDatabaseBackend
}

func GetInputDatabaseBackend() string {
uri, ok := os.LookupEnv("FML_INPUT_DATABASE_BACKEND")
if ok {
return uri
}
return defaultDatabaseBackend
}

func GetOutputDatabaseBackend() string {
uri, ok := os.LookupEnv("FML_OUTPUT_DATABASE_BACKEND")
if ok {
return uri
}
return defaultDatabaseBackend
}

func GetPostgresUri() string {
uri, ok := os.LookupEnv("FML_POSTGRES_URI")
if ok {
Expand Down