Fixed correctness issues with harness.NewEngine

This commit is contained in:
Zach Musgrave
2023-06-06 15:04:24 -07:00
parent 99ded16534
commit e93f7ca52f
3 changed files with 48 additions and 29 deletions
@@ -1282,6 +1282,7 @@ func (d *DoltSession) CWBHeadRef(ctx *sql.Context, dbName string) (ref.DoltRef,
// CurrentHead returns the current head for the db named, which must be unqualifed. Used for bootstrap resolving the
// correct session head when a database name from the client is unqualified.
// TODO: audit uses, see if basename can be removed
func (d *DoltSession) CurrentHead(ctx *sql.Context, dbName string) (string, bool, error) {
dbName = strings.ToLower(dbName)
@@ -115,30 +115,37 @@ func TestSingleQuery(t *testing.T) {
// Convenience test for debugging a single query. Unskip and set to the desired query.
func TestSingleScript(t *testing.T) {
// t.Skip()
t.Skip()
var script = queries.ScriptTest{
Name: "committing to another branch on another database with dolt_transaction_commit",
SetUpScript: []string{
"create table t1 (a int)",
"call dolt_add('.')",
"call dolt_commit('-am', 'new table')",
"call dolt_branch('b1')",
"create database db1",
"use db1",
"create table t1 (a int)",
"call dolt_add('.')",
"call dolt_commit('-am', 'new table')",
"call dolt_branch('b1')",
"commit",
"use mydb/b1",
"set autocommit = 1",
"set dolt_transaction_commit = 1",
var scripts = []queries.ScriptTest{
{
Name: "ALTER TABLE RENAME COLUMN",
SetUpScript: []string{
"ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1);",
"ALTER TABLE parent RENAME COLUMN v1 TO v1_new;",
"ALTER TABLE child RENAME COLUMN v1 TO v1_new;",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "SHOW CREATE TABLE child;",
Expected: []sql.Row{{"child", "CREATE TABLE `child` (\n `id` int NOT NULL,\n `v1_new` int,\n `v2` int,\n PRIMARY KEY (`id`),\n KEY `v1` (`v1_new`),\n CONSTRAINT `fk1` FOREIGN KEY (`v1_new`) REFERENCES `parent` (`v1_new`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_bin"}},
},
},
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "insert into `db1/b1`.t1 values (1)",
ExpectedErrStr: "no changes to dolt_commit on database mydb",
{
Name: "ALTER TABLE MODIFY COLUMN type change not allowed",
SetUpScript: []string{
"ALTER TABLE child ADD CONSTRAINT fk1 FOREIGN KEY (v1) REFERENCES parent(v1);",
},
Assertions: []queries.ScriptTestAssertion{
{
Query: "ALTER TABLE parent MODIFY v1 MEDIUMINT;",
ExpectedErr: sql.ErrForeignKeyTypeChange,
},
{
Query: "ALTER TABLE child MODIFY v1 MEDIUMINT;",
ExpectedErr: sql.ErrForeignKeyTypeChange,
},
},
},
}
@@ -147,11 +154,14 @@ func TestSingleScript(t *testing.T) {
cleanup := installTestCommitClock(tcc)
defer cleanup()
sql.RunWithNowFunc(tcc.Now, func() error {
harness := newDoltHarness(t)
enginetest.TestScript(t, harness, script)
return nil
})
harness := newDoltHarness(t)
harness.Setup(setup.MydbData, setup.Parent_childData)
for _, script := range scripts {
sql.RunWithNowFunc(tcc.Now, func() error {
enginetest.TestScript(t, harness, script)
return nil
})
}
}
// Convenience test for debugging a single query. Unskip and set to the desired query.
@@ -163,7 +163,8 @@ func commitScripts(dbs []string) []setup.SetupScript {
// NewEngine creates a new *gms.Engine or calls reset and clear scripts on the existing
// engine for reuse.
func (d *DoltHarness) NewEngine(t *testing.T) (*gms.Engine, error) {
if d.engine == nil {
initializeEngine := d.engine == nil
if initializeEngine {
d.branchControl = branch_control.CreateDefaultController()
pro := d.newProvider()
@@ -172,7 +173,7 @@ func (d *DoltHarness) NewEngine(t *testing.T) (*gms.Engine, error) {
d.provider = doltProvider
var err error
d.session, err = dsess.NewDoltSession(enginetest.NewBaseSession(), doltProvider, d.multiRepoEnv.Config(), d.branchControl)
d.session, err = dsess.NewDoltSession(enginetest.NewBaseSession(), d.provider, d.multiRepoEnv.Config(), d.branchControl)
require.NoError(t, err)
e, err := enginetest.NewEngine(t, d, d.provider, d.setupData)
@@ -203,6 +204,13 @@ func (d *DoltHarness) NewEngine(t *testing.T) (*gms.Engine, error) {
d.engine.Analyzer.Catalog.MySQLDb = mysql_db.CreateEmptyMySQLDb()
d.engine.Analyzer.Catalog.MySQLDb.AddRootAccount()
// Get a fresh session if we are reusing the engine
if !initializeEngine {
var err error
d.session, err = dsess.NewDoltSession(enginetest.NewBaseSession(), d.provider, d.multiRepoEnv.Config(), d.branchControl)
require.NoError(t, err)
}
ctx := enginetest.NewContext(d)
e, err := enginetest.RunSetupScripts(ctx, d.engine, d.resetScripts(), d.SupportsNativeIndexCreation())