#!/bin/bash
set -e
if [ -z "$TI_PARAM_STR_passowrd" ]; then 
    ./bin/randgen-test --host $TI_PARAM_STR_host --user $TI_PARAM_STR_user --port $TI_PARAM_STR_port
else
    ./bin/randgen-test --host $TI_PARAM_STR_host --user $TI_PARAM_STR_user --port $TI_PARAM_STR_port --password $TI_PARAM_STR_passowrd
fi
EXIT_CODE=$?


tc_name=$(echo $TI_PARAM_RES_tc | jq -r .name)
testbed=$(echo $TI_PARAM_RES_tc | jq -r .testbed)
tidb_pod=$(/kubectl get pod -n $testbed |grep "tidb" |awk '{print $1}')

/kubectl cp $testbed/$tidb_pod:var/lib/tidb/log ./tidb-log

race=`grep 'DATA RACE' ./tidb-log/*.log || true`
if [ ! -z "$race" ]; then
    cat ./tidb-log/*.log
    echo "tidb-server DATA RACE!"
    exit 1
fi
if [ ${EXIT_CODE} -ne 0 ]; then 
    echo "randgen-test execute failed."
    exit 1
fi
echo "RANDGEN TEST FINISHED SUCCESSFULLY!"

