mononoke: select free port in the test

Summary:
Two tests can't be run simultaneously because they use the same port. This diff
fixes it.

Reviewed By: farnz

Differential Revision: D6457855

fbshipit-source-id: 3e5f82211bcd87abc608bdeab239fe680976316d
This commit is contained in:
Stanislau Hlebik 2017-12-06 07:33:20 -08:00 committed by Facebook Github Bot
parent 2bf9290758
commit 0cceb35e49

View File

@ -15,6 +15,16 @@
> python $TESTTMP/json_pretty_print.py
> }
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
$ hg init repo
$ cd repo
$ cat >> .hg/hgrc <<EOF
@ -95,10 +105,11 @@ Add commit with a directory
summary: a
$ cd ..
$ SOCKET=`python $TESTTMP/get_free_socket.py`
$ mkdir $TESTTMP/blobrepo
$ echo 'reponame="repo"' >> $TESTTMP/config
$ echo "path=\"$TESTTMP/blobrepo\"" >> $TESTTMP/config
$ echo 'addr="127.0.0.1:3000"' >> $TESTTMP/config
$ echo "addr='127.0.0.1:$SOCKET'" >> $TESTTMP/config
$ echo "cert=\"$TESTDIR/edenservertest.crt\"" >> $TESTTMP/config
$ echo "private_key=\"$TESTDIR/edenservertest.key\"" >> $TESTTMP/config
$ echo "ca_pem_file=\"$TESTDIR/edenservertest.crt\"" >> $TESTTMP/config
@ -153,14 +164,14 @@ Temporary hack to make sure server is ready
Curl and debugdata output should match
$ alias curl="curl --cert $TESTDIR/edenservertest.crt --key $TESTDIR/edenservertest.key --cacert $TESTDIR/edenservertest.crt"
$ curl https://localhost:3000/repo/cs/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid 2> /dev/null
8515d4bfda768e04af4c13a69a72e28c7effbea7 (no-eol)
$ cd repo
$ hg debugdata -c 3903775176ed42b1458a6281db4a0ccf4d9f287a | head -n 1
8515d4bfda768e04af4c13a69a72e28c7effbea7
$ hg debugdata -m 8515d4bfda768e04af4c13a69a72e28c7effbea7
a\x00b80de5d138758541c5f05265ad144ab9fa86d1db (esc)
$ curl https://localhost:3000/repo/cs/533267b0e203537fa53d2aec834b062f0b2249cd/roottreemanifestid 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/533267b0e203537fa53d2aec834b062f0b2249cd/roottreemanifestid 2> /dev/null
47827ecc7f12d2ed0c387de75947e73cf1c53afe (no-eol)
$ hg debugdata -m 47827ecc7f12d2ed0c387de75947e73cf1c53afe
@ -169,7 +180,7 @@ Curl and debugdata output should match
c\x005d9299349fc01ddd25d0070d149b124d8f10411e (esc)
d\x00fc702583f9c961dea176fd367862c299b4a551f2 (esc)
$ curl https://localhost:3000/repo/treenode/8515d4bfda768e04af4c13a69a72e28c7effbea7/ 2> /dev/null| json_print
$ curl https://localhost:$SOCKET/repo/treenode/8515d4bfda768e04af4c13a69a72e28c7effbea7/ 2> /dev/null| json_print
[
{
"hash": "b80de5d138758541c5f05265ad144ab9fa86d1db",
@ -180,11 +191,11 @@ Curl and debugdata output should match
]
Empty file
$ curl https://localhost:3000/repo/blob/b80de5d138758541c5f05265ad144ab9fa86d1db/ 2> /dev/null
$ curl https://localhost:$SOCKET/repo/blob/b80de5d138758541c5f05265ad144ab9fa86d1db/ 2> /dev/null
$ curl https://localhost:3000/repo/cs/4dabaf45f54add88ca2797dfdeb00a7d55144243/roottreemanifestid 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/4dabaf45f54add88ca2797dfdeb00a7d55144243/roottreemanifestid 2> /dev/null
b47dc781a873595c796b01e2ed5829e3fed2c887 (no-eol)
$ curl https://localhost:3000/repo/treenode/b47dc781a873595c796b01e2ed5829e3fed2c887/ 2> /dev/null| json_print
$ curl https://localhost:$SOCKET/repo/treenode/b47dc781a873595c796b01e2ed5829e3fed2c887/ 2> /dev/null| json_print
[
{
"hash": "b80de5d138758541c5f05265ad144ab9fa86d1db",
@ -205,9 +216,9 @@ Empty file
"type": "File"
}
]
$ curl https://localhost:3000/repo/blob/5d9299349fc01ddd25d0070d149b124d8f10411e/ 2> /dev/null
$ curl https://localhost:$SOCKET/repo/blob/5d9299349fc01ddd25d0070d149b124d8f10411e/ 2> /dev/null
2
$ curl https://localhost:3000/repo/treenode/47827ecc7f12d2ed0c387de75947e73cf1c53afe/ 2> /dev/null | json_print
$ curl https://localhost:$SOCKET/repo/treenode/47827ecc7f12d2ed0c387de75947e73cf1c53afe/ 2> /dev/null | json_print
[
{
"hash": "b80de5d138758541c5f05265ad144ab9fa86d1db",
@ -234,16 +245,16 @@ Empty file
"type": "File"
}
]
$ curl https://localhost:3000/repo/blob/fc702583f9c961dea176fd367862c299b4a551f2/ 2> /dev/null
$ curl https://localhost:$SOCKET/repo/blob/fc702583f9c961dea176fd367862c299b4a551f2/ 2> /dev/null
2
$ curl https://localhost:3000/repo/cs/617e87e2aa2fe36508e8d5e15a162bcd2e79808e/roottreemanifestid 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/617e87e2aa2fe36508e8d5e15a162bcd2e79808e/roottreemanifestid 2> /dev/null
ed8f515856d818e78bd52edac84a97568de65e0f (no-eol)
$ curl https://localhost:3000/repo/cs/617e87e2aa2fe36508e8d5e15a162bcd2e79808e/roottreemanifestid/ 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/617e87e2aa2fe36508e8d5e15a162bcd2e79808e/roottreemanifestid/ 2> /dev/null
ed8f515856d818e78bd52edac84a97568de65e0f (no-eol)
$ curl https://localhost:3000/repo/treenode/ed8f515856d818e78bd52edac84a97568de65e0f/ 2> /dev/null | json_print
$ curl https://localhost:$SOCKET/repo/treenode/ed8f515856d818e78bd52edac84a97568de65e0f/ 2> /dev/null | json_print
[
{
"hash": "e7405b0462d8b2dd80219b713a93aea2c9a3c468",
@ -253,7 +264,7 @@ Empty file
}
]
$ curl https://localhost:3000/repo/treenode/e7405b0462d8b2dd80219b713a93aea2c9a3c468/ 2> /dev/null | json_print
$ curl https://localhost:$SOCKET/repo/treenode/e7405b0462d8b2dd80219b713a93aea2c9a3c468/ 2> /dev/null | json_print
[
{
"hash": "7108421418404a937c684d2479a34a24d2ce4757",
@ -262,7 +273,7 @@ Empty file
"type": "File"
}
]
$ curl https://localhost:3000/repo/treenode/e7405b0462d8b2dd80219b713a93aea2c9a3c468 2> /dev/null | json_print
$ curl https://localhost:$SOCKET/repo/treenode/e7405b0462d8b2dd80219b713a93aea2c9a3c468 2> /dev/null | json_print
[
{
"hash": "7108421418404a937c684d2479a34a24d2ce4757",
@ -272,25 +283,25 @@ Empty file
}
]
$ curl https://localhost:3000/repo/blob/7108421418404a937c684d2479a34a24d2ce4757/ 2> /dev/null
$ curl https://localhost:$SOCKET/repo/blob/7108421418404a937c684d2479a34a24d2ce4757/ 2> /dev/null
content
$ curl https://localhost:3000/repo/blob/7108421418404a937c684d2479a34a24d2ce4757 2> /dev/null
$ curl https://localhost:$SOCKET/repo/blob/7108421418404a937c684d2479a34a24d2ce4757 2> /dev/null
content
Send incorrect requests
$ curl https://localhost:3000/repo/cs/hash/roottreemanifestid 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/hash/roottreemanifestid 2> /dev/null
invalid sha-1 input: need at least 40 hex digits (no-eol)
$ curl https://localhost:3000/badrepo/cs/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid 2> /dev/null
$ curl https://localhost:$SOCKET/badrepo/cs/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid 2> /dev/null
Error: unknown repo
$ curl https://localhost:3000/badrepo/treenode/8515d4bfda768e04af4c13a69a72e28c7effbea7/ 2> /dev/null
$ curl https://localhost:$SOCKET/badrepo/treenode/8515d4bfda768e04af4c13a69a72e28c7effbea7/ 2> /dev/null
Error: unknown repo
$ curl https://localhost:3000/repo/BADURL/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid 2> /dev/null
$ curl https://localhost:$SOCKET/repo/BADURL/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid 2> /dev/null
malformed url (no-eol)
$ curl https://localhost:3000/repo/cs/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid/more 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/3903775176ed42b1458a6281db4a0ccf4d9f287a/roottreemanifestid/more 2> /dev/null
malformed url (no-eol)
$ curl https://localhost:3000/repo/cs/ 2> /dev/null
$ curl https://localhost:$SOCKET/repo/cs/ 2> /dev/null
malformed url (no-eol)
$ curl https://localhost:3000/ 2> /dev/null
$ curl https://localhost:$SOCKET/ 2> /dev/null
malformed url (no-eol)
Make sure there are no errors on the server