From aa1af795aa9941f7ff424dd2985b298e83287dab Mon Sep 17 00:00:00 2001 From: 5kbpers Date: Fri, 10 Jan 2020 17:13:28 +0800 Subject: [PATCH] fix test log Signed-off-by: 5kbpers --- tests/br_insert_after_restore/run.sh | 82 ++++++++++++++++++++++++++++ tests/run.sh | 2 +- 2 files changed, 83 insertions(+), 1 deletion(-) create mode 100755 tests/br_insert_after_restore/run.sh diff --git a/tests/br_insert_after_restore/run.sh b/tests/br_insert_after_restore/run.sh new file mode 100755 index 000000000..ea17b1452 --- /dev/null +++ b/tests/br_insert_after_restore/run.sh @@ -0,0 +1,82 @@ +#!/bin/sh +# +# Copyright 2019 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, +# See the License for the specific language governing permissions and +# limitations under the License. + +set -eu +DB="$TEST_NAME" +TABLE="usertable" +ROW_COUNT=10 +PATH="tests/$TEST_NAME:bin:$PATH" + +insertRecords() { + for i in $(seq $1); do + run_sql "INSERT INTO $DB.$TABLE VALUES ('$i');" + done +} + +createTable() { + run_sql "CREATE TABLE IF NOT EXISTS $DB.$TABLE (c1 CHAR(255));" +} + +echo "load data..." +echo "create database" +run_sql "CREATE DATABASE IF NOT EXISTS $DB;" +echo "create table" +createTable +echo "insert records" +insertRecords $ROW_COUNT + +row_count_ori=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') + +# backup full +echo "backup start..." +run_br --pd $PD_ADDR backup full -s "local://$TEST_DIR/$DB" --ratelimit 5 --concurrency 4 + +run_sql "DROP DATABASE $DB;" + +# restore full +echo "restore start..." +run_br restore full -s "local://$TEST_DIR/$DB" --pd $PD_ADDR + +row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') + +fail=false +if [ "${row_count_ori}" != "${row_count_new}" ];then + fail=true + echo "TEST: [$TEST_NAME] fail on database $DB" +fi +echo "database $DB [original] row count: ${row_count_ori}, [after br] row count: ${row_count_new}" + +if $fail; then + echo "TEST: [$TEST_NAME] failed!" + exit 1 +fi + +# insert records +insertRecords $ROW_COUNT +row_count_new=$(run_sql "SELECT COUNT(*) FROM $DB.$TABLE;" | awk '/COUNT/{print $2}') +fail=false +if [ "${row_count_ori}" != "$(expr $row_count_new \* 2)" ];then + fail=true + echo "TEST: [$TEST_NAME] fail on inserting records to database $DB after restore: ${row_count_new}" +fi + +if $fail; then + echo "TEST: [$TEST_NAME] failed!" + exit 1 +else + echo "TEST: [$TEST_NAME] successed!" +fi + +run_sql "DROP DATABASE $DB;" diff --git a/tests/run.sh b/tests/run.sh index 3cedc7093..f79dc4cf0 100755 --- a/tests/run.sh +++ b/tests/run.sh @@ -100,7 +100,7 @@ if [ "${1-}" = '--debug' ]; then read line fi -for script in tests/*/run.sh; do +for script in tests/br_insert_after_restore/run.sh; do echo "*===== Running test $script... =====*" TEST_DIR="$TEST_DIR" \ PD_ADDR="$PD_ADDR" \