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

executor: fix two data races in tests #11120

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
5 changes: 5 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,11 @@ func GetGlobalConfig() *Config {
return globalConf.Load().(*Config)
}

// StoreGlobalConfig stores a new config to the globalConf. It mostly uses in the test to avoid some data races.
func StoreGlobalConfig(config *Config) {
globalConf.Store(config)
}

// ReloadGlobalConfig reloads global configuration for this server.
func ReloadGlobalConfig() error {
confReloadLock.Lock()
Expand Down
33 changes: 32 additions & 1 deletion executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,27 @@ func (s *testSuite) TearDownSuite(c *C) {
s.store.Close()
}

func enablePessimisticTxn(enable bool) {
newConf := config.NewConfig()
newConf.PessimisticTxn.Enable = enable
config.StoreGlobalConfig(newConf)
}

func (s *testSuite) TestPessimisticSelectForUpdate(c *C) {
defer func() { enablePessimisticTxn(false) }()
enablePessimisticTxn(true)
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
tk.MustExec("drop table if exists t")
tk.MustExec("create table t(id int primary key, a int)")
tk.MustExec("insert into t values(1, 1)")
tk.MustExec("begin PESSIMISTIC")
tk.MustQuery("select a from t where id=1 for update").Check(testkit.Rows("1"))
tk.MustExec("update t set a=a+1 where id=1")
tk.MustExec("commit")
tk.MustQuery("select a from t where id=1").Check(testkit.Rows("2"))
}

func (s *testSuite) TearDownTest(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand Down Expand Up @@ -3960,6 +3981,12 @@ func (s *testOOMSuite) TestDistSQLMemoryControl(c *C) {
tk.Se.GetSessionVars().MemQuotaDistSQL = -1
}

func setOOMAction(action string) {
newConf := config.NewConfig()
newConf.OOMAction = action
config.StoreGlobalConfig(newConf)
}

func (s *testSuite) TestOOMPanicAction(c *C) {
tk := testkit.NewTestKit(c, s.store)
tk.MustExec("use test")
Expand All @@ -3971,7 +3998,11 @@ func (s *testSuite) TestOOMPanicAction(c *C) {
}
tk.Se.SetSessionManager(sm)
s.domain.ExpensiveQueryHandle().SetSessionManager(sm)
config.GetGlobalConfig().OOMAction = config.OOMActionCancel
orgAction := config.GetGlobalConfig().OOMAction
setOOMAction(config.OOMActionCancel)
defer func() {
setOOMAction(orgAction)
}()
tk.MustExec("set @@tidb_mem_quota_query=1;")
err := tk.QueryToErr("select sum(b) from t group by a;")
c.Assert(err, NotNil)
Expand Down