sapling/tests/test-fbconduit.t
Adam Simpkins 33b2fbc0bc fbconduit: fix error handling in gitnode() revset
Summary:
Don't let errors propagate out of the gitnode() revset.  Always report errors
in gitnode() as a translation failure, rather than letting exceptions propagate
up and crash mercurial.  The code was previously only catching internally
generated ConduitError exceptions, but it can also throw HttpError exceptions,
and the underlying httplib code can throw its own exceptions as well as
socket.error exceptions.

This also fixes the test code to use an ephemeral TCP port rather than assuming
port 8543 will always be available.  Using a fixed TCP port in test code is a
very common way to cause bogus failures if the tests are run in parallel.
(For instance, testing multiple repositories in parallel on the same build
host.)

Test Plan:
Added unit tests that check the behavior when the server returns a 500 error,
and when the server refuses the connection entirely.

Reviewers: quark, durham, rmcelroy

Reviewed By: rmcelroy

Subscribers: net-systems-diffs@fb.com, yogeshwer, mjpieters

Differential Revision: https://phabricator.intern.facebook.com/D4556871

Signature: t1:4556871:1487062142:b58d770d46c975d44933bec08cfce8acb25ff16b
2017-02-15 12:35:06 -08:00

158 lines
6.8 KiB
Perl

