#!/bin/bash

# TODO: remove 'sleep' after FLASH-635 is addressed
function cmd_ti_ci_release()
{
	local file="${1}"
	local args="${2}"
	local cmd_mod_names="${3}"
	local cmd_hosts="${4}"
	local cmd_indexes="${5}"
	local mods="${6}"

	shift 6
	local ti="${integrated}/ops/ti.sh"
	
	local tiflash_count=`from_mods_get_count "${mods}" "tiflash"`

	# TODO: testing, maybe unstable
	"${ti}" -k "${args}" "${file}" repeat 5 store/rm : sleep 10 : up : sleep 60

	# TODO: recover time is unstable
	"${ti}" -k "${args}" "${file}" repeat 5 kill/random : kill/random : up : sleep 60

	"${ti}" -k "${args}" "${file}" repeat 5 up : tpch/load 0.001 all true 4 '' decimal "${integrated}/data/tpch" ${tiflash_count} : tpch/wait_syncing tpch_0_001 : \
		tpch/ch all tpch_0_001 : tpch/tikv all tpch_0_001

	"${ti}" -k "${args}" "${file}" repeat 5 kill/storage : up : sleep 5 : \
		tpch/ch all tpch_0_001 : tpch/tikv all tpch_0_001

	# Replaced by endless testcase https://github.com/PingCAP-QE/endless/blob/master/testcase/tiflash/consistency/consistency_test.go
	# "${ti}" -k "${args}" "${file}" ci/cases/consistency/all
}

set -euo pipefail
cmd_ti_ci_release "${@}"
