tests/test-hgwebdir
author David Greenaway <hg-dev@davidgreenaway.com>
Sat, 03 Apr 2010 11:58:16 +1100
changeset 11060 e6df01776e08
parent 10878 c63a6ddbbf9a
child 11677 8f8a7976f4bc
permissions -rwxr-xr-x
findrenames: Optimise "addremove -s100" by matching files by their SHA1 hashes. We speed up 'findrenames' for the usecase when a user specifies they want a similarity of 100% by matching files by their exact SHA1 hash value. This reduces the number of comparisons required to find exact matches from O(n^2) to O(n). While it would be nice if we could just use mercurial's pre-calculated SHA1 hash for existing files, this hash includes the file's ancestor information making it unsuitable for our purposes. Instead, we calculate the hash of old content from scratch. The following benchmarks were taken on the current head of crew: addremove 100% similarity: rm -rf *; hg up -C; mv tests tests.new hg --time addremove -s100 --dry-run before: real 176.350 secs (user 128.890+0.000 sys 47.430+0.000) after: real 2.130 secs (user 1.890+0.000 sys 0.240+0.000) addremove 75% similarity: rm -rf *; hg up -C; mv tests tests.new; \ for i in tests.new/*; do echo x >> $i; done hg --time addremove -s75 --dry-run before: real 264.560 secs (user 215.130+0.000 sys 49.410+0.000) after: real 218.710 secs (user 172.790+0.000 sys 45.870+0.000)

#!/bin/sh
# Tests some basic hgwebdir functionality. Tests setting up paths and
# collection, different forms of 404s and the subdirectory support.

mkdir webdir
cd webdir

hg init a
echo a > a/a
hg --cwd a ci -Ama -d'1 0'
# create a mercurial queue repository
hg --cwd a qinit --config extensions.hgext.mq= -c

hg init b
echo b > b/b
hg --cwd b ci -Amb -d'2 0'

# create a nested repository
cd b
hg init d
echo d > d/d
hg --cwd d ci -Amd -d'3 0'
cd ..

hg init c
echo c > c/c
hg --cwd c ci -Amc -d'3 0'

root=`pwd`
cd ..


cat > paths.conf <<EOF
[paths]
a=$root/a
b=$root/b
EOF

hg serve -p $HGPORT -d --pid-file=hg.pid --webdir-conf paths.conf \
    -A access-paths.log -E error-paths-1.log
cat hg.pid >> $DAEMON_PIDS

echo % should give a 404 - file does not exist
"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/a/file/tip/bork?style=raw'

echo % should succeed
"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/a/file/tip/a?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/b/file/tip/b?style=raw'

echo % should give a 404 - repo is not published
"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/c/file/tip/c?style=raw'

echo % atom-log without basedir
"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/a/atom-log' \
    | grep '<link' | sed 's|//[.a-zA-Z0-9_-]*:[0-9][0-9]*/|//example.com:8080/|'

echo % rss-log without basedir
"$TESTDIR/get-with-headers.py" localhost:$HGPORT '/a/rss-log' \
    | grep '<guid' | sed 's|//[.a-zA-Z0-9_-]*:[0-9][0-9]*/|//example.com:8080/|'

cat > paths.conf <<EOF
[paths]
t/a/=$root/a
b=$root/b
coll=$root/*
rcoll=$root/**
EOF

hg serve -p $HGPORT1 -d --pid-file=hg.pid --webdir-conf paths.conf \
    -A access-paths.log -E error-paths-2.log
cat hg.pid >> $DAEMON_PIDS

echo % should succeed, slashy names
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/?style=paper' \
	| sed "s/[0-9]\{1,\} seconds\{0,1\} ago/seconds ago/"
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/?style=paper' \
	| sed "s/[0-9]\{1,\} seconds\{0,1\} ago/seconds ago/"
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/a?style=atom' \
	| sed "s/http:\/\/[^/]*\//http:\/\/127.0.0.1\//"
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/a/?style=atom' \
	| sed "s/http:\/\/[^/]*\//http:\/\/127.0.0.1\//"
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/a/file/tip/a?style=raw'
# Test [paths] '*' extension
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/coll/?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/coll/a/file/tip/a?style=raw'
#test [paths] '**' extension
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/rcoll/?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/rcoll/b/d/file/tip/d?style=raw'


"$TESTDIR/killdaemons.py"
cat > paths.conf <<EOF
[paths]
t/a = $root/a
t/b = $root/b
c = $root/c
[web]
descend=false
EOF

hg serve -p $HGPORT1 -d --pid-file=hg.pid --webdir-conf paths.conf \
    -A access-paths.log -E error-paths-3.log
cat hg.pid >> $DAEMON_PIDS
echo % test descend = False
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT1 '/t/?style=raw'


cat > collections.conf <<EOF
[collections]
$root=$root
EOF

hg serve --config web.baseurl=http://hg.example.com:8080/ -p $HGPORT2 -d \
    --pid-file=hg.pid --webdir-conf collections.conf \
    -A access-collections.log -E error-collections.log
cat hg.pid >> $DAEMON_PIDS

echo % collections: should succeed
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/file/tip/a?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/b/file/tip/b?style=raw'
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/c/file/tip/c?style=raw'

echo % atom-log with basedir /
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/atom-log' \
    | grep '<link' | sed 's|//[.a-zA-Z0-9_-]*:[0-9][0-9]*/|//example.com:8080/|'

echo % rss-log with basedir /
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/rss-log' \
    | grep '<guid' | sed 's|//[.a-zA-Z0-9_-]*:[0-9][0-9]*/|//example.com:8080/|'

"$TESTDIR/killdaemons.py"

hg serve --config web.baseurl=http://hg.example.com:8080/foo/ -p $HGPORT2 -d \
    --pid-file=hg.pid --webdir-conf collections.conf \
    -A access-collections-2.log -E error-collections-2.log
cat hg.pid >> $DAEMON_PIDS

echo % atom-log with basedir /foo/
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/atom-log' \
    | grep '<link' | sed 's|//[.a-zA-Z0-9_-]*:[0-9][0-9]*/|//example.com:8080/|'

echo % rss-log with basedir /foo/
"$TESTDIR/get-with-headers.py" localhost:$HGPORT2 '/a/rss-log' \
    | grep '<guid' | sed 's|//[.a-zA-Z0-9_-]*:[0-9][0-9]*/|//example.com:8080/|'

echo % paths errors 1
cat error-paths-1.log
echo % paths errors 2
cat error-paths-2.log
echo % paths errors 3
cat error-paths-3.log
echo % collections errors
cat error-collections.log
echo % collections errors 2
cat error-collections-2.log