<commit_before>#!/usr/bin/env bash

set -eou pipefail

function util::free_port() {
    for port in $(seq 10000 11000); do
        echo -ne "\035" | telnet 127.0.0.1 $port > /dev/null 2>&1;
        [ $? -eq 1 ] && echo "$port" && break;
    done
}

function etcd::start() {
    etcd::stop
    export ETCD_PORT=$(util::free_port)
    docker run --name aptomi-etcd-smoke -d -p ${ETCD_PORT}:2379 quay.io/coreos/etcd /usr/local/bin/etcd --advertise-client-urls http://0.0.0.0:${ETCD_PORT} --listen-client-urls http://0.0.0.0:2379
    echo "etcd listening on port ${ETCD_PORT}"
    sleep 1
}

function etcd::stop() {
    docker rm -f aptomi-etcd-smoke &>/dev/null || true
}

function cleanup() {
    set +x
    etcd::stop
}

trap cleanup EXIT

etcd::start

export APTOMI_DB_ENDPOINTS=127.0.0.1:${ETCD_PORT}
export APTOMI_TEST_DB_ENDPOINTS=${APTOMI_DB_ENDPOINTS}
<commit_msg>Replace duplicated code in with_etcd helper with util.sh<commit_after>#!/usr/bin/env bash

set -eou pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
source "${DIR}/util.sh"

function cleanup() {
    set +x
    etcd::stop
}

trap cleanup EXIT

etcd::start

export APTOMI_DB_ENDPOINTS=127.0.0.1:${ETCD_PORT}
export APTOMI_TEST_DB_ENDPOINTS=${APTOMI_DB_ENDPOINTS}

{'fraction_non_alphanumeric': 0.1619887730553328, 'fraction_numerical': 0.04170008019246191, 'mean_word_length': 3.6394052044609664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 5, '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': '3174116', 'n_tokens_mistral': 538, 'n_tokens_neox': 515, 'n_words': 107}