<commit_before>#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
source "${OS_ROOT}/hack/text.sh"
source "${OS_ROOT}/hack/lib/log.sh"
os::log::install_errexit

# Go to the top of the tree.
cd "${OS_ROOT}"

os::build::setup_env

export ETCD_HOST=${ETCD_HOST:-127.0.0.1}
export ETCD_PORT=${ETCD_PORT:-44001}
export ETCD_PEER_PORT=${ETCD_PEER_PORT:-47001}

if ! which etcd >/dev/null 2>&1; then
	if [[ ! -f ${OS_ROOT}/_tools/etcd/bin/etcd ]]; then
		echo "etcd must be in your PATH or installed in _tools/etcd/bin/ with hack/install-etcd.sh"
		exit 1
	fi
	export PATH="${OS_ROOT}/_tools/etcd/bin:$PATH"
fi

function cleanup() {
	out=$?
	set +e
	if [[ $out -ne 0 && -f "${etcdlog}" ]]; then
		cat "${etcdlog}"
	fi
	kill "${ETCD_PID}" 1>&2 2>/dev/null
	echo
	echo "Complete"
	exit $out
}

trap cleanup EXIT SIGINT

package="${OS_TEST_PACKAGE:-test/integration}"
tags="${OS_TEST_TAGS:-integration !docker etcd}"

export GOMAXPROCS="$(grep "processor" -c /proc/cpuinfo 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || 1)"
TMPDIR="${TMPDIR:-"/tmp"}"
export BASETMPDIR="${BASETMPDIR:-${TMPDIR}/openshift-integration}"
rm -rf ${BASETMPDIR} | true
mkdir -p ${BASETMPDIR}

echo
echo "Test ${package} -tags='${tags}' ..."
echo

# setup the test dirs
export ETCD_DIR=${BASETMPDIR}/etcd
etcdlog="${BASETMPDIR}/etcd.log"
testdir="${OS_ROOT}/_output/testbin/${package}"
name="$(basename ${testdir})"
testexec="${testdir}/${name}.test"
mkdir -p "${testdir}"
mkdir -p "${ETCD_DIR}"

# build the test executable (cgo must be disabled to have the symbol table available)
pushd "${testdir}" &>/dev/null
echo "Building test executable..."
CGO_ENABLED=0 go test -c -tags="${tags}" "${OS_GO_PACKAGE}/${package}"
popd &>/dev/null
	
LOG_DIR="${BASETMPDIR}/logs"
mkdir -p "${LOG_DIR}" 
os::log::start_system_logger

# Start etcd
echo "Starting etcd..."
etcd -name test -data-dir ${ETCD_DIR} \
 --listen-peer-urls http://${ETCD_HOST}:${ETCD_PEER_PORT} \
 --listen-client-urls http://${ETCD_HOST}:${ETCD_PORT} \
 --initial-advertise-peer-urls http://${ETCD_HOST}:${ETCD_PEER_PORT} \
 --initial-cluster test=http://${ETCD_HOST}:${ETCD_PEER_PORT} \
 --advertise-client-urls http://${ETCD_HOST}:${ETCD_PORT} \
 &>"${etcdlog}" &
export ETCD_PID=$!

wait_for_url "http://${ETCD_HOST}:${ETCD_PORT}/version" "etcd: " 0.25 160
curl -X PUT	"http://${ETCD_HOST}:${ETCD_PORT}/v2/keys/_test"
echo

function exectest() {
	echo "Running $1..."

	result=1
	if [ -n "${VERBOSE-}" ]; then
		ETCD_PORT=${ETCD_PORT} "${testexec}" -test.v -test.run="^$1$" "${@:2}" 2>&1
		result=$?
	else
		out=$(ETCD_PORT=${ETCD_PORT} "${testexec}" -test.run="^$1$" "${@:2}" 2>&1)
		result=$?
	fi

	os::text::clear_last_line

	if [[ ${result} -eq 0 ]]; then
		os::text::print_green "ok      $1"
		exit 0
	else
		os::text::print_red "failed  $1"
		echo "${out}"
		exit 1
	fi
}

export -f exectest
export testexec
export childargs

