Skip to content

Remove TestMain from package pkg/sqlfs #1422

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

Closed
wangkuiyi opened this issue Dec 14, 2019 · 0 comments · Fixed by #1466
Closed

Remove TestMain from package pkg/sqlfs #1422

wangkuiyi opened this issue Dec 14, 2019 · 0 comments · Fixed by #1466
Assignees
Labels

Comments

@wangkuiyi
Copy link
Collaborator

In pkg/sqlfs/sqlfile_test.go, there defines a TestMain` function

func TestMain(m *testing.M) {
testDriver = getEnv("SQLFLOW_TEST_DB", "mysql")
var e error
switch testDriver {
case "mysql":
cfg := &mysql.Config{
User: getEnv("SQLFLOW_TEST_DB_MYSQL_USER", "root"),
Passwd: getEnv("SQLFLOW_TEST_DB_MYSQL_PASSWD", "root"),
Net: getEnv("SQLFLOW_TEST_DB_MYSQL_NET", "tcp"),
Addr: getEnv("SQLFLOW_TEST_DB_MYSQL_ADDR", "127.0.0.1:3306"),
AllowNativePasswords: true,
}
testDB, e = sql.Open("mysql", cfg.FormatDSN())
assertNoErr(e)
_, e = testDB.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s;", testDatabaseName))
assertNoErr(e)
defer testDB.Close()
case "hive":
testDB, e = sql.Open("hive", "root:root@localhost:10000/churn")
assertNoErr(e)
_, e = testDB.Exec(fmt.Sprintf("CREATE DATABASE IF NOT EXISTS %s;", testDatabaseName))
assertNoErr(e)
defer testDB.Close()
default:
assertNoErr(fmt.Errorf("unrecognized environment variable SQLFLOW_TEST_DB %s", testDriver))
}
os.Exit(m.Run())
}

Currently, we suffer from the fact that we have to restrict serial execution unit tests in our CI with go test -p 1 -- for more details, please refer to #1283 (comment)

The requirement of -p 1 is possibly due to the use of a global database and tables during testing. To remove the restriction, we can start from rewrite TestMain into a new and reusable function createDatabase. In each test case, we can call this function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants