2018-01-26 09:03:38 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2018-03-13 20:38:35 +00:00
|
|
|
set -x
|
2018-01-26 09:03:38 +00:00
|
|
|
set -o errexit
|
|
|
|
set -o pipefail
|
|
|
|
|
|
|
|
CUR_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
ROOT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && cd ../.. && pwd)
|
|
|
|
DATA_DIR=${DATA_DIR:=/tmp/clickhouse}
|
|
|
|
LOG_DIR=${LOG_DIR:=$DATA_DIR/log}
|
|
|
|
BUILD_DIR=${BUILD_DIR:=$ROOT_DIR/build${BUILD_TYPE}}
|
2018-05-11 14:16:16 +00:00
|
|
|
export CLICKHOUSE_BINARY=${CLICKHOUSE_BINARY:="clickhouse"}
|
|
|
|
[ -x "$CUR_DIR/clickhouse-server" ] && [ -x "${CUR_DIR}/${CLICKHOUSE_BINARY}-client" ] && BIN_DIR= # Allow run in /usr/bin
|
2018-05-17 17:55:07 +00:00
|
|
|
[ -x "$BUILD_DIR/dbms/src/Server/${CLICKHOUSE_BINARY}-server" ] && BIN_DIR=${BIN_DIR:=$BUILD_DIR/dbms/src/Server/}
|
2018-05-11 14:16:16 +00:00
|
|
|
[ -f "$CUR_DIR/server-test.xml" ] && CONFIG_DIR=${CONFIG_DIR=$CUR_DIR}/
|
|
|
|
CONFIG_CLIENT_DIR=${CONFIG_CLIENT_DIR=$CONFIG_DIR}
|
|
|
|
CONFIG_SERVER_DIR=${CONFIG_SERVER_DIR=$CONFIG_DIR}
|
2018-01-26 09:03:38 +00:00
|
|
|
[ ! -f "${CONFIG_CLIENT_DIR}client-test.xml" ] && CONFIG_CLIENT_DIR=${CONFIG_CLIENT_DIR:=/etc/clickhouse-client/}
|
|
|
|
[ ! -f "${CONFIG_SERVER_DIR}server-test.xml" ] && CONFIG_SERVER_DIR=${CONFIG_SERVER_DIR:=/etc/clickhouse-server/}
|
|
|
|
CONFIG_CLIENT=${CONFIG_CLIENT:=${CONFIG_CLIENT_DIR}client-test.xml}
|
|
|
|
export CLICKHOUSE_CONFIG=${CLICKHOUSE_CONFIG:=${CONFIG_SERVER_DIR}server-test.xml}
|
2018-05-11 14:16:16 +00:00
|
|
|
[ -x "$CUR_DIR/clickhouse-test" ] && TEST_DIR=${TEST_DIR=$CUR_DIR/}
|
|
|
|
[ -d "$CUR_DIR/queries" ] && QUERIES_DIR=${QUERIES_DIR=$CUR_DIR/queries}
|
2018-05-25 18:13:48 +00:00
|
|
|
[ ! -d "$QUERIES_DIR" ] && [ -d "/usr/local/share/clickhouse-test/queries" ] && QUERIES_DIR=${QUERIES_DIR=/usr/local/share/clickhouse-test/queries}
|
|
|
|
[ ! -d "$QUERIES_DIR" ] && [ -d "/usr/share/clickhouse-test/queries" ] && QUERIES_DIR=${QUERIES_DIR=/usr/share/clickhouse-test/queries}
|
2018-05-11 14:16:16 +00:00
|
|
|
CLICKHOUSE_EXTRACT_CONFIG=${CLICKHOUSE_EXTRACT_CONFIG:="${BIN_DIR}${CLICKHOUSE_BINARY}-extract-from-config --config=$CLICKHOUSE_CONFIG"}
|
2018-01-26 09:03:38 +00:00
|
|
|
|
2018-05-25 20:52:20 +00:00
|
|
|
PORT_RANDOM=${PORT_RANDOM=1}
|
|
|
|
if [ "${PORT_RANDOM}" ]; then
|
|
|
|
CLICKHOUSE_PORT_BASE=${CLICKHOUSE_PORT_BASE:=$(( ( RANDOM % 50000 ) + 10000 ))}
|
|
|
|
CLICKHOUSE_PORT_TCP=${CLICKHOUSE_PORT_TCP:=$(($CLICKHOUSE_PORT_BASE + 1))}
|
|
|
|
CLICKHOUSE_PORT_HTTP=${CLICKHOUSE_PORT_HTTP:=$(($CLICKHOUSE_PORT_BASE + 2))}
|
|
|
|
CLICKHOUSE_PORT_INTERSERVER=${CLICKHOUSE_PORT_INTERSERVER:=$(($CLICKHOUSE_PORT_BASE + 3))}
|
|
|
|
CLICKHOUSE_PORT_TCP_SECURE=${CLICKHOUSE_PORT_TCP_SECURE:=$(($CLICKHOUSE_PORT_BASE + 4))}
|
|
|
|
CLICKHOUSE_PORT_HTTPS=${CLICKHOUSE_PORT_HTTPS:=$(($CLICKHOUSE_PORT_BASE + 5))}
|
|
|
|
fi
|
|
|
|
|
|
|
|
export CLICKHOUSE_PORT_TCP=${CLICKHOUSE_PORT_TCP:=`$CLICKHOUSE_EXTRACT_CONFIG --key=tcp_port`}
|
|
|
|
export CLICKHOUSE_PORT_HTTP=${CLICKHOUSE_PORT_HTTP:=`$CLICKHOUSE_EXTRACT_CONFIG --key=http_port`}
|
|
|
|
export CLICKHOUSE_PORT_INTERSERVER=${CLICKHOUSE_PORT_INTERSERVER:=`$CLICKHOUSE_EXTRACT_CONFIG --key=interserver_http_port`}
|
|
|
|
export CLICKHOUSE_PORT_TCP_SECURE=${CLICKHOUSE_PORT_TCP_SECURE:=`$CLICKHOUSE_EXTRACT_CONFIG --key=tcp_port_secure`}
|
|
|
|
export CLICKHOUSE_PORT_HTTPS=${CLICKHOUSE_PORT_HTTPS:=`$CLICKHOUSE_EXTRACT_CONFIG --key=https_port`}
|
|
|
|
|
|
|
|
|
2018-01-26 09:03:38 +00:00
|
|
|
rm -rf $DATA_DIR
|
2018-03-14 16:57:15 +00:00
|
|
|
mkdir -p $LOG_DIR
|
2018-01-26 09:03:38 +00:00
|
|
|
|
2018-05-17 17:55:07 +00:00
|
|
|
DHPARAM=`$CLICKHOUSE_EXTRACT_CONFIG --key=openSSL.server.dhParamsFile`
|
|
|
|
PRIVATEKEY=`${BIN_DIR}clickhouse-extract-from-config --config=$CLICKHOUSE_CONFIG --key=openSSL.server.privateKeyFile`
|
|
|
|
CERT=`${BIN_DIR}clickhouse-extract-from-config --config=$CLICKHOUSE_CONFIG --key=openSSL.server.certificateFile`
|
|
|
|
# Do not generate in case broken extract-config
|
|
|
|
[ -n "$DHPARAM" ] && openssl dhparam -out $DHPARAM 256
|
|
|
|
[ -n "$PRIVATEKEY" ] && [ -n "$CERT" ] && openssl req -subj "/CN=localhost" -new -newkey rsa:2048 -days 365 -nodes -x509 -keyout $PRIVATEKEY -out $CERT
|
2018-01-26 09:03:38 +00:00
|
|
|
|
2018-03-15 15:09:44 +00:00
|
|
|
if [ "$TEST_GDB" ]; then
|
|
|
|
echo -e "run \nset pagination off \nset logging file $DATA_DIR/gdb.log \nset logging on \nthread apply all backtrace \ndetach \nquit " > $DATA_DIR/gdb.cmd
|
|
|
|
GDB="gdb -x $DATA_DIR/gdb.cmd --args "
|
|
|
|
fi
|
|
|
|
|
2018-01-26 09:03:38 +00:00
|
|
|
# Start a local clickhouse server which will be used to run tests
|
|
|
|
#PATH=$PATH:$BIN_DIR \
|
2018-05-25 20:52:20 +00:00
|
|
|
$GDB ${BIN_DIR}clickhouse-server --config-file=$CLICKHOUSE_CONFIG -- --http_port=$CLICKHOUSE_PORT_HTTP --tcp_port=$CLICKHOUSE_PORT_TCP --https_port=$CLICKHOUSE_PORT_HTTPS --tcp_port_secure=$CLICKHOUSE_PORT_TCP_SECURE --interserver_http_port=$CLICKHOUSE_PORT_INTERSERVER > $LOG_DIR/stdout 2>&1 &
|
2018-01-26 09:03:38 +00:00
|
|
|
CH_PID=$!
|
|
|
|
sleep 3
|
|
|
|
|
2018-03-15 15:09:44 +00:00
|
|
|
if [ "$GDB" ]; then
|
|
|
|
# Long symbols read
|
|
|
|
sleep 40
|
|
|
|
fi
|
|
|
|
|
2018-03-13 19:49:21 +00:00
|
|
|
tail -n50 $LOG_DIR/*
|
|
|
|
|
2018-01-26 09:03:38 +00:00
|
|
|
# Define needed stuff to kill test clickhouse server after tests completion
|
|
|
|
function finish {
|
2018-03-15 15:09:44 +00:00
|
|
|
kill $CH_PID || true
|
|
|
|
wait
|
|
|
|
tail -n 50 $LOG_DIR/*
|
|
|
|
if [ "$GDB" ]; then
|
|
|
|
cat $DATA_DIR/gdb.log || true
|
|
|
|
fi
|
|
|
|
rm -rf $DATA_DIR
|
2018-01-26 09:03:38 +00:00
|
|
|
}
|
2018-03-13 19:49:21 +00:00
|
|
|
trap finish EXIT SIGINT SIGQUIT SIGTERM
|
2018-01-26 09:03:38 +00:00
|
|
|
|
|
|
|
# Do tests
|
|
|
|
if [ -n "$*" ]; then
|
|
|
|
$*
|
|
|
|
else
|
2018-05-11 14:16:16 +00:00
|
|
|
TEST_RUN=${TEST_RUN=1}
|
|
|
|
TEST_PERF=${TEST_PERF=1}
|
2018-05-25 20:52:20 +00:00
|
|
|
${BIN_DIR}clickhouse-client --config ${CONFIG_CLIENT} --port $CLICKHOUSE_PORT_TCP -q 'SELECT * from system.build_options;'
|
2018-05-11 14:16:16 +00:00
|
|
|
[ "$TEST_RUN" ] && env PATH=$PATH:$BIN_DIR ${TEST_DIR}clickhouse-test --binary ${BIN_DIR}clickhouse --configclient $CONFIG_CLIENT --configserver $CLICKHOUSE_CONFIG --tmp $DATA_DIR/tmp --queries $QUERIES_DIR $TEST_OPT0 $TEST_OPT
|
2018-05-25 20:52:20 +00:00
|
|
|
( [ "$TEST_PERF" ] && ${BIN_DIR}clickhouse-performance-test --port $CLICKHOUSE_PORT_TCP --r $CUR_DIR/performance --skip-tags=long $* ) || true
|
2018-01-26 09:03:38 +00:00
|
|
|
fi
|