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

ddl: make TestModifyColumnNullToNotNull test stable #13223

Merged
merged 3 commits into from
Nov 7, 2019
Merged
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
22 changes: 9 additions & 13 deletions ddl/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2695,48 +2695,44 @@ func (s *testDBSuite1) TestModifyColumnNullToNotNull(c *C) {
times := 0
hook := &ddl.TestDDLCallback{}
s.tk.MustExec("delete from t1")
hook.OnJobUpdatedExported = func(job *model.Job) {
var checkErr error
hook.OnJobRunBeforeExported = func(job *model.Job) {
if tbl.Meta().ID != job.TableID {
return
}
if job.State != model.JobStateRunning {
return
}
if times == 0 {
tk2.MustExec("insert into t1 values ();")
_, checkErr = tk2.Exec("insert into t1 values ();")
}
times++
}
s.dom.DDL().(ddl.DDLForTest).SetHook(hook)
_, err := s.tk.Exec("alter table t1 change c2 c2 int not null;")
c.Assert(checkErr, IsNil)
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[ddl:1138]Invalid use of NULL value")
s.tk.MustQuery("select * from t1").Check(testkit.Rows("<nil> <nil>"))

// Check insert error when column has prevent null flag.
// Check insert error when column has PreventNullInsertFlag.
s.tk.MustExec("delete from t1")
hook.OnJobUpdatedExported = nil
hook.OnJobRunBeforeExported = func(job *model.Job) {
if tbl.Meta().ID != job.TableID {
return
}
if job.State != model.JobStateRunning {
return
}
c2 := getModifyColumn()
if mysql.HasPreventNullInsertFlag(c2.Flag) {
_, err := tk2.Exec("insert into t1 values ();")
c.Assert(err.Error(), Equals, "[table:1048]Column 'c2' cannot be null")
}
// now c2 has PreventNullInsertFlag, an error is expected.
_, checkErr = tk2.Exec("insert into t1 values ();")
}

s.dom.DDL().(ddl.DDLForTest).SetHook(hook)
s.tk.MustExec("alter table t1 change c2 c2 bigint not null;")
c.Assert(checkErr.Error(), Equals, "[table:1048]Column 'c2' cannot be null")

c2 := getModifyColumn()
c.Assert(mysql.HasNotNullFlag(c2.Flag), IsTrue)
c.Assert(mysql.HasPreventNullInsertFlag(c2.Flag), IsFalse)
_, err = s.tk.Exec("insert into t1 values ();")
c.Assert(err, NotNil)
c.Assert(err.Error(), Equals, "[table:1364]Field 'c2' doesn't have a default value")
}

Expand Down