Files
tidb/executor/simple_test.go

74 lines
2.5 KiB
Go

// Copyright 2016 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package executor_test
import (
"strconv"
"testing"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/util"
)
func TestKillStmt(t *testing.T) {
store := testkit.CreateMockStore(t)
originCfg := config.GetGlobalConfig()
newCfg := *originCfg
newCfg.EnableGlobalKill = false
config.StoreGlobalConfig(&newCfg)
defer func() {
config.StoreGlobalConfig(originCfg)
}()
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")
sm := &mockSessionManager{
serverID: 0,
}
tk.Session().SetSessionManager(sm)
tk.MustExec("kill 1")
result := tk.MustQuery("show warnings")
result.Check(testkit.Rows("Warning 1105 Invalid operation. Please use 'KILL TIDB [CONNECTION | QUERY] connectionID' instead"))
newCfg2 := *originCfg
newCfg2.EnableGlobalKill = true
config.StoreGlobalConfig(&newCfg2)
// ZERO serverID, treated as truncated.
tk.MustExec("kill 1")
result = tk.MustQuery("show warnings")
result.Check(testkit.Rows("Warning 1105 Kill failed: Received a 32bits truncated ConnectionID, expect 64bits. Please execute 'KILL [CONNECTION | QUERY] ConnectionID' to send a Kill without truncating ConnectionID."))
// truncated
sm.SetServerID(1)
tk.MustExec("kill 101")
result = tk.MustQuery("show warnings")
result.Check(testkit.Rows("Warning 1105 Kill failed: Received a 32bits truncated ConnectionID, expect 64bits. Please execute 'KILL [CONNECTION | QUERY] ConnectionID' to send a Kill without truncating ConnectionID."))
// excceed int64
tk.MustExec("kill 9223372036854775808") // 9223372036854775808 == 2^63
result = tk.MustQuery("show warnings")
result.Check(testkit.Rows("Warning 1105 Parse ConnectionID failed: Unexpected connectionID excceeds int64"))
// local kill
connID := util.NewGlobalConnID(1, true)
tk.MustExec("kill " + strconv.FormatUint(connID.ID(), 10))
result = tk.MustQuery("show warnings")
result.Check(testkit.Rows())
// remote kill is tested in `tests/globalkilltest`
}