2017-07-28 04:00:19 +03:00
|
|
|
#!/bin/bash
|
|
|
|
# Library routines and initial setup for Mononoke-related tests.
|
|
|
|
|
2018-05-10 11:20:26 +03:00
|
|
|
function get_free_socket {
|
|
|
|
|
|
|
|
# From https://unix.stackexchange.com/questions/55913/whats-the-easiest-way-to-find-an-unused-local-port
|
|
|
|
cat >> "$TESTTMP/get_free_socket.py" <<EOF
|
|
|
|
import socket
|
|
|
|
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
s.bind(('', 0))
|
|
|
|
addr = s.getsockname()
|
|
|
|
print(addr[1])
|
|
|
|
s.close()
|
|
|
|
EOF
|
|
|
|
|
|
|
|
python "$TESTTMP/get_free_socket.py"
|
|
|
|
}
|
|
|
|
|
2017-07-28 04:00:19 +03:00
|
|
|
function mononoke {
|
2018-05-10 11:20:26 +03:00
|
|
|
export MONONOKE_SOCKET
|
|
|
|
MONONOKE_SOCKET=$(get_free_socket)
|
2018-06-30 00:36:49 +03:00
|
|
|
"$MONONOKE_SERVER" "$@" --ca-pem "$TESTDIR/testcert.crt" \
|
|
|
|
--private-key "$TESTDIR/testcert.key" \
|
|
|
|
--cert "$TESTDIR/testcert.crt" \
|
|
|
|
--debug \
|
|
|
|
--listening-host-port 127.0.0.1:"$MONONOKE_SOCKET" \
|
|
|
|
-P "$TESTTMP/mononoke-config-rocks" \
|
|
|
|
--configrepo_book local_master >> "$TESTTMP/mononoke.out" 2>&1 &
|
2017-07-28 04:00:19 +03:00
|
|
|
echo $! >> "$DAEMON_PIDS"
|
|
|
|
}
|
|
|
|
|
2018-01-02 04:38:31 +03:00
|
|
|
# Wait until a Mononoke server is available for this repo.
|
|
|
|
function wait_for_mononoke {
|
2018-06-07 19:41:52 +03:00
|
|
|
local attempts=150
|
2018-06-30 00:36:49 +03:00
|
|
|
|
|
|
|
SSLCURL="curl --cert $TESTDIR/testcert.crt \
|
|
|
|
--cacert $TESTDIR/testcert.crt \
|
|
|
|
--key $TESTDIR/testcert.key \
|
|
|
|
https://localhost:$MONONOKE_SOCKET"
|
|
|
|
|
2018-05-10 11:20:26 +03:00
|
|
|
for _ in $(seq 1 $attempts); do
|
2018-06-30 00:36:49 +03:00
|
|
|
$SSLCURL 2>&1 | grep -q 'Empty reply' && break
|
2018-01-02 04:38:31 +03:00
|
|
|
sleep 0.1
|
|
|
|
done
|
2018-05-10 11:20:26 +03:00
|
|
|
|
2018-06-30 00:36:49 +03:00
|
|
|
if ! $SSLCURL 2>&1 | grep -q 'Empty reply'; then
|
2018-03-21 19:55:19 +03:00
|
|
|
echo "Mononoke did not start" >&2
|
2018-05-10 11:20:26 +03:00
|
|
|
cat "$TESTTMP/mononoke.out"
|
2018-03-21 19:55:19 +03:00
|
|
|
exit 1
|
|
|
|
fi
|
2018-01-02 04:38:31 +03:00
|
|
|
}
|
|
|
|
|
2018-06-25 17:25:53 +03:00
|
|
|
# Wait until cache warmup finishes
|
|
|
|
function wait_for_mononoke_cache_warmup {
|
|
|
|
local attempts=150
|
|
|
|
for _ in $(seq 1 $attempts); do
|
|
|
|
grep -q "finished initial warmup" "$TESTTMP/mononoke.out" && break
|
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! grep -q "finished initial warmup" "$TESTTMP/mononoke.out"; then
|
|
|
|
echo "Mononoke warmup did not finished" >&2
|
|
|
|
cat "$TESTTMP/mononoke.out"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2018-02-14 17:34:10 +03:00
|
|
|
function setup_common_config {
|
|
|
|
setup_config_repo
|
|
|
|
cat >> "$HGRCPATH" <<EOF
|
|
|
|
[ui]
|
|
|
|
ssh="$DUMMYSSH"
|
|
|
|
[extensions]
|
|
|
|
remotefilelog=
|
|
|
|
[remotefilelog]
|
|
|
|
cachepath=$TESTTMP/cachepath
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2018-02-07 18:31:25 +03:00
|
|
|
function setup_config_repo {
|
|
|
|
hg init mononoke-config
|
|
|
|
cd mononoke-config || exit
|
|
|
|
cat >> .hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
treemanifest=
|
|
|
|
remotefilelog=
|
|
|
|
[treemanifest]
|
|
|
|
server=True
|
|
|
|
[remotefilelog]
|
|
|
|
server=True
|
|
|
|
shallowtrees=True
|
|
|
|
EOF
|
|
|
|
|
|
|
|
mkdir repos
|
|
|
|
cat > repos/repo <<CONFIG
|
|
|
|
path="$TESTTMP/repo"
|
2018-03-16 23:15:29 +03:00
|
|
|
repotype="blob:rocks"
|
2018-02-26 20:41:45 +03:00
|
|
|
repoid=0
|
2018-02-07 18:31:25 +03:00
|
|
|
CONFIG
|
2018-06-25 17:25:53 +03:00
|
|
|
|
|
|
|
if [[ -v CACHE_WARMUP_BOOKMARK ]]; then
|
|
|
|
cat >> repos/repo <<CONFIG
|
|
|
|
[cache_warmup]
|
|
|
|
bookmark="$CACHE_WARMUP_BOOKMARK"
|
|
|
|
CONFIG
|
|
|
|
fi
|
|
|
|
|
2018-02-07 18:31:25 +03:00
|
|
|
hg add -q repos
|
|
|
|
hg ci -ma
|
|
|
|
hg backfilltree
|
2018-05-03 19:54:25 +03:00
|
|
|
hg book local_master
|
2018-02-07 18:31:25 +03:00
|
|
|
cd ..
|
2018-03-22 22:20:53 +03:00
|
|
|
|
|
|
|
# We need to have a RocksDb version of config repo
|
|
|
|
mkdir mononoke-config-rocks
|
2018-06-13 01:28:33 +03:00
|
|
|
$MONONOKE_BLOBIMPORT --repo_id 0 --blobstore rocksdb mononoke-config/.hg mononoke-config-rocks >> "$TESTTMP/mononoke-config-blobimport.out" 2>&1
|
2018-02-07 18:31:25 +03:00
|
|
|
}
|
2018-02-13 17:13:47 +03:00
|
|
|
|
2018-06-13 01:28:33 +03:00
|
|
|
function blobimport {
|
2018-03-20 21:42:47 +03:00
|
|
|
reponame=$2
|
|
|
|
mkdir -p "$reponame"
|
2018-06-13 01:28:33 +03:00
|
|
|
$MONONOKE_BLOBIMPORT --repo_id 0 --blobstore rocksdb "$@" >> "$TESTTMP/blobimport.out" 2>&1
|
2018-03-20 21:42:47 +03:00
|
|
|
}
|
|
|
|
|
2018-06-18 20:07:08 +03:00
|
|
|
function apiserver {
|
2018-06-23 01:21:40 +03:00
|
|
|
$MONONOKE_APISERVER --config-path "$TESTTMP/mononoke-config-rocks" --config-bookmark "local_master" "$@" >> "$TESTTMP/apiserver.out" 2>&1 &
|
2018-06-18 20:07:08 +03:00
|
|
|
echo $! >> "$DAEMON_PIDS"
|
|
|
|
}
|
|
|
|
|
2017-07-28 04:00:19 +03:00
|
|
|
# Run an hg binary configured with the settings required to talk to Mononoke.
|
|
|
|
function hgmn {
|
2018-02-14 17:34:10 +03:00
|
|
|
hg --config ui.ssh="$DUMMYSSH" --config paths.default=ssh://user@dummy/repo --config ui.remotecmd="$MONONOKE_HGCLI" "$@"
|
2017-07-28 04:00:19 +03:00
|
|
|
}
|
2018-01-21 18:21:53 +03:00
|
|
|
|
2018-03-01 01:00:26 +03:00
|
|
|
function hgmn_show {
|
|
|
|
echo "LOG $*"
|
|
|
|
hgmn log --template 'node:\t{node}\np1node:\t{p1node}\np2node:\t{p2node}\nauthor:\t{author}\ndate:\t{date}\ndesc:\t{desc}\n\n{diff()}' -r "$@"
|
|
|
|
hgmn update "$@"
|
|
|
|
echo
|
|
|
|
echo "CONTENT $*"
|
|
|
|
find . -type f -not -path "./.hg/*" -print -exec cat {} \;
|
|
|
|
}
|
|
|
|
|
2018-02-13 17:13:47 +03:00
|
|
|
function hginit_treemanifest() {
|
|
|
|
hg init "$@"
|
|
|
|
cat >> "$1"/.hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
treemanifest=
|
|
|
|
remotefilelog=
|
2018-02-23 23:50:07 +03:00
|
|
|
smartlog=
|
2018-02-13 17:13:47 +03:00
|
|
|
[treemanifest]
|
|
|
|
server=True
|
|
|
|
sendtrees=True
|
|
|
|
[remotefilelog]
|
|
|
|
reponame=$1
|
2018-02-16 13:35:20 +03:00
|
|
|
cachepath=$TESTTMP/cachepath
|
2018-02-13 17:13:47 +03:00
|
|
|
server=True
|
|
|
|
shallowtrees=True
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function hgclone_treemanifest() {
|
2018-02-16 13:35:18 +03:00
|
|
|
hg clone -q --shallow --config remotefilelog.reponame=master "$@"
|
2018-02-13 17:13:47 +03:00
|
|
|
cat >> "$2"/.hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
treemanifest=
|
|
|
|
remotefilelog=
|
|
|
|
fastmanifest=
|
2018-02-23 23:50:07 +03:00
|
|
|
smartlog=
|
2018-02-13 17:13:47 +03:00
|
|
|
[treemanifest]
|
|
|
|
sendtrees=True
|
2018-02-16 13:35:18 +03:00
|
|
|
treeonly=True
|
2018-02-13 17:13:47 +03:00
|
|
|
[remotefilelog]
|
|
|
|
reponame=$2
|
2018-02-16 13:35:20 +03:00
|
|
|
cachepath=$TESTTMP/cachepath
|
2018-02-13 17:13:47 +03:00
|
|
|
shallowtrees=True
|
|
|
|
EOF
|
|
|
|
}
|
2018-02-14 17:34:10 +03:00
|
|
|
|
2018-03-22 00:18:21 +03:00
|
|
|
function enableextension() {
|
|
|
|
cat >> .hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
$1=
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2018-02-14 17:34:10 +03:00
|
|
|
function setup_hg_server() {
|
|
|
|
cat >> .hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
treemanifest=
|
|
|
|
remotefilelog=
|
|
|
|
[treemanifest]
|
|
|
|
server=True
|
|
|
|
[remotefilelog]
|
|
|
|
server=True
|
|
|
|
shallowtrees=True
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
|
|
|
function setup_hg_client() {
|
|
|
|
cat >> .hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
treemanifest=
|
|
|
|
remotefilelog=
|
|
|
|
[treemanifest]
|
|
|
|
server=False
|
|
|
|
treeonly=True
|
|
|
|
[remotefilelog]
|
|
|
|
server=False
|
|
|
|
reponame=repo
|
|
|
|
EOF
|
|
|
|
}
|