loop="${TIMES:-1}"
pushd "./${package}" &>/dev/null
# $1 is passed to grep -E to filter the list of tests; this may be the name of a single test,<commit_msg>make test-integration use our etcd<commit_after>#!/bin/bash

set -o errexit
set -o nounset
set -o pipefail

STARTTIME=$(date +%s)
OS_ROOT=$(dirname "${BASH_SOURCE}")/..
source "${OS_ROOT}/hack/common.sh"
source "${OS_ROOT}/hack/util.sh"
source "${OS_ROOT}/hack/text.sh"
source "${OS_ROOT}/hack/lib/log.sh"
os::log::install_errexit

# Go to the top of the tree.
cd "${OS_ROOT}"

os::build::setup_env

TMPDIR="${TMPDIR:-"/tmp"}"
export BASETMPDIR="${BASETMPDIR:-${TMPDIR}/openshift-integration}"
export API_SCHEME=${API_SCHEME:-http}
export API_BIND_HOST="127.0.0.1"
export ETCD_PORT=${ETCD_PORT:-44001}
export ETCD_PEER_PORT=${ETCD_PEER_PORT:-47001}
export SUDO=''
setup_env_vars
reset_tmp_dir

function cleanup() {
	out=$?
	set +e

	cleanup_openshift
	echo "Complete"
	exit $out
}

trap cleanup EXIT SIGINT

package="${OS_TEST_PACKAGE:-test/integration}"
tags="${OS_TEST_TAGS:-integration !docker etcd}"

export GOMAXPROCS="$(grep "processor" -c /proc/cpuinfo 2>/dev/null || sysctl -n hw.logicalcpu 2>/dev/null || 1)"

echo
echo "Test ${package} -tags='${tags}' ..."
echo

# setup the test dirs
testdir="${OS_ROOT}/_output/testbin/${package}"
name="$(basename ${testdir})"
testexec="${testdir}/${name}.test"
mkdir -p "${testdir}"

# build the test executable (cgo must be disabled to have the symbol table available)
pushd "${testdir}" &>/dev/null
echo "Building test executable..."
CGO_ENABLED=0 go test -c -tags="${tags}" "${OS_GO_PACKAGE}/${package}"
popd &>/dev/null

os::log::start_system_logger

configure_os_server
openshift start etcd --config=${MASTER_CONFIG_DIR}/master-config.yaml &> ${LOG_DIR}/etcd.log &

wait_for_url "http://${API_HOST}:${ETCD_PORT}/version" "etcd: " 0.25 160
curl -X PUT	"http://${API_HOST}:${ETCD_PORT}/v2/keys/_test"
echo

function exectest() {
	echo "Running $1..."

	result=1
	if [ -n "${VERBOSE-}" ]; then
		ETCD_PORT=${ETCD_PORT} "${testexec}" -test.v -test.run="^$1$" "${@:2}" 2>&1
		result=$?
	else
		out=$(ETCD_PORT=${ETCD_PORT} "${testexec}" -test.run="^$1$" "${@:2}" 2>&1)
		result=$?
	fi

	os::text::clear_last_line

	if [[ ${result} -eq 0 ]]; then
		os::text::print_green "ok      $1"
		exit 0
	else
		os::text::print_red "failed  $1"
		echo "${out}"

		# dump etcd for failing test
		echo "[INFO] Dumping etcd contents to ${ARTIFACT_DIR}/$1-etcd_dump.json"
		curl -L "${API_SCHEME}://${API_HOST}:${ETCD_PORT}/v2/keys/?recursive=true" > "${ARTIFACT_DIR}/$1-etcd_dump.json"
		echo

		exit 1
	fi
}

export -f exectest
export testexec
export childargs

loop="${TIMES:-1}"
pushd "./${package}" &>/dev/null
# $1 is passed to grep -E to filter the list of tests; this may be the name of a single test,
{'fraction_non_alphanumeric': 0.2012058570198105, 'fraction_numerical': 0.016881998277347116, 'mean_word_length': 4.777114427860696, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2193040', 'n_tokens_mistral': 2398, 'n_tokens_neox': 2286, 'n_words': 525}