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
|
2018-10-09 02:00:11 +03:00
|
|
|
cat > "$TESTTMP/get_free_socket.py" <<EOF
|
2018-05-10 11:20:26 +03:00
|
|
|
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"
|
|
|
|
}
|
|
|
|
|
2018-11-20 16:13:59 +03:00
|
|
|
# return random value from [1, max_value]
|
|
|
|
function random_int() {
|
|
|
|
max_value=$1
|
|
|
|
|
|
|
|
VAL=$RANDOM
|
|
|
|
(( VAL %= $max_value ))
|
|
|
|
(( VAL += 1 ))
|
|
|
|
|
|
|
|
echo $VAL
|
|
|
|
}
|
|
|
|
|
2018-07-17 02:56:46 +03:00
|
|
|
function sslcurl {
|
|
|
|
curl --cert "$TESTDIR/testcert.crt" --cacert "$TESTDIR/testcert.crt" --key "$TESTDIR/testcert.key" "$@"
|
|
|
|
}
|
|
|
|
|
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" \
|
2019-01-03 19:43:45 +03:00
|
|
|
--ssl-ticket-seeds "$TESTDIR/server.pem.seeds" \
|
2018-06-30 00:36:49 +03:00
|
|
|
--debug \
|
2019-01-03 19:43:45 +03:00
|
|
|
--listening-host-port "[::1]:$MONONOKE_SOCKET" \
|
2018-12-04 14:50:22 +03:00
|
|
|
-P "$TESTTMP/mononoke-config" \
|
2018-10-01 13:28:11 +03:00
|
|
|
--do-not-init-cachelib >> "$TESTTMP/mononoke.out" 2>&1 &
|
2019-01-03 19:43:45 +03:00
|
|
|
export MONONOKE_PID=$!
|
|
|
|
echo "$MONONOKE_PID" >> "$DAEMON_PIDS"
|
2017-07-28 04:00:19 +03:00
|
|
|
}
|
|
|
|
|
2019-02-21 16:43:59 +03:00
|
|
|
function mononoke_hg_sync {
|
|
|
|
$MONONOKE_HG_SYNC \
|
|
|
|
--do-not-init-cachelib \
|
2019-02-26 21:50:12 +03:00
|
|
|
--mononoke-config-path mononoke-config \
|
|
|
|
ssh://user@dummy/"$1" sync-once --start-id "$2"
|
2019-02-21 16:43:59 +03:00
|
|
|
}
|
|
|
|
|
2019-03-18 01:04:13 +03:00
|
|
|
function mononoke_hg_sync_with_failure_handler {
|
|
|
|
$MONONOKE_HG_SYNC \
|
|
|
|
--do-not-init-cachelib \
|
|
|
|
--mononoke-config-path mononoke-config \
|
|
|
|
--run-on-failure "$3" \
|
|
|
|
ssh://user@dummy/"$1" sync-once --start-id "$2"
|
|
|
|
}
|
2019-02-27 17:59:02 +03:00
|
|
|
|
|
|
|
function create_mutable_counters_sqlite3_db {
|
|
|
|
cat >> "$TESTTMP"/mutable_counters.sql <<SQL
|
|
|
|
CREATE TABLE mutable_counters (
|
|
|
|
repo_id INT UNSIGNED NOT NULL,
|
|
|
|
name VARCHAR(512) NOT NULL,
|
|
|
|
value BIGINT NOT NULL,
|
|
|
|
PRIMARY KEY (repo_id, name)
|
|
|
|
);
|
|
|
|
SQL
|
|
|
|
sqlite3 "$TESTTMP/repo/mutable_counters" "$(cat "$TESTTMP"/mutable_counters.sql)"
|
|
|
|
}
|
|
|
|
|
|
|
|
function init_mutable_counters_sqlite3_db {
|
|
|
|
sqlite3 "$TESTTMP/repo/mutable_counters" \
|
|
|
|
"insert into mutable_counters (repo_id, name, value) values(0, 'latest-replayed-request', 0)";
|
|
|
|
}
|
|
|
|
|
|
|
|
function mononoke_hg_sync_loop {
|
|
|
|
$MONONOKE_HG_SYNC \
|
|
|
|
--do-not-init-cachelib \
|
|
|
|
--mononoke-config-path mononoke-config \
|
|
|
|
ssh://user@dummy/"$1" sync-loop --start-id "$2"
|
|
|
|
}
|
|
|
|
|
2018-01-02 04:38:31 +03:00
|
|
|
# Wait until a Mononoke server is available for this repo.
|
|
|
|
function wait_for_mononoke {
|
2019-02-01 14:48:43 +03:00
|
|
|
# MONONOKE_START_TIMEOUT is set in seconds
|
|
|
|
# Number of attempts is timeout multiplied by 10, since we
|
|
|
|
# sleep every 0.1 seconds.
|
|
|
|
local attempts=$(expr ${MONONOKE_START_TIMEOUT:-15} \* 10)
|
2018-06-30 00:36:49 +03:00
|
|
|
|
2018-07-17 02:56:46 +03:00
|
|
|
SSLCURL="sslcurl --noproxy localhost \
|
2018-06-30 00:36:49 +03:00
|
|
|
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-10-09 12:05:20 +03:00
|
|
|
function setup_common_hg_configs {
|
2018-02-14 17:34:10 +03:00
|
|
|
cat >> "$HGRCPATH" <<EOF
|
|
|
|
[ui]
|
|
|
|
ssh="$DUMMYSSH"
|
|
|
|
[extensions]
|
|
|
|
remotefilelog=
|
|
|
|
[remotefilelog]
|
|
|
|
cachepath=$TESTTMP/cachepath
|
|
|
|
EOF
|
|
|
|
}
|
|
|
|
|
2018-10-09 12:05:20 +03:00
|
|
|
function setup_common_config {
|
2018-12-04 14:50:22 +03:00
|
|
|
setup_mononoke_config "$@"
|
2018-10-09 12:05:20 +03:00
|
|
|
setup_common_hg_configs
|
|
|
|
}
|
|
|
|
|
2019-02-06 01:52:00 +03:00
|
|
|
function create_pushrebaserecording_sqlite3_db {
|
|
|
|
cat >> "$TESTTMP"/pushrebaserecording.sql <<SQL
|
|
|
|
CREATE TABLE pushrebaserecording (
|
|
|
|
id bigint(20) NOT NULL,
|
|
|
|
repo_id int(10) NOT NULL,
|
|
|
|
ontorev binary(40) NOT NULL,
|
|
|
|
onto varchar(512) NOT NULL,
|
|
|
|
onto_rebased_rev binary(40),
|
|
|
|
conflicts longtext,
|
|
|
|
pushrebase_errmsg varchar(1024) DEFAULT NULL,
|
|
|
|
upload_errmsg varchar(1024) DEFAULT NULL,
|
|
|
|
bundlehandle varchar(1024) DEFAULT NULL,
|
|
|
|
timestamps longtext NOT NULL,
|
|
|
|
recorded_manifest_hashes longtext NOT NULL,
|
|
|
|
real_manifest_hashes longtext NOT NULL,
|
|
|
|
duration_ms int(10) DEFAULT NULL,
|
|
|
|
replacements_revs varchar(1024) DEFAULT NULL,
|
|
|
|
ordered_added_revs varchar(1024) DEFAULT NULL,
|
|
|
|
PRIMARY KEY (id)
|
|
|
|
);
|
|
|
|
SQL
|
|
|
|
sqlite3 "$TESTTMP"/pushrebaserecording "$(cat "$TESTTMP"/pushrebaserecording.sql)"
|
|
|
|
}
|
|
|
|
|
2019-02-21 16:43:59 +03:00
|
|
|
function init_pushrebaserecording_sqlite3_db {
|
|
|
|
sqlite3 "$TESTTMP/pushrebaserecording" \
|
|
|
|
"insert into pushrebaserecording \
|
|
|
|
(id, repo_id, bundlehandle, ontorev, onto, timestamps, recorded_manifest_hashes, real_manifest_hashes) \
|
|
|
|
values(1, 0, 'handle', 'add0c792bfce89610d277fd5b1e32f5287994d1d', 'master_bookmark', '', '', '')";
|
|
|
|
}
|
|
|
|
|
|
|
|
function init_bookmark_log_sqlite3_db {
|
|
|
|
sqlite3 "$TESTTMP/repo/books" \
|
|
|
|
"insert into bookmarks_update_log \
|
|
|
|
(repo_id, name, from_changeset_id, to_changeset_id, reason, timestamp) \
|
|
|
|
values(0, 'master_bookmark', NULL, X'04C1EA537B01FFF207445E043E310807F9059572DD3087A0FCE458DEC005E4BD', 'pushrebase', 0)";
|
|
|
|
|
|
|
|
sqlite3 "$TESTTMP/repo/books" "select * from bookmarks_update_log";
|
|
|
|
}
|
|
|
|
|
2018-12-04 14:50:22 +03:00
|
|
|
function setup_mononoke_config {
|
|
|
|
cd "$TESTTMP" || exit
|
|
|
|
mkdir mononoke-config
|
2018-10-09 02:00:11 +03:00
|
|
|
REPOTYPE="blob:rocks"
|
|
|
|
if [[ $# -gt 0 ]]; then
|
|
|
|
REPOTYPE="$1"
|
|
|
|
fi
|
|
|
|
|
2018-12-04 14:50:22 +03:00
|
|
|
cd mononoke-config
|
2018-07-04 17:03:34 +03:00
|
|
|
mkdir -p repos/repo
|
|
|
|
cat > repos/repo/server.toml <<CONFIG
|
2018-02-07 18:31:25 +03:00
|
|
|
path="$TESTTMP/repo"
|
2018-10-09 02:00:11 +03:00
|
|
|
repotype="$REPOTYPE"
|
2018-02-26 20:41:45 +03:00
|
|
|
repoid=0
|
2018-06-30 06:19:49 +03:00
|
|
|
enabled=true
|
2019-01-17 13:26:01 +03:00
|
|
|
hash_validation_percentage=100
|
2018-11-08 15:07:24 +03:00
|
|
|
CONFIG
|
|
|
|
|
|
|
|
if [[ -v READ_ONLY_REPO ]]; then
|
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
|
|
|
readonly=true
|
|
|
|
CONFIG
|
|
|
|
fi
|
2018-08-31 18:41:24 +03:00
|
|
|
|
2019-02-25 20:24:37 +03:00
|
|
|
if [[ -v PUSHREBASE_REWRITE_DATES ]]; then
|
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
|
|
|
[pushrebase]
|
|
|
|
rewritedates=true
|
|
|
|
CONFIG
|
|
|
|
else
|
2018-11-08 15:07:24 +03:00
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
2018-08-31 18:41:24 +03:00
|
|
|
[pushrebase]
|
|
|
|
rewritedates=false
|
2018-06-30 06:19:49 +03:00
|
|
|
CONFIG
|
2019-02-25 20:24:37 +03:00
|
|
|
fi
|
2018-06-30 06:19:49 +03:00
|
|
|
|
2019-02-01 14:48:43 +03:00
|
|
|
if [[ ! -v ENABLE_ACL_CHECKER ]]; then
|
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
2019-01-04 17:14:03 +03:00
|
|
|
[hook_manager_params]
|
|
|
|
entrylimit=1048576
|
|
|
|
weightlimit=104857600
|
|
|
|
disable_acl_checker=true
|
|
|
|
CONFIG
|
2019-02-01 14:48:43 +03:00
|
|
|
fi
|
2019-01-04 17:14:03 +03:00
|
|
|
|
2019-02-12 23:36:51 +03:00
|
|
|
if [[ -v ENABLE_PRESERVE_BUNDLE2 ]]; then
|
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
|
|
|
[bundle2_replay_params]
|
|
|
|
preserve_raw_bundle2 = true
|
|
|
|
CONFIG
|
|
|
|
fi
|
|
|
|
|
2018-07-04 17:03:34 +03:00
|
|
|
if [[ -v CACHE_WARMUP_BOOKMARK ]]; then
|
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
|
|
|
[cache_warmup]
|
|
|
|
bookmark="$CACHE_WARMUP_BOOKMARK"
|
|
|
|
CONFIG
|
2018-10-17 12:17:11 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -v LFS_THRESHOLD ]]; then
|
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
|
|
|
[lfs]
|
|
|
|
threshold=$LFS_THRESHOLD
|
|
|
|
CONFIG
|
2018-07-04 17:03:34 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
mkdir -p repos/disabled_repo
|
|
|
|
cat > repos/disabled_repo/server.toml <<CONFIG
|
2018-06-30 06:19:49 +03:00
|
|
|
path="$TESTTMP/disabled_repo"
|
2018-10-09 02:00:11 +03:00
|
|
|
repotype="$REPOTYPE"
|
2018-06-30 06:19:49 +03:00
|
|
|
repoid=2
|
|
|
|
enabled=false
|
2018-02-07 18:31:25 +03:00
|
|
|
CONFIG
|
2018-10-09 12:05:20 +03:00
|
|
|
}
|
2018-06-25 17:25:53 +03:00
|
|
|
|
2018-10-09 12:05:20 +03:00
|
|
|
function register_hook {
|
2018-11-13 20:34:53 +03:00
|
|
|
hook_name="$1"
|
|
|
|
path="$2"
|
|
|
|
hook_type="$3"
|
2018-10-11 15:41:02 +03:00
|
|
|
|
2018-11-13 20:34:53 +03:00
|
|
|
shift 3
|
2019-02-08 18:24:03 +03:00
|
|
|
EXTRA_CONFIG_DESCRIPTOR=""
|
2018-10-11 15:41:02 +03:00
|
|
|
if [[ $# -gt 0 ]]; then
|
2019-02-08 18:24:03 +03:00
|
|
|
EXTRA_CONFIG_DESCRIPTOR="$1"
|
2018-10-11 15:41:02 +03:00
|
|
|
fi
|
|
|
|
|
2019-02-08 18:24:03 +03:00
|
|
|
(
|
|
|
|
cat <<CONFIG
|
2018-10-09 12:05:20 +03:00
|
|
|
[[bookmarks.hooks]]
|
|
|
|
hook_name="$hook_name"
|
|
|
|
[[hooks]]
|
|
|
|
name="$hook_name"
|
|
|
|
path="$path"
|
|
|
|
hook_type="$hook_type"
|
|
|
|
CONFIG
|
2019-02-08 18:24:03 +03:00
|
|
|
[ -n "$EXTRA_CONFIG_DESCRIPTOR" ] && cat "$EXTRA_CONFIG_DESCRIPTOR"
|
|
|
|
) >> repos/repo/server.toml
|
2018-10-09 12:05:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function blobimport {
|
2018-12-11 20:45:43 +03:00
|
|
|
input="$1"
|
|
|
|
output="$2"
|
|
|
|
shift 2
|
2018-07-12 04:25:23 +03:00
|
|
|
mkdir -p "$output"
|
2018-10-01 13:28:09 +03:00
|
|
|
$MONONOKE_BLOBIMPORT --repo_id 0 \
|
2018-12-04 14:50:23 +03:00
|
|
|
--mononoke-config-path "$TESTTMP/mononoke-config" \
|
|
|
|
"$input" --do-not-init-cachelib "$@" >> "$TESTTMP/blobimport.out" 2>&1
|
2018-10-01 13:28:09 +03:00
|
|
|
BLOBIMPORT_RC="$?"
|
|
|
|
if [[ $BLOBIMPORT_RC -ne 0 ]]; then
|
|
|
|
cat "$TESTTMP/blobimport.out"
|
|
|
|
# set exit code, otherwise previous cat sets it to 0
|
|
|
|
return "$BLOBIMPORT_RC"
|
|
|
|
fi
|
2018-03-20 21:42:47 +03:00
|
|
|
}
|
|
|
|
|
2018-08-16 09:31:22 +03:00
|
|
|
function bonsai_verify {
|
2018-12-11 19:10:54 +03:00
|
|
|
GLOG_minloglevel=2 $MONONOKE_BONSAI_VERIFY --repo_id 0 \
|
2018-12-04 14:50:23 +03:00
|
|
|
--mononoke-config-path "$TESTTMP/mononoke-config" "$@"
|
2018-08-16 09:31:22 +03:00
|
|
|
}
|
|
|
|
|
2018-11-22 21:25:53 +03:00
|
|
|
function setup_no_ssl_apiserver {
|
|
|
|
APISERVER_PORT=$(get_free_socket)
|
|
|
|
no_ssl_apiserver --http-host "127.0.0.1" --http-port "$APISERVER_PORT"
|
|
|
|
wait_for_apiserver --no-ssl
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-06-18 20:07:08 +03:00
|
|
|
function apiserver {
|
2018-12-06 19:54:02 +03:00
|
|
|
$MONONOKE_APISERVER "$@" --mononoke-config-path "$TESTTMP/mononoke-config" \
|
2018-07-17 02:56:46 +03:00
|
|
|
--ssl-ca "$TESTDIR/testcert.crt" \
|
|
|
|
--ssl-private-key "$TESTDIR/testcert.key" \
|
2018-10-01 13:28:11 +03:00
|
|
|
--ssl-certificate "$TESTDIR/testcert.crt" \
|
2018-12-06 05:10:52 +03:00
|
|
|
--ssl-ticket-seeds "$TESTDIR/server.pem.seeds" \
|
2018-10-01 13:28:11 +03:00
|
|
|
--do-not-init-cachelib >> "$TESTTMP/apiserver.out" 2>&1 &
|
2018-12-06 05:10:52 +03:00
|
|
|
export APISERVER_PID=$!
|
|
|
|
echo "$APISERVER_PID" >> "$DAEMON_PIDS"
|
2018-06-18 20:07:08 +03:00
|
|
|
}
|
|
|
|
|
2018-09-27 21:16:18 +03:00
|
|
|
function no_ssl_apiserver {
|
|
|
|
$MONONOKE_APISERVER "$@" \
|
2018-12-06 19:54:02 +03:00
|
|
|
--mononoke-config-path "$TESTTMP/mononoke-config" >> "$TESTTMP/apiserver.out" 2>&1 &
|
2018-09-27 21:16:18 +03:00
|
|
|
echo $! >> "$DAEMON_PIDS"
|
|
|
|
}
|
|
|
|
|
2018-09-24 20:59:02 +03:00
|
|
|
function wait_for_apiserver {
|
|
|
|
for _ in $(seq 1 200); do
|
2018-12-03 13:12:11 +03:00
|
|
|
if [[ -a "$TESTTMP/apiserver.out" ]]; then
|
|
|
|
PORT=$(grep "Listening to" < "$TESTTMP/apiserver.out" | grep -Pzo "(\\d+)\$") && break
|
|
|
|
fi
|
2018-09-24 20:59:02 +03:00
|
|
|
sleep 0.1
|
|
|
|
done
|
|
|
|
|
|
|
|
if [[ -z "$PORT" ]]; then
|
|
|
|
echo "error: Mononoke API Server is not started"
|
|
|
|
cat "$TESTTMP/apiserver.out"
|
|
|
|
exit 1
|
|
|
|
fi
|
2018-09-27 21:16:18 +03:00
|
|
|
|
2018-12-04 19:27:47 +03:00
|
|
|
export APIHOST="localhost:$PORT"
|
2018-09-24 20:59:02 +03:00
|
|
|
export APISERVER
|
2018-09-27 21:16:18 +03:00
|
|
|
APISERVER="https://localhost:$PORT"
|
|
|
|
if [[ ($# -eq 1 && "$1" == "--no-ssl") ]]; then
|
|
|
|
APISERVER="http://localhost:$PORT"
|
|
|
|
fi
|
2018-09-24 20:59:02 +03:00
|
|
|
}
|
|
|
|
|
2018-07-26 07:36:05 +03:00
|
|
|
function extract_json_error {
|
|
|
|
input=$(cat)
|
|
|
|
echo "$input" | head -1 | jq -r '.message'
|
|
|
|
echo "$input" | tail -n +2
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
}
|
2018-10-11 15:41:09 +03:00
|
|
|
|
|
|
|
# Does all the setup necessary for hook tests
|
|
|
|
function hook_test_setup() {
|
|
|
|
. "$TESTDIR"/library.sh
|
|
|
|
|
2018-12-04 14:50:22 +03:00
|
|
|
setup_mononoke_config
|
2018-10-11 15:41:09 +03:00
|
|
|
cd "$TESTTMP/mononoke-config" || exit 1
|
|
|
|
|
|
|
|
cat >> repos/repo/server.toml <<CONFIG
|
|
|
|
[[bookmarks]]
|
|
|
|
name="master_bookmark"
|
|
|
|
CONFIG
|
|
|
|
|
|
|
|
HOOK_FILE="$1"
|
|
|
|
HOOK_NAME="$2"
|
|
|
|
HOOK_TYPE="$3"
|
|
|
|
shift 3
|
2019-02-08 18:24:03 +03:00
|
|
|
EXTRA_CONFIG_DESCRIPTOR=""
|
2018-10-11 15:41:09 +03:00
|
|
|
if [[ $# -gt 0 ]]; then
|
2019-02-08 18:24:03 +03:00
|
|
|
EXTRA_CONFIG_DESCRIPTOR="$1"
|
2018-10-11 15:41:09 +03:00
|
|
|
fi
|
|
|
|
|
2018-11-13 20:34:53 +03:00
|
|
|
if [[ ! -z "$HOOK_FILE" ]] ; then
|
|
|
|
mkdir -p common/hooks
|
|
|
|
cp "$HOOK_FILE" common/hooks/"$HOOK_NAME".lua
|
2019-02-08 18:24:03 +03:00
|
|
|
register_hook "$HOOK_NAME" common/hooks/"$HOOK_NAME".lua "$HOOK_TYPE" "$EXTRA_CONFIG_DESCRIPTOR"
|
2018-11-13 20:34:53 +03:00
|
|
|
else
|
2019-02-08 18:24:03 +03:00
|
|
|
register_hook "$HOOK_NAME" "" "$HOOK_TYPE" "$EXTRA_CONFIG_DESCRIPTOR"
|
2018-11-13 20:34:53 +03:00
|
|
|
fi
|
2018-10-11 15:41:09 +03:00
|
|
|
|
|
|
|
setup_common_hg_configs
|
|
|
|
cd "$TESTTMP" || exit 1
|
|
|
|
|
|
|
|
cat >> "$HGRCPATH" <<EOF
|
|
|
|
[ui]
|
|
|
|
ssh="$DUMMYSSH"
|
|
|
|
EOF
|
|
|
|
|
|
|
|
hg init repo-hg
|
|
|
|
cd repo-hg || exit 1
|
|
|
|
setup_hg_server
|
|
|
|
hg debugdrawdag <<EOF
|
|
|
|
C
|
|
|
|
|
|
|
|
|
B
|
|
|
|
|
|
|
|
|
A
|
|
|
|
EOF
|
|
|
|
|
|
|
|
hg bookmark master_bookmark -r tip
|
|
|
|
|
|
|
|
cd ..
|
2018-12-11 20:45:43 +03:00
|
|
|
blobimport repo-hg/.hg repo
|
2018-10-11 15:41:09 +03:00
|
|
|
|
|
|
|
mononoke
|
|
|
|
wait_for_mononoke "$TESTTMP"/repo
|
|
|
|
|
|
|
|
hgclone_treemanifest ssh://user@dummy/repo-hg repo2 --noupdate --config extensions.remotenames= -q
|
|
|
|
cd repo2 || exit 1
|
|
|
|
setup_hg_client
|
|
|
|
cat >> .hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
pushrebase =
|
|
|
|
remotenames =
|
|
|
|
EOF
|
2018-10-17 12:17:11 +03:00
|
|
|
}
|
2018-10-11 15:41:09 +03:00
|
|
|
|
2018-10-17 12:17:11 +03:00
|
|
|
function setup_hg_lfs() {
|
|
|
|
cat >> .hg/hgrc <<EOF
|
|
|
|
[extensions]
|
|
|
|
lfs=
|
|
|
|
[lfs]
|
|
|
|
url=$1
|
|
|
|
threshold=$2
|
|
|
|
usercache=$3
|
|
|
|
EOF
|
2018-10-11 15:41:09 +03:00
|
|
|
}
|
2018-11-08 14:39:41 +03:00
|
|
|
|
|
|
|
function aliasverify() {
|
2018-12-04 14:50:23 +03:00
|
|
|
mode=$1
|
|
|
|
shift 1
|
2018-12-11 19:10:54 +03:00
|
|
|
GLOG_minloglevel=2 $MONONOKE_ALIAS_VERIFY --repo_id 0 \
|
2019-01-23 18:58:11 +03:00
|
|
|
--do-not-init-cachelib \
|
2018-12-04 14:50:23 +03:00
|
|
|
--mononoke-config-path "$TESTTMP/mononoke-config" \
|
|
|
|
--mode "$mode" "$@"
|
2018-11-08 14:39:41 +03:00
|
|
|
}
|
2019-01-09 20:20:53 +03:00
|
|
|
|
2019-01-22 16:56:17 +03:00
|
|
|
# Without rev
|
|
|
|
function tglogpnr() {
|
|
|
|
hg log -G -T "{node|short} {phase} '{desc}' {bookmarks} {branches}" "$@"
|
|
|
|
}
|
|
|
|
|
|
|
|
function mkcommit() {
|
|
|
|
echo "$1" > "$1"
|
|
|
|
hg add "$1"
|
|
|
|
hg ci -m "$1"
|
|
|
|
}
|
2019-02-21 16:43:59 +03:00
|
|
|
|
|
|
|
function pushrebase_replay() {
|
|
|
|
DB_INDICES=$1
|
|
|
|
|
|
|
|
REPLAY_CA_PEM="$TESTDIR/testcert.crt" \
|
|
|
|
THRIFT_TLS_CL_CERT_PATH="$TESTDIR/testcert.crt" \
|
|
|
|
THRIFT_TLS_CL_KEY_PATH="$TESTDIR/testcert.key" $PUSHREBASE_REPLAY \
|
|
|
|
--mononoke-config-path "$TESTTMP/mononoke-config" \
|
|
|
|
--reponame repo \
|
|
|
|
--hgcli "$MONONOKE_HGCLI" \
|
|
|
|
--mononoke-admin "$MONONOKE_ADMIN" \
|
|
|
|
--mononoke-address "[::1]:$MONONOKE_SOCKET" \
|
|
|
|
--mononoke-server-common-name localhost \
|
|
|
|
--db-indices "$DB_INDICES" \
|
|
|
|
--repoid 0 \
|
|
|
|
--bundle-provider filesystem \
|
|
|
|
--filesystem-bundles-storage-path "$TESTTMP" \
|
|
|
|
--sqlite3-path "$TESTTMP/pushrebaserecording"
|
|
|
|
}
|