Start up translation service.
$ python "$TESTDIR/conduithttp.py" --port-file conduit.port --pid conduit.pid
$ cat conduit.pid >> $DAEMON_PIDS
$ CONDUIT_PORT=`cat conduit.port`
Basic functionality.
$ hg init basic
$ cd basic
$ echo "[extensions]" >> .hg/hgrc
$ echo "fbconduit = $TESTDIR/../hgext3rd/fbconduit.py" >> .hg/hgrc
$ echo "[fbconduit]" >> .hg/hgrc
$ echo "reponame = basic" >> .hg/hgrc
$ echo "host = localhost:$CONDUIT_PORT" >> .hg/hgrc
$ echo "path = /intern/conduit/" >> .hg/hgrc
$ echo "protocol = http" >> .hg/hgrc
$ touch file
$ hg add file
$ hg ci -m "initial commit"
$ commitid=`hg log -T "{label('custom.fullrev',node)}"`
$ hg phase -p $commitid
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/basic/hg/basic/git/$commitid/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ hg log -T '{gitnode}\n'
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ hg log -T '{mirrornode("git")}\n'
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ hg log -T '{mirrornode("basic", "git")}\n'
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")'
Could not translate revision aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/basic/git/basic/hg/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/$commitid
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")' -T '{desc}\n'
initial commit
Make sure that we fail gracefully if the translation server returns an
HTTP error code.
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/fail_next/whoops
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")' -T '{desc}\n'
Could not translate revision aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: whoops
$ cd ..
Test with one backing repos specified.
$ hg init single_backingrepo
$ cd single_backingrepo
$ echo "[extensions]" >> .hg/hgrc
$ echo "fbconduit = $TESTDIR/../hgext3rd/fbconduit.py" >> .hg/hgrc
$ echo "[fbconduit]" >> .hg/hgrc
$ echo "reponame = single" >> .hg/hgrc
$ echo "backingrepos = single_src" >> .hg/hgrc
$ echo "host = localhost:$CONDUIT_PORT" >> .hg/hgrc
$ echo "path = /intern/conduit/" >> .hg/hgrc
$ echo "protocol = http" >> .hg/hgrc
$ touch file
$ hg add file
$ hg ci -m "initial commit"
$ commitid=`hg log -T "{label('custom.fullrev',node)}"`
$ hg phase -p $commitid
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/single/hg/single_src/git/$commitid/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ hg log -T '{gitnode}\n'
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")'
Could not translate revision aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/single_src/git/single/hg/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/$commitid
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")' -T '{desc}\n'
initial commit
$ cd ..
Test with multiple backing repos specified.
$ hg init backingrepos
$ cd backingrepos
$ echo "[extensions]" >> .hg/hgrc
$ echo "fbconduit = $TESTDIR/../hgext3rd/fbconduit.py" >> .hg/hgrc
$ echo "[fbconduit]" >> .hg/hgrc
$ echo "reponame = multiple" >> .hg/hgrc
$ echo "backingrepos = src_a src_b src_c" >> .hg/hgrc
$ echo "host = localhost:$CONDUIT_PORT" >> .hg/hgrc
$ echo "path = /intern/conduit/" >> .hg/hgrc
$ echo "protocol = http" >> .hg/hgrc
$ touch file_a
$ hg add file_a
$ hg ci -m "commit 1"
$ touch file_b
$ hg add file_b
$ hg ci -m "commit 2"
$ touch file_c
$ hg add file_c
$ hg ci -m "commit 3"
$ commit_a_id=`hg log -T "{label('custom.fullrev',node)}" -r ".^^"`
$ commit_b_id=`hg log -T "{label('custom.fullrev',node)}" -r ".^"`
$ commit_c_id=`hg log -T "{label('custom.fullrev',node)}" -r .`
$ hg phase -p $commit_a_id
$ hg phase -p $commit_b_id
$ hg phase -p $commit_c_id
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/multiple/hg/src_a/git/$commit_a_id/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/multiple/hg/src_b/git/$commit_b_id/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/multiple/hg/src_c/git/$commit_c_id/cccccccccccccccccccccccccccccccccccccccc
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/multiple/hg/src_b/git/$commit_c_id/dddddddddddddddddddddddddddddddddddddddd
$ hg log -T '{gitnode}\n' -r ".^^"
src_a: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ hg log -T '{gitnode}\n' -r ".^"
src_b: bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
$ hg log -T '{gitnode}\n' -r .
src_b: dddddddddddddddddddddddddddddddddddddddd; src_c: cccccccccccccccccccccccccccccccccccccccc
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")'
Could not translate revision aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/src_a/git/multiple/hg/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/$commit_a_id
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/src_b/git/multiple/hg/bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/$commit_b_id
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/src_c/git/multiple/hg/cccccccccccccccccccccccccccccccccccccccc/$commit_c_id
$ curl -s -X PUT http://localhost:$CONDUIT_PORT/src_b/git/multiple/hg/dddddddddddddddddddddddddddddddddddddddd/$commit_c_id
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")' -T '{desc}\n'
commit 1
$ hg log -r 'gitnode("bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb")' -T '{desc}\n'
commit 2
$ hg log -r 'gitnode("cccccccccccccccccccccccccccccccccccccccc")' -T '{desc}\n'
commit 3
$ hg log -r 'gitnode("dddddddddddddddddddddddddddddddddddddddd")' -T '{desc}\n'
commit 3
$ hg log -r gaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa -T '{desc}\n'
commit 1
$ hg log -r gbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb -T '{desc}\n'
commit 2
$ hg log -r gcccccccccccccccccccccccccccccccccccccccc -T '{desc}\n'
commit 3
$ hg log -r gdddddddddddddddddddddddddddddddddddddddd -T '{desc}\n'
commit 3
$ cd ..
Test with a bad server port, where we get connection refused errors.
$ hg init errortest
$ cd errortest
$ echo "[extensions]" >> .hg/hgrc
$ echo "fbconduit = $TESTDIR/../hgext3rd/fbconduit.py" >> .hg/hgrc
$ echo "[fbconduit]" >> .hg/hgrc
$ echo "reponame = errortest" >> .hg/hgrc
$ echo "host = localhost:9" >> .hg/hgrc
$ echo "path = /intern/conduit/" >> .hg/hgrc
$ echo "protocol = http" >> .hg/hgrc
$ touch file
$ hg add file
$ hg ci -m "initial commit"
$ commitid=`hg log -T "{label('custom.fullrev',node)}"`
$ hg phase -p $commitid
$ hg log -r 'gitnode("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")'
Could not translate revision aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: * (glob)
$ cd ..
Make sure the template keywords are documented correctly
$ cd basic
$ hg help templates | grep gitnode
gitnode Return the git revision corresponding to a given hg rev
$ cd ..