mirror of
https://github.com/facebook/sapling.git
synced 2024-10-11 09:17:30 +03:00
move to the same hg tests runner that is used by hg
Summary: This is the first step, I just copied the files from mercurial to mononoke/tests/integration/third_party and made it work. Further unification is required to reuse the same files. It renders progress bars and other fancy things and matches our mercurial test framework. Also it allows to use embedded python code! Some things are not supported: like aliases, so changes in the tests are required. Some tests used urandom and cat in a wrong way, I had to fix it as well. Reviewed By: lukaspiatkowski Differential Revision: D13871531 fbshipit-source-id: c723bb18c2233639bb36bc7964e57baddff4c0b9
This commit is contained in:
parent
0d92dd47fe
commit
77cc38f5d9
@ -12,6 +12,7 @@ import multiprocessing
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import subprocess
|
||||
import tempfile
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
@ -29,6 +30,7 @@ MONONOKE_BONSAI_VERIFY_TARGET = '//scm/mononoke:bonsai_verify'
|
||||
MONONOKE_APISERVER_TARGET = '//scm/mononoke/apiserver:apiserver'
|
||||
DUMMYSSH_TARGET = '//scm/mononoke/tests/integration:dummyssh'
|
||||
BINARY_HG_TARGET = '//scm/hg:hg'
|
||||
BINARY_HGPYTHON_TARGET = '//scm/hg:hgpython'
|
||||
MONONOKE_HGCLI_TARGET = '//scm/mononoke/hgcli:hgcli'
|
||||
MONONOKE_SERVER_TARGET = '//scm/mononoke:mononoke'
|
||||
FACEBOOK_HOOKS_TARGET = '//scm/mononoke/facebook/hooks:hooks'
|
||||
@ -74,17 +76,16 @@ def run(
|
||||
ctx, tests, dry_run, interactive, output, verbose, debug,
|
||||
simple_test_selector, keep_tmpdir
|
||||
):
|
||||
runner = hg_run_tests.TestRunner()
|
||||
|
||||
testdir = parutil.get_dir_path(TESTDIR_PATH)
|
||||
# Also add to the system path because the Mercurial run-tests.py does an
|
||||
# absolute import of killdaemons etc.
|
||||
sys.path.insert(0, os.path.join(testdir, 'third_party'))
|
||||
|
||||
# Use hg.real to avoid going through the wrapper and incurring slowdown
|
||||
# from subprocesses.
|
||||
# XXX is this the right thing to do?
|
||||
args = ['--with-hg', get_hg_binary()]
|
||||
run_tests_dir = os.path.join(
|
||||
os.path.join(testdir, 'third_party'), 'hg_run_tests.py'
|
||||
)
|
||||
args = [
|
||||
get_hg_python_binary(),
|
||||
run_tests_dir,
|
||||
'--maxdifflines=1000',
|
||||
'--with-hg', get_hg_binary()
|
||||
]
|
||||
if dry_run:
|
||||
args.append('--list-tests')
|
||||
if interactive:
|
||||
@ -139,7 +140,15 @@ def run(
|
||||
# particular, add_to_environ depends on getcwd always being inside
|
||||
# fbcode
|
||||
os.chdir(testdir)
|
||||
ret = runner.run(args)
|
||||
# Also add to the system path because the Mercurial run-tests.py does an
|
||||
# absolute import of killdaemons etc.
|
||||
env = os.environ.copy()
|
||||
env["HGPYTHONPATH"] = os.path.join(testdir, 'third_party')
|
||||
p = subprocess.Popen(
|
||||
args, env=env, stderr=sys.stderr, stdout=sys.stdout
|
||||
)
|
||||
p.communicate("")
|
||||
ret = p.returncode
|
||||
|
||||
if dry_run:
|
||||
# The output must go to stdout. Set simple_test_selector to make
|
||||
@ -173,5 +182,10 @@ def get_hg_binary():
|
||||
)
|
||||
|
||||
|
||||
def get_hg_python_binary():
|
||||
return pathutils.get_build_rule_output_path(
|
||||
BINARY_HGPYTHON_TARGET, pathutils.BuildRuleTypes.PYTHON_BINARY
|
||||
)
|
||||
|
||||
if __name__ == '__main__':
|
||||
run()
|
||||
|
@ -9,8 +9,9 @@ setup testing repo for mononoke
|
||||
$ hg init repo-hg
|
||||
$ cd repo-hg
|
||||
$ setup_hg_server
|
||||
$ TEST_CONTENT=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 1000 | head -n 1)
|
||||
$ echo $TEST_CONTENT >> test
|
||||
>>> import os, textwrap, base64
|
||||
>>> open('test', 'w').write(textwrap.fill(base64.b64encode(os.urandom(10000))) + "\n")
|
||||
$ TEST_CONTENT=$(cat test)
|
||||
$ SHA=$(sha256sum test | awk '{print $1;}')
|
||||
$ ln -s test link
|
||||
$ mkdir -p folder/subfolder
|
||||
@ -51,8 +52,8 @@ starts api server
|
||||
$ APISERVER_PORT=$(get_free_socket)
|
||||
$ apiserver -H "[::1]" -p $APISERVER_PORT
|
||||
$ wait_for_apiserver
|
||||
$ alias sslcurl="sslcurl --silent"
|
||||
$ alias s_client="openssl s_client -connect $APIHOST -cert \"$TESTDIR/testcert.crt\" -key \"$TESTDIR/testcert.key\" -ign_eof"
|
||||
$ function sslcurl() { curl --silent --cert "$TESTDIR/testcert.crt" --cacert "$TESTDIR/testcert.crt" --key "$TESTDIR/testcert.key" "$@"; }
|
||||
$ function s_client() { openssl s_client -connect $APIHOST -cert "$TESTDIR/testcert.crt" -key "$TESTDIR/testcert.key" -ign_eof "$@"; }
|
||||
|
||||
ping test
|
||||
$ sslcurl -i $APISERVER/health_check | grep -iv "date"
|
||||
@ -177,24 +178,24 @@ test reachability on url encoded bookmarks
|
||||
false (no-eol)
|
||||
|
||||
test folder list
|
||||
$ sslcurl $APISERVER/repo/list/$COMMIT2/folder | tee output | python -mjson.tool
|
||||
$ sslcurl $APISERVER/repo/list/$COMMIT2/folder | tee output | jq .
|
||||
[
|
||||
{
|
||||
"name": "subfolder",
|
||||
"type": "tree",
|
||||
"hash": "732eacf2be3265bd6bc4d2c205434b280f446cbf"
|
||||
}
|
||||
{
|
||||
"name": "subfolder",
|
||||
"type": "tree",
|
||||
"hash": "732eacf2be3265bd6bc4d2c205434b280f446cbf"
|
||||
}
|
||||
]
|
||||
|
||||
$ TREEHASH=$(cat output | jq -r ".[0].hash")
|
||||
|
||||
$ sslcurl $APISERVER/repo/list/$COMMIT2/folder/subfolder | python -mjson.tool
|
||||
$ sslcurl $APISERVER/repo/list/$COMMIT2/folder/subfolder | jq .
|
||||
[
|
||||
{
|
||||
"name": ".keep",
|
||||
"type": "file",
|
||||
"hash": "2c186c8c5bc0df5af5b951afe407d803f9e6b8c9"
|
||||
}
|
||||
{
|
||||
"name": ".keep",
|
||||
"type": "file",
|
||||
"hash": "2c186c8c5bc0df5af5b951afe407d803f9e6b8c9"
|
||||
}
|
||||
]
|
||||
|
||||
test nonexist fold
|
||||
@ -224,15 +225,15 @@ test get blob by hash
|
||||
404
|
||||
|
||||
test get tree
|
||||
$ sslcurl $APISERVER/repo/tree/$TREEHASH | python -mjson.tool
|
||||
$ sslcurl $APISERVER/repo/tree/$TREEHASH | jq .
|
||||
[
|
||||
{
|
||||
"name": ".keep",
|
||||
"type": "file",
|
||||
"hash": "2c186c8c5bc0df5af5b951afe407d803f9e6b8c9",
|
||||
"size": 6,
|
||||
"content_sha1": "f572d396fae9206628714fb2ce00f72e94f2258f"
|
||||
}
|
||||
{
|
||||
"name": ".keep",
|
||||
"type": "file",
|
||||
"hash": "2c186c8c5bc0df5af5b951afe407d803f9e6b8c9",
|
||||
"size": 6,
|
||||
"content_sha1": "f572d396fae9206628714fb2ce00f72e94f2258f"
|
||||
}
|
||||
]
|
||||
|
||||
$ sslcurl -w "\n%{http_code}" $APISERVER/repo/tree/$BLOBHASH | extract_json_error > output
|
||||
|
@ -23,7 +23,7 @@
|
||||
$ for (( i=0; i < $lines_cnt; i++ ))
|
||||
> do
|
||||
> LINE_LENGTH=$(random_int $max_line_length)
|
||||
> echo $(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $LINE_LENGTH | head -n 1) >> file
|
||||
> echo $(head -c 10000 /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $LINE_LENGTH 2>/dev/null | head -n 1) >> file
|
||||
> done
|
||||
|
||||
$ hg ci -Aqm "commit"$c
|
||||
@ -35,7 +35,7 @@
|
||||
> do
|
||||
> LINE_LENGTH=$(random_int $max_line_length)
|
||||
> LINE_NUMBER=$(random_int $lines_cnt)
|
||||
> CONTENT=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $LINE_LENGTH | head -n 1)
|
||||
> CONTENT=$(head -c 10000 /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w $LINE_LENGTH 2>/dev/null | head -n 1)
|
||||
> sed -i "$LINE_NUMBER""s/.*/$CONTENT/" file
|
||||
> done
|
||||
> hg ci -Aqm "commit"$c
|
||||
|
@ -28,7 +28,7 @@ verify content
|
||||
user: test
|
||||
date: Thu Jan 01 00:00:00 1970 +0000
|
||||
summary: a
|
||||
(re)
|
||||
|
||||
|
||||
$ cd $TESTTMP
|
||||
$ blobimport repo-hg/.hg repo
|
||||
@ -342,7 +342,7 @@ command, but the output of this command is long
|
||||
# Node ID bb0985934a0f8a493887892173b68940ceb40b4f
|
||||
# Parent 0e7ec5675652a04069cbf976a42e45b740f3243c
|
||||
b
|
||||
(re)
|
||||
|
||||
diff -r 0e7ec5675652 -r bb0985934a0f a
|
||||
--- a/a Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/a Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -354,8 +354,8 @@ command, but the output of this command is long
|
||||
+++ b/b_dir/b Thu Jan 01 00:00:00 1970 +0000
|
||||
@@ -0,0 +1,1 @@
|
||||
+b file content
|
||||
(re)
|
||||
(re)
|
||||
|
||||
|
||||
fbd6b221382efa5d5bc53130cdaccf06e04c97d3 comparison SUCCESS
|
||||
# HG changeset patch
|
||||
# User test
|
||||
@ -364,7 +364,7 @@ command, but the output of this command is long
|
||||
# Node ID fbd6b221382efa5d5bc53130cdaccf06e04c97d3
|
||||
# Parent bb0985934a0f8a493887892173b68940ceb40b4f
|
||||
d
|
||||
(re)
|
||||
|
||||
diff -r bb0985934a0f -r fbd6b221382e b_dir/b
|
||||
--- a/b_dir/b Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/b_dir/b Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -376,8 +376,8 @@ command, but the output of this command is long
|
||||
+++ b/d_dir/d Thu Jan 01 00:00:00 1970 +0000
|
||||
@@ -0,0 +1,1 @@
|
||||
+d file content
|
||||
(re)
|
||||
(re)
|
||||
|
||||
|
||||
30da5bf63484d2d6572edafb3ea211c17cd8c005 comparison SUCCESS
|
||||
# HG changeset patch
|
||||
# User test
|
||||
@ -386,7 +386,7 @@ command, but the output of this command is long
|
||||
# Node ID 30da5bf63484d2d6572edafb3ea211c17cd8c005
|
||||
# Parent fbd6b221382efa5d5bc53130cdaccf06e04c97d3
|
||||
e
|
||||
(re)
|
||||
|
||||
diff -r fbd6b221382e -r 30da5bf63484 a
|
||||
--- a/a Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/a Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -399,8 +399,8 @@ command, but the output of this command is long
|
||||
@@ -1,1 +1,1 @@
|
||||
-updated b file content
|
||||
+b file content
|
||||
(re)
|
||||
(re)
|
||||
|
||||
|
||||
8315ea53ef41d34f56232c88669cc80225b6e66d comparison SUCCESS
|
||||
# HG changeset patch
|
||||
# User test
|
||||
@ -409,7 +409,7 @@ command, but the output of this command is long
|
||||
# Node ID 8315ea53ef41d34f56232c88669cc80225b6e66d
|
||||
# Parent 30da5bf63484d2d6572edafb3ea211c17cd8c005
|
||||
f
|
||||
(re)
|
||||
|
||||
diff -r 30da5bf63484 -r 8315ea53ef41 a
|
||||
--- a/a Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/a Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -433,8 +433,8 @@ command, but the output of this command is long
|
||||
@@ -1,1 +1,1 @@
|
||||
-d file content
|
||||
+b file content
|
||||
(re)
|
||||
(re)
|
||||
|
||||
|
||||
634de738bb0ff135e32d48567718fb9d7dedf575 comparison SUCCESS
|
||||
# HG changeset patch
|
||||
# User test
|
||||
@ -443,7 +443,7 @@ command, but the output of this command is long
|
||||
# Node ID 634de738bb0ff135e32d48567718fb9d7dedf575
|
||||
# Parent 8315ea53ef41d34f56232c88669cc80225b6e66d
|
||||
g
|
||||
(re)
|
||||
|
||||
diff -r 8315ea53ef41 -r 634de738bb0f a
|
||||
--- a/a Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -480,8 +480,8 @@ command, but the output of this command is long
|
||||
+++ b/e_dir/e Thu Jan 01 00:00:00 1970 +0000
|
||||
@@ -0,0 +1,1 @@
|
||||
+a file content
|
||||
(re)
|
||||
(re)
|
||||
|
||||
|
||||
f40c09205504d8410f8c8679bf7a85fef25f9337 comparison SUCCESS
|
||||
# HG changeset patch
|
||||
# User test
|
||||
@ -490,7 +490,7 @@ command, but the output of this command is long
|
||||
# Node ID f40c09205504d8410f8c8679bf7a85fef25f9337
|
||||
# Parent bb0985934a0f8a493887892173b68940ceb40b4f
|
||||
c
|
||||
(re)
|
||||
|
||||
diff -r bb0985934a0f -r f40c09205504 b_dir/b
|
||||
--- a/b_dir/b Thu Jan 01 00:00:00 1970 +0000
|
||||
+++ b/b_dir/b Thu Jan 01 00:00:00 1970 +0000
|
||||
@ -502,5 +502,5 @@ command, but the output of this command is long
|
||||
+++ b/c_dir/c Thu Jan 01 00:00:00 1970 +0000
|
||||
@@ -0,0 +1,1 @@
|
||||
+c file content
|
||||
(re)
|
||||
(re)
|
||||
|
||||
|
||||
|
@ -19,7 +19,7 @@ setup data
|
||||
start mononoke
|
||||
$ mononoke
|
||||
$ wait_for_mononoke $TESTTMP/repo
|
||||
$ alias s_client="openssl s_client -connect localhost:$MONONOKE_SOCKET -cert \"$TESTDIR/testcert.crt\" -key \"$TESTDIR/testcert.key\" -ign_eof"
|
||||
$ function s_client () { openssl s_client -connect localhost:$MONONOKE_SOCKET -cert "$TESTDIR/testcert.crt" -key "$TESTDIR/testcert.key" -ign_eof "$@"; }
|
||||
|
||||
test TLS Session/Ticket resumption when using client certs
|
||||
$ TMPFILE=$(mktemp)
|
||||
|
21
tests/integration/third_party/heredoctest.py
vendored
Normal file
21
tests/integration/third_party/heredoctest.py
vendored
Normal file
@ -0,0 +1,21 @@
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
globalvars = {}
|
||||
lines = sys.stdin.readlines()
|
||||
while lines:
|
||||
l = lines.pop(0)
|
||||
if l.startswith("SALT"):
|
||||
print(l[:-1])
|
||||
elif l.startswith(">>> "):
|
||||
snippet = l[4:]
|
||||
while lines and lines[0].startswith("... "):
|
||||
l = lines.pop(0)
|
||||
snippet += l[4:]
|
||||
c = compile(snippet, "<heredoc>", "single")
|
||||
try:
|
||||
exec(c, globalvars)
|
||||
except Exception as inst:
|
||||
print(repr(inst))
|
2770
tests/integration/third_party/hg_run_tests.py
vendored
2770
tests/integration/third_party/hg_run_tests.py
vendored
File diff suppressed because it is too large
Load Diff
91
tests/integration/third_party/tinit.sh
vendored
Normal file
91
tests/integration/third_party/tinit.sh
vendored
Normal file
@ -0,0 +1,91 @@
|
||||
# This file will be sourced by all .t tests. Put general purposed functions
|
||||
# here.
|
||||
|
||||
_repocount=0
|
||||
|
||||
# Create a new repo
|
||||
newrepo() {
|
||||
reponame="$1"
|
||||
if [ -z "$reponame" ]; then
|
||||
_repocount=$((_repocount+1))
|
||||
reponame=repo$_repocount
|
||||
fi
|
||||
mkdir "$TESTTMP/$reponame"
|
||||
cd "$TESTTMP/$reponame"
|
||||
hg init
|
||||
}
|
||||
|
||||
switchrepo() {
|
||||
reponame="$1"
|
||||
cd $TESTTMP/$reponame
|
||||
}
|
||||
|
||||
# Enable extensions or features
|
||||
enable() {
|
||||
local rcpath
|
||||
# .hg/hgrc may not exist yet, so just check for requires
|
||||
if [ -f .hg/requires ]; then
|
||||
rcpath=.hg/hgrc
|
||||
else
|
||||
rcpath="$HGRCPATH"
|
||||
fi
|
||||
for name in "$@"; do
|
||||
if [ "$name" = obsstore ]; then
|
||||
cat >> $rcpath << EOF
|
||||
[experimental]
|
||||
evolution = createmarkers, allowunstable
|
||||
EOF
|
||||
else
|
||||
cat >> $rcpath << EOF
|
||||
[extensions]
|
||||
$name=
|
||||
EOF
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
||||
# Like "hg debugdrawdag", but do not leave local tags in the repo and define
|
||||
# nodes as environment variables.
|
||||
# This is useful if the test wants to hide those commits because tags would
|
||||
# make commits visible. The function will set environment variables so
|
||||
# commits can still be referred as $TAGNAME.
|
||||
drawdag() {
|
||||
hg debugdrawdag "$@"
|
||||
eval `hg tags -T '{tag}={node}\n'`
|
||||
rm -f .hg/localtags
|
||||
}
|
||||
|
||||
# Simplify error reporting so crash does not show a traceback.
|
||||
# This is useful to match error messages without the traceback.
|
||||
shorttraceback() {
|
||||
enable errorredirect
|
||||
setconfig errorredirect.script='printf "%s" "$TRACE" | tail -1 1>&2'
|
||||
}
|
||||
|
||||
# Set config items like --config way, instead of using cat >> $HGRCPATH
|
||||
setconfig() {
|
||||
python "$RUNTESTDIR/setconfig.py" "$@"
|
||||
}
|
||||
|
||||
# Create a new extension
|
||||
newext() {
|
||||
extname="$1"
|
||||
if [ -z "$extname" ]; then
|
||||
_extcount=$((_extcount+1))
|
||||
extname=ext$_extcount
|
||||
fi
|
||||
cat > "$TESTTMP/$extname.py"
|
||||
setconfig "extensions.$extname=$TESTTMP/$extname.py"
|
||||
}
|
||||
|
||||
showgraph() {
|
||||
hg log --graph -T "{rev} {node|short} {desc|firstline}" | sed \$d
|
||||
}
|
||||
|
||||
tglog() {
|
||||
hg log -G -T "{rev}: {node|short} '{desc}' {bookmarks} {branches}" "$@"
|
||||
}
|
||||
|
||||
tglogp() {
|
||||
hg log -G -T "{rev}: {node|short} {phase} '{desc}' {bookmarks} {branches}" "$@"
|
||||
}
|
Loading…
Reference in New Issue
Block a user