Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

*: fix DB connection close and all_mode integration test (#403) #436

Merged
merged 3 commits into from
Dec 18, 2019
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
12 changes: 11 additions & 1 deletion pkg/conn/baseconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package conn

import (
"database/sql"
"database/sql/driver"
"fmt"
"strings"

Expand Down Expand Up @@ -207,5 +208,14 @@ func (conn *BaseConn) close() error {
if conn == nil || conn.DBConn == nil {
return nil
}
return terror.ErrDBUnExpect.Delegate(conn.DBConn.Close(), "close")

err := conn.DBConn.Raw(func(dc interface{}) error {
// return an `ErrBadConn` to ensure close the connection, but do not put it back to the pool.
// if we choose to use `Close`, it will always put the connection back to the pool.
return driver.ErrBadConn
})
if err != driver.ErrBadConn {
return terror.ErrDBUnExpect.Delegate(err, "close")
}
return nil
}
27 changes: 27 additions & 0 deletions tests/_utils/check_http_alive
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash
# parameter 1: url, only GET method supported now
# parameter 2: text needs to be contained
# parameter 3: retry count, if check failed we will wait 1s before next retry, until retry time exceeds retry count

set -eu

url=$1
contain=$2
retry_count=$3

shift 3

counter=0
while [ $counter -lt $retry_count ]; do
got=$(curl -s $url | grep "$contain" | wc -l)
if [[ $got -gt 0 ]]; then
echo "HTTP $url is alive"
exit 0
fi
((counter+=1))
echo "wait for HTTP alive for $counter-th time"
sleep 1
done

echo "HTTP $url is not alive"
exit 1
5 changes: 5 additions & 0 deletions tests/all_mode/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set -eu
cur=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
source $cur/../_utils/test_prepare
WORK_DIR=$TEST_DIR/$TEST_NAME
API_VERSION="v1alpha1"

function run() {
export GO_FAILPOINTS="github.com/pingcap/dm/dm/worker/TaskCheckInterval=return(\"500ms\")"
Expand Down Expand Up @@ -34,6 +35,10 @@ function run() {
run_dm_worker $WORK_DIR/worker1 $WORKER1_PORT $cur/conf/dm-worker1.toml
run_dm_worker $WORK_DIR/worker2 $WORKER2_PORT $cur/conf/dm-worker2.toml

# wait for task running
check_http_alive 127.0.0.1:$MASTER_PORT/apis/${API_VERSION}/status/test '"name":"test","stage":"Running"' 10
sleep 2 # still wait for subtask running on other dm-workers

# kill tidb
pkill -hup tidb-server 2>/dev/null || true
wait_process_exit tidb-server
Expand Down